From 5b659407a6434a6b6bc0c85b2da96a422136e9cf Mon Sep 17 00:00:00 2001 From: ksschwabe Date: Tue, 25 Aug 2015 17:24:11 +0200 Subject: [PATCH 1/4] Bug fix: Incorrect APBs used in HRT driver and tone alarm driver. --- src/drivers/stm32/drv_hrt.c | 8 ++++---- src/drivers/stm32/tone_alarm/tone_alarm.cpp | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/drivers/stm32/drv_hrt.c b/src/drivers/stm32/drv_hrt.c index e37b750fe8..0ea6bd8d04 100644 --- a/src/drivers/stm32/drv_hrt.c +++ b/src/drivers/stm32/drv_hrt.c @@ -85,7 +85,7 @@ #elif HRT_TIMER == 2 # define HRT_TIMER_BASE STM32_TIM2_BASE # define HRT_TIMER_POWER_REG STM32_RCC_APB1ENR -# define HRT_TIMER_POWER_BIT RCC_APB2ENR_TIM2EN +# define HRT_TIMER_POWER_BIT RCC_APB1ENR_TIM2EN # define HRT_TIMER_VECTOR STM32_IRQ_TIM2 # define HRT_TIMER_CLOCK STM32_APB1_TIM2_CLKIN # if CONFIG_STM32_TIM2 @@ -103,7 +103,7 @@ #elif HRT_TIMER == 4 # define HRT_TIMER_BASE STM32_TIM4_BASE # define HRT_TIMER_POWER_REG STM32_RCC_APB1ENR -# define HRT_TIMER_POWER_BIT RCC_APB2ENR_TIM4EN +# define HRT_TIMER_POWER_BIT RCC_APB1ENR_TIM4EN # define HRT_TIMER_VECTOR STM32_IRQ_TIM4 # define HRT_TIMER_CLOCK STM32_APB1_TIM4_CLKIN # if CONFIG_STM32_TIM4 @@ -129,10 +129,10 @@ # endif #elif HRT_TIMER == 9 # define HRT_TIMER_BASE STM32_TIM9_BASE -# define HRT_TIMER_POWER_REG STM32_RCC_APB1ENR +# define HRT_TIMER_POWER_REG STM32_RCC_APB2ENR # define HRT_TIMER_POWER_BIT RCC_APB2ENR_TIM9EN # define HRT_TIMER_VECTOR STM32_IRQ_TIM1BRK -# define HRT_TIMER_CLOCK STM32_APB1_TIM9_CLKIN +# define HRT_TIMER_CLOCK STM32_APB2_TIM9_CLKIN # if CONFIG_STM32_TIM9 # error must not set CONFIG_STM32_TIM9=y and HRT_TIMER=9 # endif diff --git a/src/drivers/stm32/tone_alarm/tone_alarm.cpp b/src/drivers/stm32/tone_alarm/tone_alarm.cpp index 17f4c9362b..beffbdd8b6 100644 --- a/src/drivers/stm32/tone_alarm/tone_alarm.cpp +++ b/src/drivers/stm32/tone_alarm/tone_alarm.cpp @@ -148,22 +148,22 @@ # endif #elif TONE_ALARM_TIMER == 9 # define TONE_ALARM_BASE STM32_TIM9_BASE -# define TONE_ALARM_CLOCK STM32_APB1_TIM9_CLKIN -# define TONE_ALARM_CLOCK_ENABLE RCC_APB1ENR_TIM9EN +# define TONE_ALARM_CLOCK STM32_APB2_TIM9_CLKIN +# define TONE_ALARM_CLOCK_ENABLE RCC_APB2ENR_TIM9EN # ifdef CONFIG_STM32_TIM9 # error Must not set CONFIG_STM32_TIM9 when TONE_ALARM_TIMER is 9 # endif #elif TONE_ALARM_TIMER == 10 # define TONE_ALARM_BASE STM32_TIM10_BASE -# define TONE_ALARM_CLOCK STM32_APB1_TIM10_CLKIN -# define TONE_ALARM_CLOCK_ENABLE RCC_APB1ENR_TIM10EN +# define TONE_ALARM_CLOCK STM32_APB2_TIM10_CLKIN +# define TONE_ALARM_CLOCK_ENABLE RCC_APB2ENR_TIM10EN # ifdef CONFIG_STM32_TIM10 # error Must not set CONFIG_STM32_TIM10 when TONE_ALARM_TIMER is 10 # endif #elif TONE_ALARM_TIMER == 11 # define TONE_ALARM_BASE STM32_TIM11_BASE -# define TONE_ALARM_CLOCK STM32_APB1_TIM11_CLKIN -# define TONE_ALARM_CLOCK_ENABLE RCC_APB1ENR_TIM11EN +# define TONE_ALARM_CLOCK STM32_APB2_TIM11_CLKIN +# define TONE_ALARM_CLOCK_ENABLE RCC_APB2ENR_TIM11EN # ifdef CONFIG_STM32_TIM11 # error Must not set CONFIG_STM32_TIM11 when TONE_ALARM_TIMER is 11 # endif From fb2082e6aeeffdaec6c5b7408832fb620b549ce0 Mon Sep 17 00:00:00 2001 From: ksschwabe Date: Wed, 26 Aug 2015 11:03:32 +0200 Subject: [PATCH 2/4] Introduce new variable for TONE_ALARM_CLOCK_POWER_REG to account for timers being on different APBs --- src/drivers/stm32/tone_alarm/tone_alarm.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/drivers/stm32/tone_alarm/tone_alarm.cpp b/src/drivers/stm32/tone_alarm/tone_alarm.cpp index beffbdd8b6..023ce426cc 100644 --- a/src/drivers/stm32/tone_alarm/tone_alarm.cpp +++ b/src/drivers/stm32/tone_alarm/tone_alarm.cpp @@ -121,6 +121,7 @@ #if TONE_ALARM_TIMER == 2 # define TONE_ALARM_BASE STM32_TIM2_BASE # define TONE_ALARM_CLOCK STM32_APB1_TIM2_CLKIN +# define TONE_ALARM_CLOCK_POWER_REG STM32_RCC_APB1ENR # define TONE_ALARM_CLOCK_ENABLE RCC_APB1ENR_TIM2EN # ifdef CONFIG_STM32_TIM2 # error Must not set CONFIG_STM32_TIM2 when TONE_ALARM_TIMER is 2 @@ -128,6 +129,7 @@ #elif TONE_ALARM_TIMER == 3 # define TONE_ALARM_BASE STM32_TIM3_BASE # define TONE_ALARM_CLOCK STM32_APB1_TIM3_CLKIN +# define TONE_ALARM_CLOCK_POWER_REG STM32_RCC_APB1ENR # define TONE_ALARM_CLOCK_ENABLE RCC_APB1ENR_TIM3EN # ifdef CONFIG_STM32_TIM3 # error Must not set CONFIG_STM32_TIM3 when TONE_ALARM_TIMER is 3 @@ -135,6 +137,7 @@ #elif TONE_ALARM_TIMER == 4 # define TONE_ALARM_BASE STM32_TIM4_BASE # define TONE_ALARM_CLOCK STM32_APB1_TIM4_CLKIN +# define TONE_ALARM_CLOCK_POWER_REG STM32_RCC_APB1ENR # define TONE_ALARM_CLOCK_ENABLE RCC_APB1ENR_TIM4EN # ifdef CONFIG_STM32_TIM4 # error Must not set CONFIG_STM32_TIM4 when TONE_ALARM_TIMER is 4 @@ -142,6 +145,7 @@ #elif TONE_ALARM_TIMER == 5 # define TONE_ALARM_BASE STM32_TIM5_BASE # define TONE_ALARM_CLOCK STM32_APB1_TIM5_CLKIN +# define TONE_ALARM_CLOCK_POWER_REG STM32_RCC_APB1ENR # define TONE_ALARM_CLOCK_ENABLE RCC_APB1ENR_TIM5EN # ifdef CONFIG_STM32_TIM5 # error Must not set CONFIG_STM32_TIM5 when TONE_ALARM_TIMER is 5 @@ -149,6 +153,7 @@ #elif TONE_ALARM_TIMER == 9 # define TONE_ALARM_BASE STM32_TIM9_BASE # define TONE_ALARM_CLOCK STM32_APB2_TIM9_CLKIN +# define TONE_ALARM_CLOCK_POWER_REG STM32_RCC_APB2ENR # define TONE_ALARM_CLOCK_ENABLE RCC_APB2ENR_TIM9EN # ifdef CONFIG_STM32_TIM9 # error Must not set CONFIG_STM32_TIM9 when TONE_ALARM_TIMER is 9 @@ -156,6 +161,7 @@ #elif TONE_ALARM_TIMER == 10 # define TONE_ALARM_BASE STM32_TIM10_BASE # define TONE_ALARM_CLOCK STM32_APB2_TIM10_CLKIN +# define TONE_ALARM_CLOCK_POWER_REG STM32_RCC_APB2ENR # define TONE_ALARM_CLOCK_ENABLE RCC_APB2ENR_TIM10EN # ifdef CONFIG_STM32_TIM10 # error Must not set CONFIG_STM32_TIM10 when TONE_ALARM_TIMER is 10 @@ -163,6 +169,7 @@ #elif TONE_ALARM_TIMER == 11 # define TONE_ALARM_BASE STM32_TIM11_BASE # define TONE_ALARM_CLOCK STM32_APB2_TIM11_CLKIN +# define TONE_ALARM_CLOCK_POWER_REG STM32_RCC_APB2ENR # define TONE_ALARM_CLOCK_ENABLE RCC_APB2ENR_TIM11EN # ifdef CONFIG_STM32_TIM11 # error Must not set CONFIG_STM32_TIM11 when TONE_ALARM_TIMER is 11 @@ -376,7 +383,7 @@ ToneAlarm::init() stm32_configgpio(GPIO_TONE_ALARM_IDLE); /* clock/power on our timer */ - modifyreg32(STM32_RCC_APB1ENR, 0, TONE_ALARM_CLOCK_ENABLE); + modifyreg32(TONE_ALARM_CLOCK_POWER_REG, 0, TONE_ALARM_CLOCK_ENABLE); /* initialise the timer */ rCR1 = 0; From 85bf7c31aba0b812f7ea52b8d761449d9410c2c3 Mon Sep 17 00:00:00 2001 From: Karl Schwabe Date: Sat, 29 Aug 2015 00:07:20 +0200 Subject: [PATCH 3/4] HRT driver fix : Incorrect APBs for timers 5, 10 and 11. --- src/drivers/stm32/drv_hrt.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/drivers/stm32/drv_hrt.c b/src/drivers/stm32/drv_hrt.c index 0ea6bd8d04..74c81b7a0e 100644 --- a/src/drivers/stm32/drv_hrt.c +++ b/src/drivers/stm32/drv_hrt.c @@ -112,7 +112,7 @@ #elif HRT_TIMER == 5 # define HRT_TIMER_BASE STM32_TIM5_BASE # define HRT_TIMER_POWER_REG STM32_RCC_APB1ENR -# define HRT_TIMER_POWER_BIT RCC_APB2ENR_TIM5EN +# define HRT_TIMER_POWER_BIT RCC_APB1ENR_TIM5EN # define HRT_TIMER_VECTOR STM32_IRQ_TIM5 # define HRT_TIMER_CLOCK STM32_APB1_TIM5_CLKIN # if CONFIG_STM32_TIM5 @@ -138,7 +138,7 @@ # endif #elif HRT_TIMER == 10 # define HRT_TIMER_BASE STM32_TIM10_BASE -# define HRT_TIMER_POWER_REG STM32_RCC_APB1ENR +# define HRT_TIMER_POWER_REG STM32_RCC_APB2ENR # define HRT_TIMER_POWER_BIT RCC_APB2ENR_TIM10EN # define HRT_TIMER_VECTOR STM32_IRQ_TIM1UP # define HRT_TIMER_CLOCK STM32_APB2_TIM10_CLKIN @@ -147,7 +147,7 @@ # endif #elif HRT_TIMER == 11 # define HRT_TIMER_BASE STM32_TIM11_BASE -# define HRT_TIMER_POWER_REG STM32_RCC_APB1ENR +# define HRT_TIMER_POWER_REG STM32_RCC_APB2ENR # define HRT_TIMER_POWER_BIT RCC_APB2ENR_TIM11EN # define HRT_TIMER_VECTOR STM32_IRQ_TIM1TRGCOM # define HRT_TIMER_CLOCK STM32_APB2_TIM11_CLKIN From 8e16fdeebf62211025257a4e220518b004c8ced3 Mon Sep 17 00:00:00 2001 From: Karl Schwabe Date: Sat, 29 Aug 2015 00:29:52 +0200 Subject: [PATCH 4/4] pwm_input bug fix: Incorrect APBs on timers 5, 9, 10, 11 and 12 --- src/drivers/pwm_input/pwm_input.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/drivers/pwm_input/pwm_input.cpp b/src/drivers/pwm_input/pwm_input.cpp index c137517591..06d660d92c 100644 --- a/src/drivers/pwm_input/pwm_input.cpp +++ b/src/drivers/pwm_input/pwm_input.cpp @@ -105,7 +105,7 @@ #elif PWMIN_TIMER == 2 # define PWMIN_TIMER_BASE STM32_TIM2_BASE # define PWMIN_TIMER_POWER_REG STM32_RCC_APB1ENR -# define PWMIN_TIMER_POWER_BIT RCC_APB2ENR_TIM2EN +# define PWMIN_TIMER_POWER_BIT RCC_APB1ENR_TIM2EN # define PWMIN_TIMER_VECTOR STM32_IRQ_TIM2 # define PWMIN_TIMER_CLOCK STM32_APB1_TIM2_CLKIN #elif PWMIN_TIMER == 3 @@ -123,7 +123,7 @@ #elif PWMIN_TIMER == 5 # define PWMIN_TIMER_BASE STM32_TIM5_BASE # define PWMIN_TIMER_POWER_REG STM32_RCC_APB1ENR -# define PWMIN_TIMER_POWER_BIT RCC_APB2ENR_TIM5EN +# define PWMIN_TIMER_POWER_BIT RCC_APB1ENR_TIM5EN # define PWMIN_TIMER_VECTOR STM32_IRQ_TIM5 # define PWMIN_TIMER_CLOCK STM32_APB1_TIM5_CLKIN #elif PWMIN_TIMER == 8 @@ -134,28 +134,28 @@ # define PWMIN_TIMER_CLOCK STM32_APB2_TIM8_CLKIN #elif PWMIN_TIMER == 9 # define PWMIN_TIMER_BASE STM32_TIM9_BASE -# define PWMIN_TIMER_POWER_REG STM32_RCC_APB1ENR +# define PWMIN_TIMER_POWER_REG STM32_RCC_APB2ENR # define PWMIN_TIMER_POWER_BIT RCC_APB2ENR_TIM9EN # define PWMIN_TIMER_VECTOR STM32_IRQ_TIM1BRK -# define PWMIN_TIMER_CLOCK STM32_APB1_TIM9_CLKIN +# define PWMIN_TIMER_CLOCK STM32_APB2_TIM9_CLKIN #elif PWMIN_TIMER == 10 # define PWMIN_TIMER_BASE STM32_TIM10_BASE -# define PWMIN_TIMER_POWER_REG STM32_RCC_APB1ENR +# define PWMIN_TIMER_POWER_REG STM32_RCC_APB2ENR # define PWMIN_TIMER_POWER_BIT RCC_APB2ENR_TIM10EN # define PWMIN_TIMER_VECTOR STM32_IRQ_TIM1UP # define PWMIN_TIMER_CLOCK STM32_APB2_TIM10_CLKIN #elif PWMIN_TIMER == 11 # define PWMIN_TIMER_BASE STM32_TIM11_BASE -# define PWMIN_TIMER_POWER_REG STM32_RCC_APB1ENR +# define PWMIN_TIMER_POWER_REG STM32_RCC_APB2ENR # define PWMIN_TIMER_POWER_BIT RCC_APB2ENR_TIM11EN # define PWMIN_TIMER_VECTOR STM32_IRQ_TIM1TRGCOM # define PWMIN_TIMER_CLOCK STM32_APB2_TIM11_CLKIN #elif PWMIN_TIMER == 12 # define PWMIN_TIMER_BASE STM32_TIM12_BASE # define PWMIN_TIMER_POWER_REG STM32_RCC_APB1ENR -# define PWMIN_TIMER_POWER_BIT RCC_APB2ENR_TIM12EN -# define PWMIN_TIMER_VECTOR STM32_IRQ_TIM1TRGCOM -# define PWMIN_TIMER_CLOCK STM32_APB2_TIM12_CLKIN +# define PWMIN_TIMER_POWER_BIT RCC_APB1ENR_TIM12EN +# define PWMIN_TIMER_VECTOR STM32_IRQ_TIM8BRK +# define PWMIN_TIMER_CLOCK STM32_APB1_TIM12_CLKIN #else # error PWMIN_TIMER must be a value between 1 and 12 #endif