Showing results for 
Search instead for 
Did you mean: 

Part 1: Introduction to the STM32 microcontroller clock system

ST Employee


In this article, you are introduced to the basics of the STM32 clock system. Furthermore, the tools used to easily configure the STM32 clock system. We split the article into two parts. Part two will discuss additional features and terms. If you would like to skip to part two, click this link: Part 2: Introduction to the STM32 microcontroller clock system

1. Microcontroller system clock

The MCU clock is as crucial as a heartbeat and is the silicon world’s analogy of the biological heart. The Arm® processor and all embedded peripherals inside the STM32 MCU receive one or several clocks generated by the RCC peripheral of the STM32. 


2. Reset and clock control (RCC) clock

The RCC peripheral and the number of clocks vary depending on the specific STM32 that you are working with. For this example, we use the Nucleo-H503RB in our description and project example. Some of the details like the number of phase-lock loop (PLL) are specific to the STM32H503RBT6 MCU. Overall, most of the information written here can be extrapolated to other STM32 series.


2.1 Different clock sources can be used to drive the system clock (SYSCLK) for the STM32H503:

1. HSE, also known as "high-speed external clock." External clock can be derived from two sources:

Source one:
The external clock can be fed to the MCU through the OSC_IN pin and OSC_OUT can be left as high-Z or used as a GPIO. For example, an IC chip with an integrated oscillator circuit (that is, not using MCU’s internal oscillator circuit) and a resonator can feed the clock to theOSC_IN pin. This solution is convenient because it saves you the effort of designing an external resonator circuit. A more specific example of such a system is the NSC5004A-25M. In this mode, the internal MCU oscillator is bypassed.

Source two:
The external clock can be generated by an external resonator and be interfaced with both the OSC_IN and OSC_OUT pins. For this solution, you design an external resonator circuit that interfaces with the internal oscillator circuit of the MCU. You can refer to the section 2.4 "oscillator circuit design" below for more details.



Figure 1: RM0492: Example of external clock source and external resonator circuit clock. Resonator and load capacitors must be picked by the hardware designer. Refer to AN2867.


3. HSI: Default system clock. Low-cost high-speed internal RC oscillator clock with a faster startup time than HSE (a few microseconds), but less accurate than a clock with an external resonator.

4. CSI: Low-power and low-cost internal RC oscillator with a faster startup time than HSE (a few microseconds), but less accurate than a clock with an external resonator. In terms of frequency, it sits between the low-speed and high-speed oscillators.

5. LSI: Low-speed internal RC oscillator. The LSI acts as a low-power clock source. It can be kept running when the system is in stop or standby mode for the independent watchdog (IWDG) and autowakeup unit (AWU). The clock frequency is around 32 kHz.


Good to know:

  • Internal oscillators have the disadvantage of having its frequency dependent on many external factors. We can calibrate the internal oscillator by using the trim register. When increasing the trim register value, the clock frequency increases accordingly, and vice versa when decreasing the trim register value. You can read more about internal oscillator trimming in the MCU reference manual or by referencing the application note AN5067.


5. LSE  "low-speed external oscillator." The LSE block can generate a clock from two possible sources:

  1.  External user clock: Like the HSE discussion, this would require an external module to provide clock via OSC32_IN pin while the OSC32_OUT pin must be left as high-Z. Alternatively, the OUT pin can be used as a GPIO. In this mode, the internal MCU oscillator is bypassed.
  2. External crystal/ceramic resonator: similar to the HSE discussed above, this would require a hardware designer to pick both the resonator and the load capacitors.  Refer to the "oscillator circuit design" in section 2.4 and application note AN2867 for guidance on how to do so.   


6. HSI48: RC oscillator delivering a 48 MHz clock that can be used directly as a kernel clock. See section 8 "kernel clock" for more details on the kernel clock for some peripherals, such as USB or RNG. The HSI48 oscillator mainly aims at providing a high-precision clock to the USB peripheral. This is done by means of a special clock recovery system (CRS) circuitry that can use the USB SOF signal, the LSE, or an external signal to automatically adjust the oscillator frequency on-the fly, with a very small granularity.


7. PLL: Phase locked loop clock control system multiplies frequency much more than what oscillators are capable of outputting. The clocked output by the resonators (that is, crystals/ceramics/etc.) is usually not sufficed to clock the various high-speed peripherals that are embedded on the STM32. The PLL provides the flexibility to increase the clock speed after the application PCB board has already been designed and deployed. 


Good to know:

  • You can find important characteristic data about the PLL in the datasheet. For example, for the MCU STM32H503, the datasheet DS14053 shows table "PLL characteristics (wide VCO frequency range)", which documents cycle to cycle and long term jitter for the PLL. 
  • Some STM32 series/families allow selection of drive level settings for the powering the crystal oscillator. The drive level (DL) describes the amount of power the crystal dissipates (see application note AN2867). The maximum power that can be dissipated is specified by the manufacture of the crystal. The unit of drive-level is mW.  For example, you can set the "drive capability" of STM32L476 crystal (see reference manual RM0351). 


2.2 Additional clocks found on other STM32 series:

Multispeed internal oscillator functionality is available on the STM32L series. Multispeed internal oscillator is a configurable oscillator, offering a compromise between ultra-low power and performance.


2.3 Summary of clock sources


Table 1: Example of clock source summary (example uses the STM32H503 as reference).



Relative accuracy

Main benefits



Possible resonator frequency ranges: 4-50 MHz



Requires an external resonator


64 MHz

Less accurate

Low cost and faster startup than HSE

Inside STM32 MCU


48 MHz

Accurate if used with clock recovery system (CRS)

Low cost and high precision if CRS enabled

Inside STM32 MCU


4 MHz

Less accurate

Low power, low cost, and faster startup time than HSE

Inside STM32 MCU


32.768 kHz


Low power and accuracy

Requires an external resonator


32 kHz

Less accurate

Low power and operates in low power mode

Inside STM32 MCU


2.4 Oscillator circuit design

The oscillator system consists of the crystal and the oscillator circuit. The circuit is usually internal to the MCU, though it can also come in an external package in some crystal oscillator IC. The process of oscillator design for the STM32 usually involves selecting the appropriate load capacitors for your selected crystal. We have a list of recommended crystals and capacitors in the application note AN2867. A more detailed process for the STM32 oscillator design is shared in AN2867. For further guidance in your oscillator design, see the attached spreadsheet calculator "AN2867_Crystal_Calculator.xlsx."


3. Clock tree

3.1 STM32H503 Clock Tree

Figure 2 shows the clock tree diagram as found in the STM32H503 reference manual, RM0492. The tree diagram depicts all system clock distributions. It stats from the source and moves through PLL and the prescalars, then ends at the consumer (bus and peripherals).


For most applications, the clock frequencies provided by the resonators are not sufficient, therefore we must use another module to increase the clock speed. The PLL (clock feedback control system) increases the clock frequency to satisfy the peripheral clock speed requirement.



Figure 2: RM0492: Clock tree diagram that is typically found inside the reference manual of any STM32.


Good to know:

  • Our clock tree for STM32 MCU is usually extensive and complex and the main reason is for power saving applications. This complex clock tree provides us with all the knobs and switches to change the clock speed and to turn off the clock for peripherals we will not use.


Table 2 describes the input and output shown in figure 2.


Table 2: RCC clock I/O signals.

Pin name





Low-speed output clock for external devices



Used as a GPIO or connect to one end of the resonator terminal, if designing an external low speed resonator for your design



This can be connected to an input clock from an external module. Or this pin can be connected to a second terminal of the resonator. Applicable if designing a external low speed resonator for your design



Similar to OSC32_OUT, but for high-speed resonator



Similar to OSC32_IN, but for high-speed resonator



External kernel clock input for I2S1, I2S2, and I2S3



This pin is used to direct the clock to an output pin. See the clock tree for details about which clock sources are connected to this pin.



Same as MCO1.


Figure 3 illustrates an example of the STM32H503RB MCU clock tree, which can be found under the “Clock Configuration” tab of STM32CubeMX "configurator." A convenience regarding the clock configurator is that you do not have to perform any calculations for your desired clock speed. Any potential clock conflicts are automatically resolved by this tool.



Figure 3: STM32CubeMX clock configurator tab for the STM32H5: Clock tree diagram as shown in STM32CubeMX interface.


In figure 3 above, the CPU clock is configured by the blue HCLK box near the top of the STM32CubeMX clock configuration tree.

To enable external resonators, we must select the “Crystal/Ceramic Resonator” option inside the RCC peripheral. Through RCC, we can also output the generated clock from the clock tree through master clock output 1, 2, LSCO, and SAI1 extern clock. Clock recovery system (CRS) is used to trim the frequency (up or down) when a resonator frequency leaves a set threshold. 



Figure 4: STM32CubeMX configurator: enable HSE and LSE through RCC peripheral.


An example of a generalized view on one of the PLL modules is shown in figure 5. In the case of STM32H503, there are two PLLx modules (PLL1 and PLL2). PLL1 is generally used to provide the clock to the CPU and some of the peripherals. PLL2 is used to generate the kernel clock. See section 8 "kernel clock" for more details on kernel clock for the peripherals.



Figure 5: PLL feedback control system used to increase resonator clock speed.


Figure 6 shows the PLL module configuration inside the STM32CubeMX clock configuration tab. Through the parameters M, N, R, Q, P, we can increase or decrease resonator clock speed in fine increments.



Figure 6: STM32CubeMX clock configurator tab for the STM32H5: PLL (PLL1 and PLL2).


This concludes the first part of STM32 MCU clock introduction. In part 2, we discuss additional features and provide an example code generated by the STM32CubeMX HAL generator tool. 


Related links

  1. Reference manual 0492: STM32H503 line Arm®-based 32-bit MCUs
  2. Application note 2867: Oscillator design guide for STM8AF/AL/S, STM32 MCUs and MPUs
  3. Reference manual 0351: STM32L47xxx, STM32L48xxx, STM32L49xxx and STM32L4Axxx advanced Arm®-based 32-bit MCUs
  4. Application note 5067: How to optimize STM32 MCUs internal RC oscillator accuracy
  5. Part 2: Introduction to the STM32 microcontroller clock system
Version history
Last update:
‎2024-03-11 02:10 AM
Updated by: