The SystemInit() function appears in the first line of the main() function, which shows its importance. The function SystemInit() has never been concerned before, only that it is a function for initialization of STM32 system. Today I decided to take a closer look and start STM32 again. This function is in system_stm32f10x.c. This C file is mainly for the specific hardware configuration related work.
From the function description, the function is to initialize the internal FALSH, PLL and update the system clock. This function needs to be called after reset starts.
The first line of code operates the clock control register, enabling the internal 8M high-speed clock. It can be seen from this that the system works first by relying on the internal clock source after starting.
These two lines of code are the operating clock configuration registers. MCO (MCO clock output) PLL correlation (PLL frequency doubling coefficient, PLL input clock source), ADCPRE (ADC clock), PPRE2 (high-speed APB frequency dividing coefficient), PPRE1 (low-speed APB frequency dividing coefficient), HPRE(AHB pre-dividing coefficient), SW (system clock switching), at the beginning, the system clock is switched to HSI, which serves as the system initial clock. The macro STM32F10X_CL is a macro related to the specific STM32 chip.
These sentences are to configure the parameters related to HSE, CSS, PLL and so on, and then open them to achieve the purpose of taking effect.
This section is mainly related to interrupt settings. In the beginning, we need to prohibit all interrupts and clear all interrupt flags. Different hardware has different features.
This section has something to do with setting up external RAM. The STM32F103RBT I used has nothing to do with it.
This is another function, mainly to configure the system clock frequency. The fractional frequencies of HCLK, PCLK2 and PCLK1 represent AHB,APB2 and ABB1 respectively. Other things, of course, are configuring FLASH latency cycles and enabling prefetch buffers. The latter configuration is not yet known.
This code mainly realizes the relocation of the vector table. Depending on whether you want to locate the vector table in internal SRAM or internal FLASH. This SCB has not been found in the STM32 reference manual since it was originally related to the Cortex-M3 kernel. So ST didn't include it. Kernel things to understand later, here to remind yourself.
Then look at what the function SetClock() in SystemInit() does.
This function also has the SetSysClockTo72() function, which is the specific operation register configuration.
The above code needs to be looked at carefully. SystemInit() is about that.