cancel
Showing results for 
Search instead for 
Did you mean: 

[STM32L4] [RCC] Re-configure MSI Clock once SystemClock_Config() is done

sunny
Associate II
Posted on August 04, 2016 at 14:19

Hi,

I am trying to run my system at 4 MHz SYSCLK having PLLCLK as source.

PLL has MSI as Source configured at 4 MHz.

This configuration is done in SystemClock_Config() in main().

Now, I am trying to re-configure the clocks of the PLL so that the SYSCLK has 48 MHz and SDMMC1 and USB has 48 MHz via PLLQ, since I want to run the the SDCard and USB in Device Mode.

I am able to reconfigure the clocks, oscillators and peripheral clocks by calling the HAL_RCCEx_DisableMSIPLLMode().

But my USB is not getting enumerated. I am getting USB unrecognized.

So is there any graceful way to bump up the PLL clocks on the fly i.e. after the SystemClock_Config() is called.

I read the Reference Manual and it is mentioned that on System Reset, MSI is selected as Default Source and I confirmed that the same thing is done in the code.

But then how can I update my PLL block parameters if I want to keep MSI as clock source for PLLCLK and PLLCLK as source for SYSCLK.

Thanks,

Sunny

#msi #stm32l4 #rcc #clockconfig
2 REPLIES 2
Posted on August 04, 2016 at 15:11

So is there any graceful way to bump up the PLL clocks on the fly i.e. after the SystemClock_Config() is called.

In my experience no, you have to turn off the PLL to change the parameters, and you can't randomly change the input to the PLL. So you have to go through a sequence of switching to another source, turn it off, reconfigure, and come back.

Suggest you start by configuring at 48 MHz and get to a slower SYSCLK (AHB/APB) by dividing the clock source down. And then using the dividers to gear the clocking up/down.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
sunny
Associate II
Posted on August 05, 2016 at 09:09

Hi Clive,

Thank you for the pointer.

I am able to configure the MSI and PLL clocks on the fly now.

For reference, below are the steps:

Since I am using MSI as PLL source, and PLLCLK as SYSCLK, we cannot directly change PLL Parameters (Refer Reference Manual -> RCC Chapter -> Clocks -> PLL).

  1. So we need to configure firstly, MSI as SYSCLK by HAL_RCC_ClockConfig().
  2. Configure HSI Oscillator + PLL OFF by HAL_RCC_OscConfig().
  3. Configure HSI as SYSCLK by HAL_RCC_ClockConfig().
  4. Now re-configure MSI + PLL, MSI as PLL Source by HAL_RCC_OscConfig().
  5. Then re-configure the PLLCLK as SYSCLK.
Thanks,

Sunny