cancel
Showing results for 
Search instead for 
Did you mean: 

Changing stm32L4 clock speed to 26 Mhz

maryam magdy
Associate II
Posted on June 03, 2018 at 01:41

Hello, I just want to make sure what I'm doing is right. I'm using MBED and stm32L4. I want to change clock speed to 26 Mhz, I plan to use MSI as input.  In order to do so, I will change the parameter PLL_M and leave the rest of the parameters as they are in the method 

uint8_t

SetSysClock_PLL_MSI

(

void

 defined in [

https://github.com/ARMmbed/mbed-os/blob/master/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L432xC/TARGET_NUCLEO_L432KC/system_clock.c#L80

]. To calculate PLL_m , I solve  for it in the equation: SystemClock = ((MSI / PLL_M) * PLL_N) / PLL_R  and set the SystemClock to 26 Mhz. Then I will call the method from my main program to change the clock speed. Can someone please correct me if I'm doing anything wrong?
7 REPLIES 7
T J
Lead
Posted on June 03, 2018 at 02:11

You can run the Cube and visualise the clock settings there.

it is very easy to do.

I checked it for you,

MSI input

PLLM /1

N = x12

R = /2

ABH prescaler /2

= 26MHz

Why so low ?

MSI input

PLLM /1

N = x40

R = /2

ABH prescaler /1

= 80MHz

Posted on June 03, 2018 at 02:40

((4 / 1) * 13) / 2 = 26

  /* MSI is enabled after System reset, activate PLL with MSI as source */

  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;

  RCC_OscInitStruct.MSIState = RCC_MSI_ON;

  RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_6; // 4 MHz

  RCC_OscInitStruct.MSICalibrationValue = RCC_MSICALIBRATION_DEFAULT;

  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI;

  RCC_OscInitStruct.PLL.PLLM = 1;

  RCC_OscInitStruct.PLL.PLLN = 13;

  RCC_OscInitStruct.PLL.PLLR = 2;

  RCC_OscInitStruct.PLL.PLLP = 7;

  RCC_OscInitStruct.PLL.PLLQ = 4;

  if(HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

  {

    /* Initialization Error */

    while(1);

  }
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 03, 2018 at 02:49

((4 / 1) * 13) / 2 = 26

MSI Range 6 for 4 MHz

M=1, N=13, R=2

Posted code, but stuck in moderation

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 03, 2018 at 04:15

I use the Quotes now, no moderation delay

Posted on June 05, 2018 at 01:21

Thank you so much. Can I use this code on mbed?

Posted on June 05, 2018 at 01:21

Thank you so much. Can I use this code on mbed to change the clock?

Posted on June 05, 2018 at 01:41

I'm not using mbed, you would need to seek specific support in the mbed forums if the build you are making isn't using the code you cited earlier.

Or consider if you can export the project to Keil, and then build/modify that to suit your requirements.

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