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

相关推荐
_Ningye6 小时前
STM32 — 6.1 TIM定时中断
stm32·单片机·嵌入式硬件
小白学电子_6 小时前
proteus仿真51单片机通过矩阵按键和数码管制作简单计算器
嵌入式硬件·51单片机·proteus
非鱼䲆鱻䲜8 小时前
vscode开发stm32添加新的头文件路径和包含源文件
ide·vscode·stm32·cmake·包含头文件·包含源文件
FreakStudio8 小时前
把 Flask 搬进 ESP32,高中生自研嵌入式 Web 框架 MicroFlask !
python·单片机·嵌入式·cortex-m3·异步编程·电子diy
AnalogElectronic9 小时前
RP2040 pico 实验6,光敏电阻传感器模块(LM393 比较器版)
单片机
17(无规则自律)9 小时前
【Linux驱动实战】:字符设备之ioctl与mutex全解析
linux·c语言·驱动开发·嵌入式硬件
电子工程师成长日记-C519 小时前
51单片机4乘4计算器
单片机·嵌入式硬件·51单片机
梅尔文.古9 小时前
ADCU-Ethernet-以太网在AUTOSAR与Linux架构下对比
arm开发·单片机·汽车
没有医保李先生9 小时前
esp32和stm32的工程宏定义
stm32·单片机·嵌入式硬件
炸膛坦客10 小时前
单片机/C/C++八股:(十五)内存对齐、结构体内存对齐
c语言·开发语言·单片机