Skip to main content
maryam magdy
Associate III
June 2, 2018
Question

Changing stm32L4 clock speed to 26 Mhz

  • June 2, 2018
  • 7 replies
  • 1464 views
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?
    This topic has been closed for replies.

    7 replies

    T J
    Senior III
    June 3, 2018
    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

    Tesla DeLorean
    Guru
    June 3, 2018
    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
    T J
    Senior III
    June 3, 2018
    Posted on June 03, 2018 at 04:15

    I use the Quotes now, no moderation delay

    Tesla DeLorean
    Guru
    June 3, 2018
    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
    maryam magdy
    Associate III
    June 5, 2018
    Posted on June 05, 2018 at 01:21

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

    Tesla DeLorean
    Guru
    June 5, 2018
    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..