From 24119176e7ff39e55c8067624d74d17ac1f0ffa3 Mon Sep 17 00:00:00 2001 From: Damien George Date: Sat, 4 Oct 2014 01:54:31 +0100 Subject: 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. --- stmhal/timer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'stmhal/timer.c') 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); -- cgit v1.2.3