2020-02-12 11:38 PM
I have a project which uses STM32F767VGT6 MCU. I have the basic initialisation done through CubeMX and it runs on 40MHz frequency. During runtime, I would like to increase or decrease this CPU frequency. Is it possible to do so, and if yes can you please guide me on how to do this?
Thanks
2020-02-13 12:26 AM
It certainly is possible. But I think CubeMX will get in the way because it is only designed to support a single frequency.
How to do this.
Fundamentals:
At higher speeds, stm32 uses a Phase-Locked-Loop (PLL) to multiply a reference frequency by a number to get your wanted frequency. You want to change that number to get a different frequency. During such a change, the output of the PLL might go too high for the cpu to cope with, so ST do not allow you to change the number while the cpu uses the PLL as its clock source.
Anything that gets its clock from the PLL (e.g. USARTs, PWM) will be unpredictable, probably unusable, during the change
So you will have to
All this is explained in the Reference Manual for your stm32. But (by using CubeMX) you are at a disadvantage because you don't know what other CubeMX things you also have to set up to allow it to re-calculate e.g. baud rates for USARTs.
Edit:
Because this is difficult, you should consider why you want to do this. (You don't need to tell us why but it would show that you are taking things seriously). A valid reason is to save power, but remember that you can save a significant portion of your system power by:
Hope this helps,
Danish
2020-02-13 01:00 AM
Running at reduced speed does not necessarily reduce overall power consumption.
A company called Energy Micro (now bought up by Cypress AFAIK) had success with optimizing sleep mode consumption of Cortex M cores instead.
Short burst execution periods with optimized sleep consumption might be better suited for battery operations.
2020-02-13 02:03 AM
Hey,
Thanks for your response. The reason why I want to do this is not just to save power.
My board has multiple peripherals and the controller has to wait for those peripherals to complete their work. I can't put the controller to sleep during this time as it doesn't maintain it's GPIO's. Also, during some heavy processing, I want it to be running on higher frequencies so that it doesn't take lots of time. As @Ozone also mentioned, short bursts can help more with battery optimization.
I do understand the basic principle behind switching PLL multiplier, just wanted to make sure if someone else has tried it before and got it to work.
Thanks
2020-02-13 02:25 AM
Could you expand on what you mean by "doesn't maintain it's GPIO's"?
While the cpu is sleeping, all GPIO stay in their current state. This is irrespective of whether you maintain or freeze the AHBx clock to the GPIO.
2020-02-13 02:49 AM
The usual reasons to switch clocks during runtime is either clock fail recovery, or reducing consumption (switch-over to LSI).
While waiting for your peripherals (whatever that means in your context), you could as well do other task, or even busy-idling.
I use to avoid adding unnecessary complexity.
> Also, during some heavy processing, I want it to be running on higher frequencies so that it doesn't take lots of time.
Check that you don't loose more time waiting on the clock chain + PLL to stabilize, then you gain by raising the core clock.
2020-02-13 02:52 AM
Hey,
Apologies, I got confused between sleep and standby modes. GPIO are maintained in sleep but not in standby mode.
But the reason why I can't put the controller to sleep is that the controller is providing clock to another peripheral. If controller goes to sleep, then the clock will also stop on GPIO (please correct if I am wrong on this.) The clock is being generated using the microcontroller clock output (MCO) pin.
2020-02-13 03:12 AM
I've never used MCO myself.
My reading of the Reference Manual, in particular the Clock Tree figure, makes me think MCO is always fed even when sleeping.
If it's easy, can you test this and report back?
2020-02-13 03:21 AM
Ok, I will test and report back.
But I think I need to reconsider my requirements for this. Thank you both for your feedback. Really appreciate it.
2020-02-18 06:13 AM
In fact all clock changes are done during runtime.