1. System clock configuration
STM32 has multiple clock sources, namely HSI, HSE, LSE, and LSI.
HSI Oscillator Clock:
The default clock when the system is powered on is the internal oscillator 8MHZ, which can be used directly as the system clock or as the input of the PLL after being divided by 2. The clock frequency accuracy is poor.
HSE oscillator clock external:
Provides a very accurate master clock, 8MHZ on the STM32F1 series board and 25MHZ on the STM32F2 series board. Multiplied by PLL: used as system clock.
The PLL clock source input can be half of the HSI clock or the HSE clock.
LSE Clock:
The LSE crystal is a 32.867k low speed external crystal. It provides a real-time clock. It is usually used exclusively for RTC and will be used when the RTC module is used.
LSI clock (Internal):
LSI's RC acts as a low-power clock source, which can keep running in shutdown and standby modes. It provides clocks for independent watchdog and automatic wake-up units. The LSI clock frequency is about 40KHZ. It is generally used for IWDGCLK.
The usual clock choice is HSE with PLL to make it work at 72MHZ (STM32F1 series) or 120MHZ (STM32F2 series).
STM32F1xx series
STM32F2XX series
The only difference between RCC_DeInit() and SystemInit() is that SystemInit() has an additional SetSysClock(). SystemInit() includes the entire configuration of the internal clock to the external clock, but the configured frequency is not adjustable. If you need to adjust the frequency, you can use RCC_DeInit() and other operations.
Clock configuration process:
1. Reset the RCC register to the default value RCC_DeInit;
2. Turn on the external high-speed clock crystal HSE RCC_HSEConfig (RCC_HSE_ON);
3. Wait for the external high-speed clock crystal to work HSEStartUpStatus =RCC_WaitForHSEStartUp();
4. Set AHB clock RCC_HCLKConfig;
5. Set high-speed APB2 clock RCC_PCLK2Config;
6. Set the low speed APB1 clock RCC_PCLK1Config
7. Set PLL RCC_PLLConfig;
8. Enable PLL RCC_PLLCmd(ENABLE);
9. Wait for PLL to work while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET);
10. Set the system clock RCC_SYSCLKConfig;
11. Determine whether PLL is the system clock while(RCC_GetSYSCLKSource() != 0x08);
12. Turn on the peripheral clock to be used RCC_APB2PeriphClockCmd()/RCC_APB1PeriphClockCmd();
/****************************************************** ****************************
* Function Name: RCC_Configuration
* Description: Configures the different system clocks.
* Input : None
* Output : None
* Return : None
*************************************************** *******************************/
void RCC_Configuration(void)
{
/* RCC system reset(for debug purpose) */
RCC_DeInit();
/* Enable HSE */
RCC_HSEConfig(RCC_HSE_ON);
/* Wait till HSE is ready */
HSEStartUpStatus = RCC_WaitForHSEStartUp();
if(HSESTartUpStatus == SUCCESS)
{
/* Enable Prefetch Buffer */
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
/* HCLK = SYSCLK */
RCC_HCLKConfig(RCC_SYSCLK_Div1);
/* PCLK2 = HCLK */
RCC_PCLK2Config(RCC_HCLK_Div1);
/* PCLK1 = HCLK */
RCC_PCLK1Config(RCC_HCLK_Div1);
/* Select HSE as system clock source */
RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE);
/* Wait till HSE is used as system clock source */
while(RCC_GetSYSCLKSource() != 0x04)
{
}
}
XXXXXXXX; // Clock configuration for other peripherals respectively.
XXXXXXXX;
XXXXXXXX;
}
2. About PLL Settings
The PLL setting is mainly implemented through the function: void RCC_PLLConfig(uint32_t RCC_PLLSource, uint32_t PLLM, uint32_t PLLN, uint32_t PLLP, uint32_t PLLQ, uint32_t PLLR).
The main point is to talk about the relationship between the setting of PLL value and the clock of each part. The function involves the setting of 6 quantities, the first one is the selection of internal clock or external clock, and the following ones are the setting of PLL value.
RCC_PLLSource selection:
RCC_PLLSource_HIS: HIS internal clock is selected, the frequency is 16MHZ
RCC_PLLSource_HSE: HSE external clock selection, the frequency can be selected by yourself, between 4MHZ-26MHZ, the system default is 25MHZ, if you need to change, then change the 70th line in stm32f2xx.h
#define HSE_VALUE ((uint32_t)25000000) /*!< Value of the External oscillator in Hz */
Modify it to the value of the external crystal oscillator.
l By selecting PLLM and PLLN, PLLVCO is calculated using the following formula:
PLLVCO = (HSE_VALUE / PLL_M) * PLL_N.
The value of PLL_M can be 0-63, and the value of PLL_N can be 192-432.
l Select the frequency division number by selecting PLLP to obtain the system clock. The calculation formula is as follows:
SYSCLK = PLLVCO / PLL_P. Remember not to exceed the maximum frequency of 120MHZ.
The PLLP options are 2, 4, 6, and 8.
l Select PLLQ to OTGFS, SDIO and RNG clocks. The calculation formula is as follows:
Clock = PLLVCO / PLLQ, cannot exceed 48MHZ.
PLL_Q can be 4-15.
l Determine the I2S clock by selecting PLLR. The calculation formula is as follows:
I2SCLK = PLLVCO / PLLR.
PLL_R can be 2-7.
Previous article:Causes and solutions for insufficient STM32 stack allocation space
Next article:Application of STM32F2xx timer
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Are the amplitudes of common-mode interference signals different? The results found online are different.
- When it comes to setting up a development environment, do manufacturers need to put in more effort? Or do developers need more knowledge?
- I would like to ask, the output waveform of the power amplifier is more than 180 degrees out of phase with the input waveform. What is going on?
- Why can't I change my password?
- AD+FPGA+asynchronous FIFO+CMI+SPI code
- I would like to ask a question about PAD. What is the use of setting LAYER to KEEPOUT layer?
- Summary of the idea of zigbee gateway docking equipment
- 【Perf-V Review】8-segment digital tube
- Problems in driving low-power three-phase brushless motors
- Notice on organizing the 2021 National Undergraduate Electronic Design Competition