Detailed explanation of STM32f103 clock tree

I. Overview

stm32 has four clock signal sources, HSE (high-speed external clock), HSI (high-speed internal clock), LSE (low-speed external clock), LSI (low-speed internal clock). HSE is usually connected to 8M crystal oscillator, through internal frequency division and frequency multiplication, the maximum clock frequency can be 72MHz. LSE is usually connected to a 32.768KHz crystal oscillator, which is usually used as the clock source of the RTC clock.

Two, stm32f103 clock tree

[External link picture transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the picture and upload it directly (img-Kb6hgwxq-1683955293362)(https://note.youdao.com/yws/res/30547/WEBRESOURCEe6ed4483b76a39bfd152bc3bf7d015c6)]

2.1. Clock Introduction

①, HSI is a high-speed internal clock, RC oscillator, the frequency is 8MHz;
②, HSE is a high-speed external clock, which can be connected to a quartz/ceramic resonator, or an external clock source, and the frequency range is 4MHz~16MHz.
Our development board is connected to an 8M crystal oscillator.
③. LSI is a low-speed internal clock, RC oscillator with a frequency of 40kHz. The clock source of the independent watchdog can only be LSI, and
LSI can also be used as the clock source of RTC.
④. LSE is a low-speed external clock connected to a quartz crystal with a frequency of 32.768kHz. This is mainly the clock source of RTC.
⑤. PLL is the phase-locked loop multiplier output, and its clock input source can be selected as HSI/2, HSE or HSE/2. The frequency multiplier can be selected as 2~16 times, but the maximum output frequency should not exceed 72MHz.

2.2. Clock function

A. MCO is a clock output IO (PA8) of STM32. It can select a clock signal output, which can be divided by
2, HSI, HSE, or system clock output by PLL. This clock can be used to
provide clock source for other external systems.
B. Here is the RTC clock source, as can be seen from the figure, the RTC clock source can choose LSI, LSE, and
128 frequency division of HSE.
C. It can be seen from the figure that the USB clock at C comes from the PLL clock source. There is a full-speed
USB module in STM32, and its serial interface engine needs a clock source with a frequency of 48MHz. The clock source can only
be obtained from the PLL output, which can be divided by 1.5 or 1. That is, when the USB
module is used, the PLL must be enabled, and the clock frequency is configured as 48MHz or 72MHz.
D. D is the system clock SYSCLK of STM32, which is the clock
source for most of the components in STM32. The system clock can be selected as PLL output, HSI or HSE. The maximum frequency of the system clock is 72MHz.
Of course, you can also overclock, but in general, there is no need to take risks to overclock for system stability.
E. E here refers to all other peripherals. It can be seen from the clock diagram that the final
source of clocks for all other peripherals is SYSCLK. SYSCLK is divided by AHB frequency divider and sent to each module for use. These modules include
:
①, AHB bus, core, memory and HCLK used by DMA.
②, After dividing by 8, send it to the system timer clock of Cortex, that is, the systick.
③. Directly send to the idle running clock FCLK of Cortex.
④. Send to APB1 frequency divider. APB1 frequency divider outputs one channel for APB1 peripherals (PCLK1, maximum
frequency 36MHz), and the other channel for Timer 2, 3, 4 frequency multipliers.
⑤. Send to APB2 frequency divider. One channel of APB2 frequency divider frequency division output is used by APB2 peripherals (PCLK2,
maximum frequency 72MHz), and the other channel is used by Timer 1 frequency multiplier.
What needs to be understood is the difference between APB1 and APB2. APB1 is connected to low-speed peripherals, including power interface,
backup interface, CAN, USB, I2C1, I2C2, UART2, UART3, etc., and APB2 is connected to high-speed peripherals, including UART1, SPI1, Timer1, ADC1, ADC2
, all ordinary IO ports (PA~PE), second function IO ports, etc. The clock of the peripheral connected under APB2
is higher than that of APB1.
Among the above clock outputs, many are with enable control, such as AHB bus clock, core clock, various APB1 peripherals
, APB2 peripherals, etc. When you need to use a certain module, remember to enable the corresponding clock first.
The above content comes from punctual atom "stm32 incomplete development manual"

Three, cubemx clock configuration

[External link picture transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the picture and upload it directly (img-AOEJPPda-1683955293363)(https://note.youdao.com/yws/res/30562/WEBRESOURCE560df8a091fef5d979a6e6b08767584f)]

If you want to use HSE, you need to enable the RCC clock function of cubeMX
[External link picture transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the picture and upload it directly (img-36HlnsiZ-1683955293363)(https://note.youdao.com/yws/res/c/WEBRESOURCE80afb8cf168518f0b07ae630b28019cc)]

When configuring the clock with cubemx, there are three options:

  • Disable
  • BYPASS Clock Source (bypass clock source)
  • Crystal/Ceramic Resonator (crystal/ceramic crystal oscillator)
    Here we choose a crystal oscillator, that is, a crystal oscillator.

The maximum operating frequency of stm32f103 is 72MHz. We can directly input the maximum clock frequency in PCLK2 to let the system automatically allocate clock selection and configuration for us.

Guess you like

Origin blog.csdn.net/weixin_39270987/article/details/130656431