From bbfd190206383577dfa5e6b4f1e7162fcffd11c8 Mon Sep 17 00:00:00 2001 From: Martin Simpson Date: Mon, 27 Jul 2015 12:16:45 +0100 Subject: [PATCH] Update pwmout_api.c Line 244 changed PclkFreq*2 to PcklFreq Line 246 changed PclkFreq to PclkFreq*2 This is proposed as the current pwmout_api.c gives the wrong period/frequency when using e.g."mypwm.period_ms(1);" For PWM1 1ms gave 500Hz and PWM2,3 and 4 gave 2KHz Applied to source as above and re-compiled this gave 1KHz outputs for all PWM's selected Tried on NUCLEO STM32F401RE will effect other NUCLEO-STM32F4 as above HAL Clocks are as follows for the F401RE Board: PCLK1=42000000 PCLK2=84000000 HCLK=84000000 Kind Regards Martin --- .../mbed/targets/hal/TARGET_STM/TARGET_STM32F4/pwmout_api.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/pwmout_api.c b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/pwmout_api.c index 3820e46f1f..e6000c1bf6 100644 --- a/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/pwmout_api.c +++ b/libraries/mbed/targets/hal/TARGET_STM/TARGET_STM32F4/pwmout_api.c @@ -241,9 +241,9 @@ void pwmout_period_us(pwmout_t* obj, int us) TimHandle.Init.Period = us - 1; if (APBxCLKDivider == RCC_HCLK_DIV1) - TimHandle.Init.Prescaler = (uint16_t)((PclkFreq*2) / 1000000) - 1; // 1 µs tick + TimHandle.Init.Prescaler = (uint16_t)((PclkFreq) / 1000000) - 1; // 1 µs tick else - TimHandle.Init.Prescaler = (uint16_t)((PclkFreq) / 1000000) - 1; // 1 µs tick + TimHandle.Init.Prescaler = (uint16_t)((PclkFreq)*2 / 1000000) - 1; // 1 µs tick TimHandle.Init.ClockDivision = 0; TimHandle.Init.CounterMode = TIM_COUNTERMODE_UP; HAL_TIM_PWM_Init(&TimHandle);