From a125228d1fd1944bff85f15dfea205c70c256493 Mon Sep 17 00:00:00 2001 From: Petr Ledvina Date: Thu, 26 Mar 2015 18:07:18 +0100 Subject: [PATCH 1/2] Fix PPM in TIM1 --- src/main/drivers/timer.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/main/drivers/timer.c b/src/main/drivers/timer.c index f17c54f211..7ad90c065d 100644 --- a/src/main/drivers/timer.c +++ b/src/main/drivers/timer.c @@ -383,6 +383,24 @@ void timerConfigure(const timerHardware_t *timerHardwarePtr, uint16_t period, ui configTimeBase(timerHardwarePtr->tim, period, mhz); TIM_Cmd(timerHardwarePtr->tim, ENABLE); timerNVICConfigure(timerHardwarePtr->irq); + // HACK - enable second IRQ on timers that need it + switch(timerHardwarePtr->irq) { +#if defined(STM32F10X) + case TIM1_CC_IRQn: + timerNVICConfigure(TIM1_UP_IRQn); + break; +#endif +#ifdef STM32F303xC + case TIM1_CC_IRQn: + timerNVICConfigure(TIM1_UP_TIM16_IRQn); + break; +#endif +#if defined(STM32F10X_XL) + case TIM8_CC_IRQn: + timerNVICConfigure(TIM8_UP_IRQn); + break; +#endif + } } // allocate and configure timer channel. Timer priority is set to highest priority of its channels From 68305a39293d9ebfd330b2b438697d0796dbc0e9 Mon Sep 17 00:00:00 2001 From: Petr Ledvina Date: Thu, 26 Mar 2015 18:17:21 +0100 Subject: [PATCH 2/2] Fix timer period on STM32F303 TIM2 TIM2 is 32bit itmer, but we want 16bit period ... --- src/main/drivers/timer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/drivers/timer.c b/src/main/drivers/timer.c index 7ad90c065d..0d44bd0eb1 100644 --- a/src/main/drivers/timer.c +++ b/src/main/drivers/timer.c @@ -366,7 +366,7 @@ void configTimeBase(TIM_TypeDef *tim, uint16_t period, uint8_t mhz) TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; TIM_TimeBaseStructInit(&TIM_TimeBaseStructure); - TIM_TimeBaseStructure.TIM_Period = period - 1; // AKA TIMx_ARR + TIM_TimeBaseStructure.TIM_Period = (period - 1) & 0xffff; // AKA TIMx_ARR // "The counter clock frequency (CK_CNT) is equal to f CK_PSC / (PSC[15:0] + 1)." - STM32F10x Reference Manual 14.4.11 // Thus for 1Mhz: 72000000 / 1000000 = 72, 72 - 1 = 71 = TIM_Prescaler