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

相关推荐
蓬荜生灰7 分钟前
永磁无刷电机旋转原理
单片机·嵌入式硬件
金色光环2 小时前
【Modbus学习笔记】stm32实现Modbus
笔记·stm32·学习
Ronin-Lotus5 小时前
嵌入式硬件与应用篇---寄存器GPIO控制
stm32·单片机·嵌入式硬件·微处理器原理与应用
星辰pid12 小时前
STM32控制四自由度机械臂(SG90舵机)(硬件篇)(简单易复刻)
stm32·单片机·嵌入式硬件·机械臂
威桑14 小时前
STM32 专有名词缩写整合
stm32·单片机·嵌入式硬件
星源~14 小时前
tree 命令集成到 Git Bash:可视化目录结构的指南
git·单片机·物联网·嵌入式·项目开发
SKYDROID云卓小助手15 小时前
无人设备遥控器之自动调整编码技术篇
人工智能·嵌入式硬件·算法·自动化·信号处理
所念皆星海91115 小时前
图灵完备之路(数电学习三分钟)----数据选择器与总线
嵌入式硬件·通信·数电
智者知已应修善业17 小时前
【51单片机节日彩灯控制器设计】2022-6-11
c语言·经验分享·笔记·单片机·嵌入式硬件·51单片机
开-悟17 小时前
嵌入式编程-使用AI查找BUG的启发
c语言·人工智能·嵌入式硬件·bug