The role of the two crystals, 32.768KHz and 8MHz, in STM32#
In general, for some mature STM32 development boards, two crystals are externally connected to the MCU in their circuit schematics. One is a low-speed crystal of 32.768kHz, and the other is a high-speed crystal of 8MHz. The following text discusses the roles of these two crystals.
1. STM32 Schematic#
In the design of the schematic for STM32 chips, it is common to use two crystals, as shown in the following figure:
When mounting the crystals, due to their larger size compared to the surrounding resistors, the crystals occupy a significant amount of space, as shown in the following figure:
This is not favorable for making some ultra-small circuit boards because of limited board space. Therefore, we need to understand the roles of these two crystals, especially the low-speed crystal of 32.768kHz, and make appropriate choices.
2. CubeMX Clock Configuration Diagram#
In the STM32 official recommended development tool, CubeMX, we can intuitively see the clock configuration diagram of the MCU. In the diagram, we can see the clock configuration of the chip, as well as the inputs for the low-speed crystal of 32.768kHz and the high-speed crystal of 8MHz, as shown in the red box on the left side of the following figure:
2.1 Low-speed Crystal of 32.768kHz#
From the diagram, it can be seen that the low-speed crystal of 32.768kHz is connected to LSE (low-speed external clock signal) and eventually reaches the real-time clock (RTC).
RTC is an independent timer [1]. As the name "real-time clock" suggests, RTC can record the current system time and date in real-time, regardless of whether the chip is powered on or off. If you want to use RTC to record the system time, the chip needs to be connected to an additional backup power source, usually a button battery. In this way, RTC can continue to operate powered by the battery when the chip is powered off [2].
For circuit boards that do not need to record the system time after power-off, we can omit the low-speed crystal of 32.768kHz to save board space and simplify the circuit design.
2.2 High-speed Crystal of 8MHz#
From the diagram, it can be seen that the high-speed crystal of 8MHz is connected to HSE (high-speed external clock signal) and eventually reaches SYSCLK (system clock).
SYSCLK is the system clock that provides power for the operation of various major modules inside the chip and is indispensable. The high-speed crystal of 8MHz serves as the source of the system clock and can be provided by the HSI RC clock source inside the chip or an external independent clock source. This article [3] mentions that when using the HSI RC clock source inside the chip as the system clock, it was found that there was a deviation in the clock, causing the serial port device to be unusable. Due to the lack of accuracy of the HSI RC clock source inside the chip, we usually use an external independent clock source to provide the system clock for the chip.
For STM32 circuit boards, the external high-speed crystal of 8MHz needs to be retained to provide the system clock for the chip to work properly.
3. References#
- 【STM32】RTC Real-Time Clock, Detailed Step-by-Step Explanation, Understand RTC in One Article ↩︎
- [RTC Real-Time Clock Experiment (Low Power Consumption, Button Battery Power Supply)](https://blog.csdn.net/zhuguanlin121/article/details/121430674?ops_request_misc=&request_id=&biz_id=102&utm_term=RTC 需要供电 & utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-0-121430674.142^v40^control,185^v2^control&spm=1018.2226.3001.4187) ↩︎
- [STM32 HSI Clock Deviation Problem](https://blog.csdn.net/Roomen0/article/details/105782637/?ops_request_misc=&request_id=&biz_id=102&utm_term=stm32 HSI 不准 & utm_medium=distribute.pc_search_result.none-task-blog-2~all~sobaiduweb~default-0-105782637.142^v40^control,185^v2^control&spm=1018.2226.3001.4187) ↩︎