Skip to content

Commit fd4941f

Browse files
author
Laurent MEUNIER
committed
[STM32F3] Fix for pmw period change
The new period needs to be saved before the duty cycle is updated as the period is used in pwmout_write function. Also presclaer shall better be initiliazed properly.
1 parent e56b9d0 commit fd4941f

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

hal/targets/hal/TARGET_STM/TARGET_STM32F3/pwmout_api.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ void pwmout_init(pwmout_t* obj, PinName pin)
6969
obj->pin = pin;
7070
obj->period = 0;
7171
obj->pulse = 0;
72+
obj->prescaler = 1;
7273

7374
pwmout_period_us(obj, 20000); // 20 ms per default
7475
}
@@ -188,12 +189,12 @@ void pwmout_period_us(pwmout_t* obj, int us)
188189
error("Cannot initialize PWM");
189190
}
190191

191-
// Set duty cycle again
192-
pwmout_write(obj, dc);
193-
194192
// Save for future use
195193
obj->period = us;
196194

195+
// Set duty cycle again
196+
pwmout_write(obj, dc);
197+
197198
__HAL_TIM_ENABLE(&TimHandle);
198199
}
199200

0 commit comments

Comments
 (0)