How to run to the main function after GD32 MCU starts
INDUSTRIAL LCD DISPLAYS / IGBT MODULES DISTRIBUTOR

Infineon / Mitsubishi / Fuji / Semikron / Eupec / IXYS

How to run to the main function after GD32 MCU starts

Posted Date: 2024-01-15

How to run to the main function entry after GD32 MCU is started? Do you also have such doubts? What did the MCU do before executing the main function? Here are the answers for you.

After the MCMCU is powered on, it will first start from the main Flash/SRAM/ISP based on the status of BOOT0 and BOOT1. If BOOT0 is low level, the MCU will start from the main Flash, that is, the data in the main Flash will be mapped to At the 0x0000 0000 address, the ARM processor will obtain the top of the stack pointer from the 0x0000 0000 address, and then obtain the reset interrupt entry address (boot code base address) from 0x0000 0004. As shown in the figure below, we can open a bin file at random and the first 4 words The first section is the MSP stack pointer, the next four bytes are the reset interrupt entry address, and the following is the interrupt vector table.

After the MCU finds the stack pointer and the reset interrupt entry address, it will load and execute the reset interrupt. The reset interrupt function is defined in the .s startup file. The specific definition is as follows. After entering the reset interrupt function, the SystemInit system initialization function is first executed. This function is mainly a system clock configuration function, and then jumps to the main function for execution. That is to say, the system clock has been configured before executing the main function. After executing the reset interrupt function, the MCU will enter the main function for execution.

;/* reset Handler */ Reset_Handler PROC EXPORT Reset_Handler (WEAK) IMPORT SystemInit IMPORT __main LDR R0, =SystemInit BLX R0 LDR R0, =__main BX R0 ENDP


#run #main #function #GD32 #MCU #starts