Usually, for some mature STM32 development boards, in the design of its circuit schematic diagram, the MCU is connected with two crystal oscillators. One is a low-speed crystal oscillator 32.768kHz, and the other is a high-speed crystal oscillator 8MHZ. The role of both is discussed below.
Article Directory
1. STM32 Schematic
Usually, some mature development boards will use two crystal oscillators when designing the schematic diagram of the STM32 chip, as shown in the figure below:
When patching the crystal oscillator, since the volume of the crystal oscillator is much larger than that of the surrounding resistors, the crystal oscillator will take up more space. As shown below:
This is not good for us to make some ultra-small boards, because the board space is limited. For this reason, we need to understand the role of these two crystal oscillators, especially the low-speed crystal oscillator 32.768kHz, and choose appropriately.
2. CubeMX clock configuration diagram
In CubeMX, the officially recommended development tool for STM32, we can visually see the clock configuration diagram of the MCU. In the figure, you can see the clock configuration of the chip, and you can also see the entrance of the low-speed crystal oscillator 32.768kHz and the high-speed crystal oscillator 8MHZ. As shown in the red box on the left side of the figure below:
2.1 Low-speed crystal oscillator 32.768kHz
It can be seen from the figure that the low-speed crystal oscillator 32.768kHz is connected to the LSE (low-speed external clock signal), and finally reaches the RTC (real-time clock).
RTC is an independent timer1 . It can be understood from the four words of real-time clock (real-time clock), RTC can record the current system time and date for the system in real time, regardless of whether the chip is powered off or not. If you want to use the RTC to record the system time in real time, the chip needs to be connected to an additional backup power supply, usually a button battery. In this way, the RTC can continue to run with battery power after the chip is powered off 2 .
For circuit boards that do not need to record the system time after power-off , we discard the low-speed crystal oscillator 32.768kHz to save board space and simplify circuit design.
2.2 High speed crystal oscillator 8MHZ
It can be seen from the figure that the 8MHz high-speed crystal oscillator is connected to HSE (high-speed external clock signal), and finally reaches SYSCLK (system clock).
SYSCLK is the system clock, which provides power for the operation of the various modules inside the chip and is indispensable. The high-speed crystal oscillator 8MHz is used as the source of the system clock, which can be provided by the HSI RC clock source inside the chip or an independent clock source outside the chip . This article 3 mentioned that when using the HSI RC clock source inside the chip as the system clock, it was found that the clock was deviated, which made the serial device unusable. Because the HSI RC clock source inside the chip is not accurate enough, we usually use an external independent clock source to provide the system clock for the chip.
For the STM32 circuit board, the external high-speed crystal oscillator 8MHz needs to be reserved to provide the system clock for the chip so that the chip can work normally.