9 years, 2 months ago.

Switching clock frequency using the ST32L4 or STM32L1 MCUs

I have used the MBED library for some time now using the STM32L1 and plan to switch to the ST32L4 series when available. To save power, I plan to reduce the clock frequency for not so important tasks (98%) to restore it for computing intensive tasks. For the STM32L4 I plan to switch between the MSI and HSE clock sources. I looked into the mbed sources and believe I know what to do.

The question I have is what about the mbed configured Serials and Timers. Do I need to re-create this that they function properly, has somebody any advise on this?

Thank you.

2 Answers

9 years, 2 months ago.

You will have to study the chapters on clock configuration. Peripheral clocks are derived from the systemcore clock, which is generated by a PLL that gets its input from the HSI or other sources. Just switching the clocksource at runtime to a lower frequency will reduce the systemcore clock and also affects the peripheral clocks. In general that will mean your serials (baudrate) and timers now use the wrong reference and are all incorrect. Some peripherals will adjust to the clockfreq at boottime, others will adjust on instantiation. The latter ones will not be able to detect that you have switched clocksources at runtime and they need to be fixed (when you wish to use them during the slow phases) or you need to delete the objects and instantiate them again when another clock has been selected.

It may be easier to just stick to one clockfreq and put the device in sleep mode, waking up at regular intervals to see what needs to be done or waking up on interrupts.

Accepted Answer

Thanks, I will investigate into it further. I plan to use the L4 stop2 mode and wakeup on interrupts and periodically every 30 seconds. For the L1 I found here an RTC wakeup which wakes up from the deepsleep. The current L4 implementation uses a stop1 mode only I will replace it with stop2 and hopefully to get down to 2uA. Another wakeup or timer option will be the WDOG which is clock sourced from the RTC which is independent of the CPU clock.

Now I am waiting for the mbed STM32L4 support of the Nucleo and Discovery boards. I have seen the STM code checkins for the L4 in the mbed repository, I hope that the L4 gets supported soon.

posted by Helmut Tschemernjak 09 Sep 2015
9 years, 2 months ago.

I think UARTs reread the core clock when you set the baudrate again, but Timers are only set once when the first one is instantiated. You can manually change the prescaler of the Timer mbed uses to make it correct again, but in general for power consumption of many application the most effective way is going into deepsleep (this depends on your application though).

Thank you for your help. See my comments above.

posted by Helmut Tschemernjak 09 Sep 2015