1. Startup code analysis—SystemInit (void) system clock initialization
SystemInit (void) is the system initialization function. Many novices don’t know where to call it. Xiao Xiao will explain it to you immediately.
The assembly code in the startup_stm32f0xx.s file is the STM32 startup code.
The steps to start the code are generally:
1) Initialization of heap and stack;
2) Vector table definition;
3) Address remapping and transfer of interrupt vector table;
4) Set the system clock frequency;
5) Initialization of interrupt register;
6) Enter the main program.
There is too much nonsense, and I guess you are tired of reading it. Now I will focus on the key points, especially step 4. (Steps 5 and 6 are usually executed in user code during programming).
Reset_Handler
PROC; marks the beginning of a function, which is also the reset entry.
IMPORT
__main ; tells the compiler to use the label in other files
IMPORT
SystemInit; Same as above
Here is the key.
LDR
R0, =SystemInit;
The "=" here means that LDR is currently a pseudo instruction, not a standard instruction. Here, the address of SystemInit is given to RO. That is, SystemInit (void) is called and compiled here. Therefore, users do not need to write a PLL configuration program when writing a program.
BX
R0; BX is the program jump between the ARM instruction set and the THUMB instruction set.
Others are omitted. Details are shown in the figure below:
After SystemInit initializes RCC, it calls SetSysClock(void) to set the system clock.
code show as below:
void SystemInit (void)
{
RCC->CR |= (uint32_t)0x00000001;
RCC->CFGR &= (uint32_t)0xF8FFB80C;
RCC->CR &= (uint32_t)0xFEF6FFFF;
RCC->CR &= (uint32_t)0xFFFBFFFF;
RCC->CFGR &= (uint32_t)0xFFC0FFFF;
RCC->CFGR2 &= (uint32_t)0xFFFFFFF0;
RCC->CFGR3 &= (uint32_t)0xFFFFFEAC;
RCC->CR2 &= (uint32_t)0xFFFFFFFE;
RCC->CIR = 0x00000000;
SetSysClock();
}
2. SetSysClock() sets the system clock
Since PLL_SOURCE_HSE was defined earlier, conditional compilation is performed.
RCC->CR |= ((uint32_t)RCC_CR_HSEON); // Enable HSE, as shown below:
Wait for HSE to be set up. The code is as follows.
do
{
HSEStatus = RCC->CR & RCC_CR_HSERDY;
StartUpCounter++;
} while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));
if ((RCC->CR & RCC_CR_HSERDY) != RESET)
{
HSEStatus = (uint32_t)0x01;
}
else
{
HSEStatus = (uint32_t)0x00;
}
The setting is completed, HSEStatus is assigned a value of 1, and the code is as follows:
if ((RCC->CR & RCC_CR_HSERDY) != RESET)
{
HSEStatus = (uint32_t)0x01;
}
else
{
HSEStatus = (uint32_t)0x00;
}
HSEStatus HSE==1 indicates that the HSE status is normal, enabling the buffer and setting the FLASH delay, HCLK\PCLK. The PLL frequency multiplication is shown in the red line in the figure below. Modify RCC_CFGR_PLLMULL to achieve frequency multiplication (default 6 times).
Previous article:Introduction to STM32 study notes
Next article:Things to note when doing ARM bare metal C and programming
Recommended Content
Latest Microcontroller Articles
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- 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
MoreDaily News
- 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
Guess you like
- Please recommend a DC-DC chip with 12V-3.3V wide voltage input and 3.3V2A output
- Several key performance characteristics of the MSP432P401R MCU 14-bit ADC
- Zigbee3.0 ZCL_ALARMS usage
- 【BearPi-HM Micro】Development of smart street light module based on E53 interface
- Using Ultra-Wideband Technology to Display the Bible
- How is "u8 Dat2:7;" written in the structure? What does it mean?
- Modeling and Optimization Design of Finite State Machines
- Help! Can micropython do image processing or video processing?
- Pin-regulated 8mA output amplifier
- Is this the most comprehensive collection of RF project design tools?