summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-08-14 00:30:14 +0100
committerDamien George <damien.p.george@gmail.com>2014-08-14 00:30:14 +0100
commitbf133f7737c99d5359a52abd49e465af863fa734 (patch)
treedb0e5a2d2856c4b2b5c9287755d8aa4321282560
parent2c781eabbd42b65e6453bad7dcf07344a285f99f (diff)
downloadmicropython-bf133f7737c99d5359a52abd49e465af863fa734.tar.gz
micropython-bf133f7737c99d5359a52abd49e465af863fa734.zip
stmhal: Resolve question in comment about timer clock.
-rw-r--r--stmhal/timer.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/stmhal/timer.c b/stmhal/timer.c
index 30bcf2c079..b0b35740f5 100644
--- a/stmhal/timer.c
+++ b/stmhal/timer.c
@@ -274,8 +274,11 @@ STATIC mp_obj_t pyb_timer_init_helper(pyb_timer_obj_t *self, uint n_args, const
tim_clock = HAL_RCC_GetPCLK1Freq();
}
- // compute the prescaler value so TIM triggers at freq-Hz
- // dpgeorge: I don't understand why we need to multiply tim_clock by 2
+ // Compute the prescaler value so TIM triggers at freq-Hz
+ // On STM32F405/407/415/417 there are 2 cases for how the clock freq is set.
+ // If the APB prescaler is 1, then the timer clock is equal to its respective
+ // APB clock. Otherwise (APB prescaler > 1) the timer clock is twice its
+ // respective APB clock. See DM00031020 Rev 4, page 115.
uint32_t period = MAX(1, 2 * tim_clock / vals[0].u_int);
uint32_t prescaler = 1;
while (period > 0xffff) {