cancel
Showing results for 
Search instead for 
Did you mean: 

How to use STM32CubeMX to configure HSE (High-Speed External Oscillator) and LSE (Low-Speed External Oscillator)

Stefanie LAU
ST Employee

How can I use STM32CubeMX to configure HSE (high-speed external oscillator) or LSE (low-speed external oscillator)?

The STM32 MCUs support several possible clock sources, several internal oscillators, and two external oscillators, which require external components. By default, the STM32 microcontroller’s internal oscillators are suitable for various application use cases. However, in the case that a very accurate clock is needed it is recommended to incorporate the usage of external oscillators.
The two external oscillators STM32 MCUs' supports are:
  • High-speed external oscillator (HSE)
    • The external oscillator has the advantage of producing a very accurate main clock. Using a 25 MHz oscillator is a good choice for an accurate USB OTG high-speed peripheral, I2S and SAI.
  • Low-speed external oscillator (LSE)
    • The external oscillator has the advantage of providing a low-power highly accurate clock source needed for real-time clock (RTC), clock/calendar, and other timing functions.
The HSE and LSE can be provided from an external source using the OSC_IN and OSC32_IN pins (bypass mode) or a crystal/ceramic resonator.
For a deeper dive on oscillator design and HSE/LSE hardware configuration requirements, please review AN2867 (oscillator design guide for STM8AF/AL/S, STM32 MCUs and MPUs) and your STM32’s respective hardware development application note.
STM32CubeMX is a graphical tool that allows you to quickly configure any STM32 microcontroller and microprocessors as well as generate the corresponding initialization C code for the Arm Cortex-M core or a partial Linux device tree for an Arm Cortex-A core.
Through using STM32CubeMX, you can easily navigate and modify your project’s desired HSE/LSE software configurations with the click of a button.
In this article, we go over step-by-step the following:
  1. How to check if you have the HSE/LSE clock configured in your current project
  2. How to configure the HSE/LSE clock source in STM32CubeMX
  3. How to disable the HSE/LSE clock source in STM32CubeMX

1. Checking your current HSE/LSE clock configuration in STM32CubeMX

The quickest and easiest way to check if you have the HSE/LSE configured in your current project is by checking the clock configuration tab in your project’s .ioc file.
In the example HSE/LSE clock configuration below. We see that the input frequency to LSE is highlighted in blue while the input frequency to HSE is greyed out. Icons highlighted in blue are available and for the most part are modifiable while greyed out icons are unavailable and cannot be modified. Therefore, we can conclude that in this example case, the LSE is configured while the HSE is not.
1035.png

2. Enabling the HSE/LSE clock configuration in STM32CubeMX

Step 1. Launch your project’s .ioc file, and start at the pinout and configuration tab.
1036.png
Step 2. On the left-hand side navigation bar, expand the system Core tab and select RCC (Reset and Clock Controller). The RCC peripheral is used to control the internal peripherals including the reset signals and clock distribution. In the RCC category, you have the option to enable/disable the HSE, LSE, MCO (master clock output), Audio Clock Input (I2S_CKIN), and CRS Sync. In addition, configure parameters such as the MCU's power parameters, RCC parameters, the MCU's system parameters and PLL (phase-locked loop) range parameters. 
1037.png
Step 3. In the middle panel (RCC mode and configuration), under mode next to High-Speed clock (HSE) and Low Speed Clock (LSE) you see an option for drop-down menus. By default, the HSE and the LSE are both disabled.
1038.png

Step 4. There are 3 options that users can choose from to configure the HSE/LSE:
  • Disable – no HSE/LSE external clock source is selected
  • BYPASS clock source – the HSE/LSE clock can be provided from an external source using the OSC_IN and OSC32_IN pins. For more information on bypass requirements refer to your STM32’s reference manual namely, the HSE / LSE oscillator section.
  • Crystal/Ceramic resonator – the HSE/LSE clock can be provided from an external crystal/ceramic resonator
1039.png
Once you have selected from the available HSE/LSE clock sources, you will also see the clock pins configured on the microcontroller’s pinout view, located on the right-hand panel of the STM32CubeMX GUI.
1040.png
Step 5. To make additional modifications such as adjusting the HSE input frequency, select the clock configuration tab.
1042.png
Step 6. On the left-hand side of the clock configuration view, you see the input frequency to HSE/LSE now highlighted in blue depending on your configuration for HSE/LSE in step 4. Boxes highlighted in blue are available and modifiable for the most part, while the greyed-out boxes are not available and cannot be modified by the user. In the example shown below, both the HSE and LSE are available. 
1045.png
 

3. Disabling the HSE/LSE clock configuration in STM32CubeMX

Step 1. Launch your project’s .ioc file, and start at the pinout and configuration tab.  
1048.png
Step 2. On the left-hand side navigation bar, expand the system Core tab and select RCC.
1050.png
Step 3. In the middle panel (RCC mode and configuration), under Mode next to High Speed clock (HSE) and Low Speed clock (LSE) you see your current configuration(s) for HSE/LSE.
1052.png
Step 4. To remove the HSE/LSE from your clock configuration, use the drop-down menu to change the HSE/LSE’s current clock option to disable.
1054.png
Step 5. To verify that the HSE/LSE clock configuration has indeed been removed, visit the clock Configuration tab. If you have previously modified the PLL source mux / RTC clock mux to be sourced by HSE or LSE respectively, then STM32CubeMX is smart enough to run its automatic clock resolver. This automatic clock resolver is a function that helps review and assists in resolving any glaring clock issues.
In this example case, we previously configured the HSE to feed into the PLL source mux therefore this clock configuration resolver pop-up appeared. We proceed forward by clicking yes and running the automatic clock issue solver.
1057.png
After the automatic clock issue solver runs, we will then see that the HSE is no longer configured as the HSE and its input frequency block is greyed out and no longer a selectable option into the PLL source mux.
1060.png

Relevant documentation and links:

Version history
Last update:
‎2022-06-09 05:51 AM
Updated by: