Skip to content

Commit bf133f7

Browse files
committed
stmhal: Resolve question in comment about timer clock.
1 parent 2c781ea commit bf133f7

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

stmhal/timer.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,11 @@ STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *self, uint n_args, const
274274
tim_clock = HAL_RCC_GetPCLK1Freq();
275275
}
276276

277-
// compute the prescaler value so TIM triggers at freq-Hz
278-
// dpgeorge: I don't understand why we need to multiply tim_clock by 2
277+
// Compute the prescaler value so TIM triggers at freq-Hz
278+
// On STM32F405/407/415/417 there are 2 cases for how the clock freq is set.
279+
// If the APB prescaler is 1, then the timer clock is equal to its respective
280+
// APB clock. Otherwise (APB prescaler > 1) the timer clock is twice its
281+
// respective APB clock. See DM00031020 Rev 4, page 115.
279282
uint32_t period = MAX(1, 2 * tim_clock / vals[0].u_int);
280283
uint32_t prescaler = 1;
281284
while (period > 0xffff) {

0 commit comments

Comments
 (0)