cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to change CPU frequency during runtime on STM32F767VGT6 MCU?

AShar.9
Associate II

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

9 REPLIES 9
Danish1
Lead II

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

  1. switch to a different clock source (HSI or HSE)
  2. turn PLL off, change multiplier number, turn PLL back on
  3. Adjust wait-states of FLASH to suit your new frequency
  4. wait for PLL to lock
  5. switch to PLL clock source
  6. Recalculate baud rates

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:

  • Sleeping when you don't need to do anything
  • Reducing the frequency of AHB, APB

Hope this helps,

Danish

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.

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

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.

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.

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.

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?

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.

Piranha
Chief II

In fact all clock changes are done during runtime.