stm32启动时用到的systeminit、__main说明

  1. 先运行systeminit函数,其功能:初始化时钟(SYSCLK, HCLK, PCLK2 and PCLK1 prescalers)、配置中断向量表(中断向量表的定位是在flash还是SRAM)
  2. 再运行__main函数:
  • 作用:Initialization of the execution environment and execution of the application
  • You can customize execution intialization by defining your own __main that branches to __rt_entry.
  • The entry point of a program is at __main in the C library where library code:
  • Copies non-root (RO(不会拷贝,官方提供和实际实践有出入) and RW) execution regions from their load addresses to their execution addresses. Also, if any data sections are compressed, they are decompressed from the load address to the execution address.
  • Zeroes ZI regions.
  • Branches to __rt_entry.
  • If you do not want the library to perform these actions, you can define your own __main that branches to __rt_entry。
  1. 再运行The library function __rt_entry() runs the program as follows:
  • Sets up the stack and the heap by one of a number of means that include calling __user_setup_stackheap(), calling __rt_stackheap_init(), or loading the absolute addresses of scatter-loaded regions.
  • Calls __rt_lib_init() to initialize referenced library functions, initialize the locale and, if necessary, set up argc and argv for main().This function is called immediately after__rt_stackheap_init() and is passed an initial chunk of memory to use as a heap. This function is the standard ARM C library initialization function and it must not be reimplemented.
  • Calls main(), the user-level root of the application.
  • From main(), your program might call, among other things, library functions.
  • Calls exit() with the value returned by main().

因为库函数里面的 ___main函数 和 ____rt_entry函数是弱函数,所有我们可以自己编写__main和__rt_entry

相关推荐
btzhy1 天前
STM32单片机:基本定时器应用:单脉冲模式(STM32L4xx)
stm32·单片机·嵌入式硬件·基本定时器应用:单脉冲模式
文sir.1 天前
温湿度采集系统(stm32+mqtt+Onenet云平台+esp8266)
stm32·单片机·嵌入式硬件·mqtt·onenet·云平台·esp8266
DIY机器人工房1 天前
嵌入式面试题:你有没有用过直接基于TCP协议,不借助HTTP、MQTT这类上层协议的项目经历?
stm32·单片机·嵌入式硬件·面试题·diy机器人工房
zhmc1 天前
Cortex M0单片机指令执行周期
单片机·嵌入式硬件
编程小白菜1231 天前
STM32L051单片机485Ymode升级后程序不能正常运行问题
stm32·嵌入式硬件
NEU-UUN1 天前
5.1.STM32-EXTI外部中断——全程手敲板书
stm32·单片机·嵌入式硬件
TangDuoduo00051 天前
【常见传感器原理及应用】
单片机·嵌入式硬件
q***06472 天前
SocketTool、串口调试助手、MQTT中间件基础
单片机·嵌入式硬件·中间件
洋九八2 天前
电路基础和 PCB 制作
单片机·嵌入式硬件·pcb工艺
qq_401700412 天前
RS485基本原理,电路、防雷、layout及设计要点
stm32·单片机