diff options
author | Damien George <damien.p.george@gmail.com> | 2014-10-04 01:54:31 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-10-04 01:54:31 +0100 |
commit | 24119176e7ff39e55c8067624d74d17ac1f0ffa3 (patch) | |
tree | 104e9f4c089414658f7378f333db3350c623e3cb /stmhal/timer.c | |
parent | c568a2b44387bee14ea5f427a6e9b736eb1b5345 (diff) | |
download | micropython-24119176e7ff39e55c8067624d74d17ac1f0ffa3.tar.gz micropython-24119176e7ff39e55c8067624d74d17ac1f0ffa3.zip |
stmhal: Allow pyb.freq() function to change SYSCLK frequency.
Eg pyb.freq(120000000) sets the CPU to 120MHz. The frequency can be set
at any point in the code, and can be changed as many times as you like.
Note that any active timers will need to be reconfigured after a freq
change.
Valid range is 24MHz to 168MHz (but not all freqs are supported). The
code maintains a 48MHz clock for the USB at all times and it's possible
to change the frequency at a USB REPL and keep the REPL alive (well,
most of the time it stays, sometimes it resets the USB for some reason).
Note that USB does not work with pyb.freq of 24MHz.
Diffstat (limited to 'stmhal/timer.c')
-rw-r--r-- | stmhal/timer.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/stmhal/timer.c b/stmhal/timer.c index 14ef3cc4a9..5efecbc9d2 100644 --- a/stmhal/timer.c +++ b/stmhal/timer.c @@ -181,7 +181,7 @@ void timer_tim3_init(void) { TIM3_Handle.Instance = TIM3; TIM3_Handle.Init.Period = (USBD_CDC_POLLING_INTERVAL*1000) - 1; // TIM3 fires every USBD_CDC_POLLING_INTERVAL ms - TIM3_Handle.Init.Prescaler = 84-1; // for System clock at 168MHz, TIM3 runs at 1MHz + TIM3_Handle.Init.Prescaler = 2 * HAL_RCC_GetPCLK1Freq() / 1000000 - 1; // TIM3 runs at 1MHz TIM3_Handle.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; TIM3_Handle.Init.CounterMode = TIM_COUNTERMODE_UP; HAL_TIM_Base_Init(&TIM3_Handle); |