
Click the aboveblue text to follow us
The clock system is a core component of STM32 microcontrollers, responsible for providing timing signals to all modules of the chip, ensuring stable operation of the system. However, there are many easily overlooked traps in the design of the clock system. If not handled carefully, it may lead to issues such as system instability, excessive power consumption, or performance limitations.

Below are the typical clock parameters for the STM32F1 series for reference:

This article will delve into common traps in STM32 clock system design and share how to avoid these issues.
1
Improper Clock Source Selection
The STM32 series microcontrollers provide various clock sources, such as external high-speed crystal oscillators (HSE), external low-speed crystal oscillators (LSE), internal high-speed oscillators (HSI), and internal low-speed oscillators (LSI). Different clock sources have different characteristics and uses.
Some developers may overly rely on external clock sources (like HSE) during design, neglecting the advantages of internal clock sources (like HSI) in certain scenarios. While external crystals typically offer higher precision, if the design does not adequately consider the stability or supply issues of the external clock, it may lead to system instability.
When selecting a clock source, it is essential to fully consider the system’s requirements, including precision, power consumption, stability, and the reliability of the external clock source. For applications requiring high-precision clocks, an external crystal can be chosen; for low-power applications, HSI may be more suitable.
2
Incorrect Clock Tree Configuration
The STM32 clock system is managed through a clock tree, which connects multiple clock sources, PLLs (Phase-Locked Loops), and dividers. Errors in clock tree configuration are often the root cause of system timing issues.
In the STM32 clock tree configuration, the PLL is a crucial clock source. If the PLL’s multiplication or division factors are not correctly set in the design, it may lead to clock frequencies exceeding the system’s capacity, thereby affecting system stability.
When configuring the clock tree, it is vital to understand the clock requirements of each module clearly. The PLL’s multiplication and division factors must be set appropriately, ensuring that the system’s main clock frequency does not exceed the maximum supported value.
3
Clock Frequency Mismatch
Different modules of the STM32 (such as APB, AHB, peripherals) have varying clock frequency requirements. If clock frequencies are not allocated reasonably during design, it may lead to peripherals not functioning correctly or system performance not meeting standards.
For example, the clock frequencies of the APB and AHB buses should be configured according to the needs of the peripherals. If the APB bus clock is too high, it may cause some peripherals (like USART, SPI, etc.) to malfunction.
It is essential to configure clock frequencies reasonably and ensure that the clock frequency of peripherals does not exceed their operational range. By consulting the STM32 datasheet, ensure that the clock requirements of each peripheral are met.
4
Omission of Peripheral Clock Configuration
In embedded design, many developers focus only on the CPU core clock during the initial system design, neglecting the configuration of peripheral clocks. For instance, the clock sources for peripherals like USART, SPI, and I2C may depend on different bus clocks, and if these configurations are omitted, it may lead to peripherals not functioning correctly.
Some developers may overlook the clock sources for peripherals during design, potentially resulting in communication errors, timeouts, or unstable operation of the peripherals.
When configuring the clock system, in addition to setting the main clock, it is crucial to ensure that all peripheral clock sources and frequency settings are correct to avoid omissions.
5
Power Management Issues
The STM32 series MCUs support various low-power modes, such as sleep mode, stop mode, and standby mode. In these modes, the configuration of the clock system directly affects the system’s power consumption.
In low-power modes, some clock sources (like HSE) may be turned off, and certain peripheral clocks may also be disabled. If clocks are enabled at inappropriate times, it may prevent the system from reducing power consumption to the expected levels.
During design, it is necessary to use low-power modes appropriately based on application requirements and ensure that the enabling and disabling of clocks in low-power modes are controllable.
6
Clock Security Issues
In certain applications, the security of the system’s clock is crucial. The STM32 clock system has some protective mechanisms, such as independent watchdogs (IWDG) and hardware resets. If the configuration of clock security is neglected during design, it may lead to the system being unable to recover in abnormal situations.
For example, some systems may rely on external clock sources, and if the external clock fails without appropriate monitoring and switching mechanisms, the system may halt.
During design, it is essential to consider the failure of clock sources and use appropriate watchdog mechanisms or clock monitoring modules to ensure that in case of clock source issues, the system can switch to a backup clock or reset promptly.
7
Clock Settings During System Reset
Reset is a critical mechanism for ensuring system stability and reliability. The STM32 supports various reset methods, such as external reset, software reset, and independent watchdog reset. After a reset, the initialization of the clock system is crucial; incorrect clock configurations may prevent the system from starting normally after a reset.
After a reset, some clock sources may not recover in time, leading to the system being unable to function correctly post-reset.
During design, it is vital to ensure the correct order of clock initialization during the reset process and to use appropriate clock sources for system startup.
8
Clock Stability and Startup Delay
The clock sources of STM32 (especially HSE and PLL) require a certain stabilization time to begin outputting stable clock signals. If the system is started before the clock is stable, it may lead to system instability or failure to start.
Sometimes developers may overlook the startup time of clock sources like HSE and directly use the clock signal, resulting in abnormal system startup or clock instability.
When configuring clocks, it is necessary to ensure that the clock source is stable and to introduce an appropriate delay when starting the system.
9
Failure to Consider Power Supply Voltage Impact on Clock Frequency
Some STM32 series (like STM32F4) require higher power supply voltages (like 2.7-3.6V) at high clock frequencies. Insufficient voltage may lead to instability.
10
Incorrect Flash Wait Cycle Settings
Flash access speed is limited and requires wait cycles (latency) to be set according to SYSCLK frequency. For example, STM32F1 requires:
- ≤24MHz: 0 wait cycles
- 24-48MHz: 1 wait cycle
- 48-72MHz: 2 wait cycles. Incorrect settings may prevent the CPU from reading instructions correctly.
The design of the STM32 clock system is a critical aspect of embedded development, and correct configuration can ensure efficient and stable system operation.

Clickto read the original text for more exciting content~