Following the program execution flow, main is the program entry, where various initializations are performed.
1. Clock configuration
First is RCC_Configuration(), which performs basic clock initialization. STM32 has multiple clock sources: (1) HSI is enabled by default when powered on, and has low precision; (2) HSE external high-speed clock, which is generally used by the system clock and multiplied by PLL; (3) LSE external low-speed clock, which is generally used for RTC; (4) LSI internal low-speed clock, which has low precision and is generally used for IWDGCLK;
void RCC_Configuration(void)
{
RCC_DeInit(); //Reset RCC to default value
RCC_HSEConfig(RCC_HSE_ON); //Turn on the HSE clock as the clock source for the PLL
HSEStartUpStatus = RCC_WaitForHSEStartUp(); //Get HSE clock status
if(HSEStartUpStatus == SUCCESS) //If HSE starts successfully
{
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); // Enable FLASH prefetch function
RCC_HCLKConfig(RCC_SYSCLK_Div1); //配置HCLK,PCLK2,PCLK1,PLL
RCC_PCLK2Config(RCC_HCLK_Div1);
RCC_PCLK1Config(RCC_HCLK_Div1);
RCC_SYSCLKConfig(RCC_SYSCLKSource_HSE);
while(RCC_GetSYSCLKSource() != 0x04) // Check whether HSE is used as system clock after frequency multiplication
{
}
}
}
In this way, the clock is initialized. First reset the RCC, then configure each clock source, get the status and wait for success. If we want to use a certain function or pin, we need to turn on the relevant clock source.
2. Interrupt vector setting
void NVIC_Configuration(void)
{
#ifdef VECT_TAB_RAM
/* Set the Vector Table base location at 0x20000000 */
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
#else /* VECT_TAB_FLASH */
/* Set the Vector Table base location at 0x08000000 */
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
#endif
}
NVIC_SetVectorTable sets the position and offset of the vector table
NVIC_ VectTab Description
NVIC_VectTab_FLASH vector table is located in FLASH
NVIC_VectTab_RAM The vector table is located in RAM and is used to set the priority of various interrupts, the address of the vector table, etc.
Previous article:stm32 executes the initialization function in the interrupt function
Next article:STM32 GPIO Operation (by woody)
Recommended ReadingLatest update time:2024-11-23 07:59
- Popular Resources
- Popular amplifiers
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- STM32MP157A-DK1 Review - 3. MPU functions: SPI, ADC, I2C
- ST MEMS Creative Competition Post 2 - Project Introduction and Planning
- AP6212 Firmware
- BMW ASF active steering system1
- Countdown! The 15th Automechanika Shanghai is coming soon
- [2022 Digi-Key Innovation Design Competition] Material Unboxing STM32H7B3-DK
- How does the Zigbee coordinator select the appropriate channel to create a network?
- How can I learn FPGA quickly?
- Detailed explanation of ADC of TMS320F28335
- Why is Huawei's 5G technology stronger than that of the United States?