cancel
Showing results for 
Search instead for 
Did you mean: 

How to change MSI frequency on the fly ?

VGava
Associate II

Hi, 

I am working on an STM32L476RCT6 and I use STM32CubeMX to configure the peripherals of the microcontroller.

Currently the microcontroller runs on MSI, whose frequency is set at 8 MHz. The clock configuration is as follows :

0693W000008zHvSQAU.pngI want to use the USB interface of the microcontroller in Device Only mode. In such a case, I get two problems in the clock configuration menu, which you can see below :

0693W000008zHsAQAU.pngCLK48 Clock Mux frequency needs to be 48 MHz, and HCLK needs to be > 14 MHz.

The USB interface will be rarely used and I need to maintain a low power consumption, I was thus thinking of switching clocks/frequencies only when USB is needed, and then go back to the initial clock configuration.

One solution could be to switch MSI frequency to 48 MHz, and then go back to 8 MHz. Which steps do I need to follow to make this change ?

I do not care about having to wait for clocks to stabilize, and I do not have an HSE on my card.

Is there a better solutionn, like using the PLL ? 

Thanks.

3 REPLIES 3
Uwe Bonnes
Principal III

If you do not need to care for VOS or wait state setting, just set the register.

You'd likely need to walk the RCC/PLL settings thru viable clocks to reconfigure.

You can't change the PLL settings on the fly, it has to be disabled, changed, renabled, locked

Similarly you need to switch the system to a working clock in the interim.

Consider, HSI ON, wait HSI ready, PLL settings to use HSI, wait for PLL lock, switch to PLL source

Going back, switch to MSI source, disable PLL and HSI

Watch also your FLASH wait states, and APB and AHB clocking. Watch other peripherals, like USART where baud rates will change based on the peripheral's source clock.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Uwe Bonnes
Principal III

You do not need PLL to run at 48 MHz. you can use MSI, so no need to switch PLL.