From fef715b3d645807c939299cd0aa52c236d46323f Mon Sep 17 00:00:00 2001 From: Vladimir Zidar Date: Sun, 1 Jan 2017 16:53:06 +0100 Subject: [PATCH] LP-463 Use correct timer clock for F1 target. All timers get 72M clock regardless of APB domain they live on. --- flight/pios/common/pios_servo.c | 15 ++++++--------- flight/targets/boards/coptercontrol/pios_board.h | 2 -- flight/targets/boards/oplinkmini/pios_board.h | 2 -- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/flight/pios/common/pios_servo.c b/flight/pios/common/pios_servo.c index 7dd2ca3de..61592f5a7 100644 --- a/flight/pios/common/pios_servo.c +++ b/flight/pios/common/pios_servo.c @@ -261,26 +261,23 @@ void PIOS_Servo_SetHz(const uint16_t *speeds, const uint32_t *clock, uint8_t ban new_clock = clock[i]; } - uint32_t apb_clock; + uint32_t timer_clock; // Choose the correct prescaler value for the APB the timer is attached #if defined(STM32F10X_MD) - if (timer == TIM1 || timer == TIM8) { - apb_clock = PIOS_PERIPHERAL_APB2_CLOCK; - } else { - apb_clock = PIOS_PERIPHERAL_APB1_CLOCK; - } + // F1 has both timer clock domains running at master clock speed + timer_clock = PIOS_MASTER_CLOCK; #elif defined(STM32F40_41xxx) || defined(STM32F446xx) || defined(STM32F411xE) if (timer == TIM1 || timer == TIM8 || timer == TIM9 || timer == TIM10 || timer == TIM11) { - apb_clock = PIOS_PERIPHERAL_APB2_CLOCK; + timer_clock = PIOS_PERIPHERAL_APB2_CLOCK; } else { - apb_clock = PIOS_PERIPHERAL_APB1_CLOCK; + timer_clock = PIOS_PERIPHERAL_APB1_CLOCK; } #else #error Unsupported MCU #endif - TIM_TimeBaseStructure.TIM_Prescaler = (apb_clock / new_clock) - 1; + TIM_TimeBaseStructure.TIM_Prescaler = (timer_clock / new_clock) - 1; TIM_TimeBaseStructure.TIM_Period = ((new_clock / speeds[i]) - 1); TIM_TimeBaseInit((TIM_TypeDef *)timer, &TIM_TimeBaseStructure); } diff --git a/flight/targets/boards/coptercontrol/pios_board.h b/flight/targets/boards/coptercontrol/pios_board.h index 3db6fc639..21281f229 100644 --- a/flight/targets/boards/coptercontrol/pios_board.h +++ b/flight/targets/boards/coptercontrol/pios_board.h @@ -88,8 +88,6 @@ // System Settings // ------------------------- #define PIOS_MASTER_CLOCK 72000000 -#define PIOS_PERIPHERAL_APB1_CLOCK (PIOS_MASTER_CLOCK / 2) -#define PIOS_PERIPHERAL_APB2_CLOCK (PIOS_MASTER_CLOCK / 1) // ------------------------- // Interrupt Priorities diff --git a/flight/targets/boards/oplinkmini/pios_board.h b/flight/targets/boards/oplinkmini/pios_board.h index d0277acb8..64329e688 100644 --- a/flight/targets/boards/oplinkmini/pios_board.h +++ b/flight/targets/boards/oplinkmini/pios_board.h @@ -139,8 +139,6 @@ // System Settings // ------------------------- #define PIOS_MASTER_CLOCK 72000000 -#define PIOS_PERIPHERAL_APB1_CLOCK (PIOS_MASTER_CLOCK / 2) -#define PIOS_PERIPHERAL_APB2_CLOCK (PIOS_MASTER_CLOCK / 1) // ------------------------- // Interrupt Priorities