From the perspective of clock source, there are two types of external clock (E) and internal clock (I ).
From the perspective of clock rate, there are two types of high-speed clock (HS) and low-speed clock (LS ).
In combination, there are four clock types: HSE, his, LSE, and LSI. Why is there such a complicated clock configuration mainly because of two factors: system performance and power consumption. A single clock may cause excess performance and high power consumption. Multiple clocks can balance power consumption and performance.
After the system is reset, sysclock is provided for the his clock by default. That is, 16 MHz. To prompt system performance, we need to enable an external clock crystal oscillator (25 MHz on board ). After enabling, we can also see that the chip temperature has increased (using an internal temperature sensor for testing, as evidenced by the following images ).
These four types of clock are configured inside the chip to drive various peripherals. When it comes to the chip, there are more clock classifications corresponding to so many peripherals, but mainly considering the existence of the bridge, there are five categories: ahb3, ahb2, ahb1, apb2, and apb1. All peripherals in the chip are mounted on these five buses respectively. As to which peripheral is mounted on which bus, we need to check the chip's rm0410 Reference Manual (page74.
To test the clock configuration today, I will use the universal timer tim2 for the following Demonstration operations:
First, check which bus tim2 is attached:
We can see that it is mounted on the apb1 bus.
Then you can view the clock loop of Tim.
The default clock source is internal HSI after the chip is reset, no matter whether the MCU 8 or stm32 series is used. To use the HSE of the external clock source, you must enable the relevant control registers through the software.
If an external HSE is used, there are generally two modes:
1. External crystal/Ceramic Resonator (HSE crystal) Mode
This mode is common, and HSE crystals can provide accurate clock sources for the system. The hserdy bit in the clock control register rcc_cr is used to indicate whether the high-speed external oscillator is stable. At startup, the clock is released only when this bit is set to '1' by hardware. HSE crystals can be enabled and disabled by setting the hseon bit in rcc_cr in the clock control register.
The clock source is formed by the combination of an external passive crystal and the MCU internal clock driving circuit. It has a certain start time and a high accuracy. To reduce clock output distortion and reduce startup stability, the crystal/Ceramic Resonator and load capacitance must be as close as possible to the oscillator pins. The load capacitance value must be adjusted according to the selected crystal. This sentence is clearly written in the manual and often seems to be ignored. In this regard, the official st has made a special application note, numbered an2867. You can search for and download from www.stmcu.com.cn or www.st.com.
On the whole, the main difference between ceramic crystals and Z crystals lies in accuracy and temperature stability. The accuracy of Z crystals is higher than that of ceramic crystals, and the temperature stability is better.
2. HSE Bypass Mode
In this mode, an external clock must be provided. You can select this mode by setting the hsebyp and hseon bits in the clock control register. The external clock signal (50% duty cycle of the square wave, sine wave or triangular wave) must be connected to the soc_in pin. At this time, the osc_out pin is in a high-impedance state.
The HSE Bypass Mode means that the internal clock driver component of the chip is not required to use the external crystal mentioned above, and the clock signal is directly imported from the outside. The driver components inside the chip are bypassed.
However, when this mode is used, configuration Errors often occur, that is, the same configuration as the HSE crystal mode. This occurs in ipv8/stm32 applications. Fortunately, this bypass mode is not used as much as the external crystal mode, otherwise more people may be in trouble here.
Let's take the 3f4 series chip as an example.
As mentioned above, besides configuring hseon, the bypass mode also requires configuring hsebyp.
For the standard library function voidrcc_hseconfig (uint32_t rcc_hse)
Or the related parameters in the cube library function _ hal_rcc_hse_config (rcc_oscinitstruct-> hsestate) may be: rcc_hse_on, rcc_hse_bypass, or rcc_hse_off.
If you use the stm32cubemx graphic configuration interface, you can see three options:
In the Application Development of St MCU, active crystal oscillator is often used as the clock source. What kind of working mode should I choose if I use it?
An active crystal oscillator is generally enclosed in four-pin packages, including power supply, ground wire, oscillating output, and a control end [or floating end ]. Compared with passive crystals, the active crystal oscillator itself is a complete oscillator. You only need to provide an appropriate power supply to output the clock, without the need for an extra oscillator to drive the matching circuit. The clock output is independent of the oscillator circuit of the external device, and is relatively less susceptible to the instability of the external line. Naturally, the price is higher than that of the passive crystal, but the output level of the crystal cannot change with the change of the application circuit as the passive crystal does.
It is easy to see that if an active crystal oscillator is used as an external clock source, we should configure the HSE bypass mode instead of the HSE crystal mode. Connect the output foot of the source crystal oscillator to the osc_in foot of the MCU.
---------------------
Silent monk 314
Source: csdn
Original: 78947096
Copyright Disclaimer: This article is an original article by the blogger. For more information, see the blog post link!
Timing F7 series clock problems: HSE mode configuration (Bypass mode, non-Bypass Mode)