Recognize STM32 's system clock

Source: Internet
Author: User

STM32 A total of five clock sources, namely:

    • HSI is a high-speed internal clock, rc oscillator, the frequency of 8MHz;
    • HSE is a high-speed external clock with a frequency range of 4~6mhz; (can connect quartz/ceramic resonator or external clock source)
    • LSI is low speed internal clock, frequency 40kHz; (independent watchdog clock source, available as RTC Clock source)
    • The LSE is a low-speed external clock with a frequency of 32.768kHz quartz crystals; (main RTC Clock source)
    • PLL is a phase-locked loop multiplier output, the frequency can be selected as HSI/2, HSE or HSE/2, octave can choose 2~16 times, but its output frequency maximum not more than 72MHz;

The system clock is highlighted here, and the source of all other peripheral clocks is sysclk,sysclk via the AHB divider and sent to each module for use. These modules include the APB1 and APB2 dividers.

    • To the APB1 divider, output all the way for APB1 peripheral use (maximum frequency is 36MHz), and the other way to the timer (timer) 2, 3, 4 times frequency multiplier use;
    • To the APB2 divider, the output for APB2 peripheral use (the maximum frequency of 72MHz), the other way to send a timer (timer) 1 time times the frequency of use;

Specifically, the following table:

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 band-controlled, for example:

            Rcc_apb2periphclockcmd (rcc_apb2periph_gpiod| Rcc_apb2periph_gpiog, ENABLE);

Is the clock enable for PD and PG ports.

The STM32 clock system configuration is initialized with function Sys-teminit (), and other configurations are in the Stm32f10x-rcc.h file.

For the system clock by default in the case of the Systeminit function in the Setsysclock () function, the following:

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 to determine how much the system macro defines the clock, and then set the corresponding value, the system defaults to 72MHz:

                                   #define Sysclk_freq_72mhz  72000000

If you need to set the clock for other frequencies, simply comment out the code on line 115th of the stm32f10x-rcc.c file and add the frequency code you want.

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

                    • SYSCLK (System clock) =72mhz;
                    • AHB bus clock (using system clock) =72mhz;
                    • APB1 bus Clock (PCLK1) =36mhz;
                    • apb2 bus Clock (PCLK2) =72mhz;

Recognize STM32 's system clock

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.