How to change system clock frequency on NUCLEO-L476RG

Toolchain:
IAR Embeded Workbench ARM
Toolchain version:
89.20.2
MbedOS version:
6.9.0
Target:
nucleo-L476RG

Hi,

I’m using an NUCLEO-L476RG.
I want to change system clock frequency from 80MHz to 8MHz.
What should I do to change system clock frequency?

Thank you, Soichiro

Hello Soichiro,

To reduce the system clock frequency you should modify the PLL coefficients in the
/mbed/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L476xG/system_clock.c file.
The easiest way to figure out the target values is to use STM’s tool STM32MX, which you can download from the STM website for free.

  • Start a new project by clicking on the Access to board selector button:

STM32MX_01

  • In the part number combo box Slect STM32L476RG:

  • In Categories on the Pinout & Configuration tab click on the RCC (Reset an Clock Control) item and for the High Speed CLock (HSE) select Crystal/Ceramic Resonator.

  • Proceed to the Clock Configuration tab. Make sure the Input frequency is set to 8 (MHz), HSE is selected as input for the PLL block and the PLLCLK is selected as source for the SYSCLK (System Clock).
    Then start to vary the PLLM, PLLN and PLLR coefficients until you get the selected target SYSCLK.

  • Once you have succeeded (see in the picture above), modify accordingly the corresponding PLL coefficients in the file mbed/targets/TARGET_STM/TARGET_STM32L4/TARGET_STM32L476xG/system_clock.c:
    ...
#if HSE_VALUE==8000000
    RCC_OscInitStruct.PLL.PLLM              = 2; // VCO input clock = 4 MHz (8 MHz / 2)
#else
#error Unsupported externall clock value, check HSE_VALUE define
#endif
    RCC_OscInitStruct.PLL.PLLN              = 16; // VCO output clock = 64 MHz (4 MHz * 16)
    RCC_OscInitStruct.PLL.PLLP              = 7;
    RCC_OscInitStruct.PLL.PLLQ              = 2;
    RCC_OscInitStruct.PLL.PLLR              = 8;  // PLL clock = 8 MHz (64 MHz / 8)
    ...
2 Likes

Hello, hudakz.

Thank you for your advice.

I try to modify “system_clock.c” , but my application stop on creating instance of bufferedserial class.

What I did is as shown below.

  1. Change PLLN value from 40 to 8.
    2.Change PLLR value from 4 to 8.

Do you have any ideas what should I do to use BufferedSerial in addition I did?

Thank you, Soichiro.

Hi,

I want to use other clocks, (e.g. HSI or MSI), as SYSCLK source, because realized that power consumption of PLL is high.
Could you give me some advice what should I do to use HSI or MSI as SYSCLK source?

Thanks, Soichiro.

Hi,

  • Why would you like to reduce the system clock from 80 MHz to 8 MHz?

  • Why did you decide to use different settings than advised? Those setting will not produce an 8 MHz system clock.

Do you have any ideas what should I do to use BufferedSerial in addition I did?

  • The working speed of peripherals depends on the system clock frequency. To get the desired bit rate of a UART (BufferedSerial) the mbed system software divides the system clock frequency by some predefined set of coefficients. If the system clock is too low than it could happen that the required bit rate cannot be achieved.

I want to use other clocks, (e.g. HSI or MSI), as SYSCLK source, because realized that power consumption of PLL is high.
Could you give me some advice what should I do to use HSI or MSI as SYSCLK source?

  • To use HSI as clock source add an mbed_app.json with the following content to your project:
{
    "target_overrides": {
        "*": {
            "target.clock_source": "USE_PLL_HSI"        
        }
    }
}
  • To use MSI as clock source add an mbed_app.json with the following content to your project:
{
    "target_overrides": {
        "*": {
            "target.clock_source": "USE_PLL_MSI"        
        }
    }
}

Please notice that the above settings will use the PLL block.
Unfortunately, I don’t know how to make it work without using the PLL block :frowning:

Hi,

Do you have any ideas what should I do to use BufferedSerial in addition I did?

It worth to call SystemCoreClockUpdate() function and then, set the baud rate.
I did it before using Non-ST target board as below:
https://os.mbed.com/users/MACRUM/notebook/lpcxpresso1769-om13085/

Thank you for your reply.

  • Why would you like to reduce the system clock from 80MHz to 8 MHz?
    For Reduce Power consumption.
  • Why did you decide to use different settings than advised? Those setting will not produce an 8 MHz system clock.

Because the nucleo-L476RG board does not have an external crystal to use HSE.
MSI is used for PLL in default setting of mbedOS, so I tried the configuration with MSI.
I think my setting can produce 8MHz system clock. But this setting did not work.

  • The working speed of peripherals depends on the system clock frequency. To get the desired bit rate of a UART ( BufferedSerial ) the mbed system software divides the system clock frequency by some predefined set of coefficients. If the system clock is too low than it could happen that the required bit rate cannot be achieved.

I asked STM if the 115.2kHz UART work on my settings, (e.g. 8MHz clock, 16 over sampling and so on), and got answer YES.
So I guessed the reason why UART did not work is there are some setting I should do in addition I did.

Unfortunately, I don’t know how to make it work without using the PLL block :frowning:

OK. I understood the system clock setting of mbed assuming to use PLL block.

Thank you for your advice.
I will try o call SystemCoreClockUpdate() function.

Hi,

I tred to use SystemCoreClockUpdate() function after changing SYSCLK source setting shown as below.

As a result, I could change SYSCLK from PLL to MSI and can set baud rate of UART.
However the setting of SYSCLK change back to PLL after ThisThread::sleep_for() function.
I guess the setting of SYSCLK is changed by callback function in sleep_for().
I want to know how to avoid to change back SYSCLK setting.
Could you give me some advice?

Thanks, Soichiro

Sorry for my reply.

I could change clock source and frequency when I did below.

  • Change clock CLOCK_SOURCE setting from USE_PLL_MSI to USE_PLL_HSI in mbed_config.h
  • Configure SetSysClock_PLL_HSI(void) in system_clock.c as below.
    • Change RCC_ClkInitStruct.SYSCLKSource from RCC_SYSCLKSOURCE_PLLCLK to RCC_SYSCLKSOURCE_HSI
    • Change FLASH_LATENCY setting from FLASH_LATENCY_4 to FLASH_LATENCY_0
  • Call SystemCoreClockUpdate() function before setting uart baudrate.

Thank you for your many advice.