Understanding the system clock of STM32 and the system clock of STM32

Source: Internet
Author: User

Understanding the system clock of STM32 and the system clock of STM32

STM32 has five clock sources:

  • HSI is a high-speed internal clock and RC oscillator with an 8 MHz frequency;
  • HSE is a high-speed external clock with a frequency range of 4 ~ 6 MHz; (it can be connected to a Z/Ceramic Resonator or an external clock source)
  • LSI is a low-speed internal clock with a frequency of 40 kHz. (It is an independent watchdog clock source and can be used as an RTC clock source)
  • LSE is a low-speed external clock with a frequency of 32.768kHz Z crystal (mainly RTC clock source)
  • PLL is the frequency doubling output of the Phase-Locked Loop. The frequency can be HSI/2, HSE or HSE/2, and the frequency doubling can be 2 to 2 ~ 16 times, but its output frequency cannot exceed 72 MHz;

The system clock is introduced here. Generally, all other peripheral clock sources are SYSCLK, and SYSCLK is sent to each module after being divided by AHB divider. These modules include APB1 and APB2 divider.

  • Send the package to the APB1 divider, and output the package to the APB1 peripherals (the maximum frequency is 36 MHz), and send the package to the Timer (Timer) 2, 3, and 4;
  • To the APB2 divider, the output channel is used by APB2 peripherals (the maximum frequency is 72 MHz), and a Timer (Timer) is sent to the second frequency;

The specific table is as follows:

APB peripheral content table
Name Type Peripheral content
APB1 Low-speed peripherals

Power interface, backup interface, CAN, USB, I2C1, I2C2, UART2, UART3, etc.

APB2 High-speed peripherals UART1, SPI1, Timer1, ADC1, ADC2, General IO port (PA ~ PE), second function IO port, etc.

Many of the above clock outputs are enable-controlled, for example:

            RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD|RCC_APB2Periph_GPIOG, ENABLE);

It enables clock on the PD and PG ports.

STM32 Clock System Configuration initialization has functions other than Sys-temInit (), other configurations in the stm32f10x-rcc.h file.

The system clock is determined by default in the SetSysClock () function of the SystemInit function, as follows:

Static void SetSysClock (void)
{
# Ifdef SYSCLK_FREQ_HSE
SetSysClockToHSE ();
# Elif defined SYSCLK_FREQ_24MHz
SetSysClockTo24 ();
# Elif defined SYSCLK_FREQ_36MHz
SetSysClockTo36 ();
# Elif defined SYSCLK_FREQ_48MHz
SetSysClockTo48 ();
# Elif defined SYSCLK_FREQ_56MHz
SetSysClockTo56 ();
# Elif defined SYSCLK_FREQ_72MHz
SetSysClockTo72 ();
# Endif
}

This code is used to determine the clock defined by the system macro and set the corresponding value. The default value is 72 MHz:

                                   #define SYSCLK_FREQ_72MHz  72000000

If you need to set a clock for another frequency, you just need to comment out the above Code on the 115th line of the stm32f10x-rcc.c file and add the desired frequency code.

The system clock size set in the SystemInit () function is as follows:

                  • SYSCLK (system clock) = 72 MHz;
                  • AHB Bus clock (using system clock) = 72 MHz;
                  • APB1 bus clock (PCLK1) = 36 MHz;
                  • APB2 bus clock (PCLK2) = 72 MHz;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.