STM32 keil mdk启动代码发分析

【STM32 keil mdk启动代码发分析】
STM32 keil mdk启动代码发分析 收藏 学习STM32,看了一堆乱七八糟的文档,准备写程序了,先分析了下STM32的启动代码,看着这堆鬼鬼的汇编代码,挺吓人的,看看帮助,查查网路,还是不那么难懂。

view plain copy to clipboard print ?

  1. ; //Stack Configuration
  2. ; // Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
  3. ; //
  4. Stack_SizeEQU0x00000200; //定义堆栈大小
  5. AREASTACK, NOINIT, READWRITE, ALIGN=3; //定义一个数据段 按8字节对齐
  6. Stack_MemSPACEStack_Size; //保留Stack_Size大小的堆栈空间
  7. __initial_sp; //标号,代表堆栈顶部地址,后面有用
  8. ; //Heap Configuration
  9. ; //Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
  10. ; //
  11. Heap_SizeEQU0x00000020; //定义堆空间大小
  12. AREAHEAP, NOINIT, READWRITE, ALIGN=3; //定义一个数据段,8字节对齐
  13. __heap_base
  14. Heap_MemSPACEHeap_Size; //保留Heap_Size的堆空间
  15. __heap_limit; //标号,代表堆末尾地址,后面有用
  16. PRESERVE8; //指示编译器8字节对齐
  17. THUMB; //指示编译器为THUMB指令
  18. ; Vector Table Mapped to Address 0 at Reset
  19. AREARESET, DATA, READONLY; //定义只读数据段,其实放在CODE区,位于0地址
  20. EXTERNNMIException
  21. EXTERNHardFaultException
  22. EXTERNMemManageException
  23. EXTERNBusFaultException
  24. EXTERNUsageFaultException
  25. EXTERNSVCHandler
  26. EXTERNDebugMonitor
  27. EXTERNPendSVC
  28. EXTERNSysTickHandler; //声明这些符号在外部定义,同C
  29. ; //在××it.c中实现这些函数 ,中断就能自动调用了
  30. EXPORT__Vectors
  31. __VectorsDCD__initial_sp; Top of Stack//Cotex-M要求此处为堆栈顶部地址
  32. DCDReset_Handler; Reset Handler
  33. DCDNMIException; NMI Handler
  34. DCDHardFaultException; Hard Fault Handler
  35. DCDMemManageException; MPU Fault Handler
  36. DCDBusFaultException; Bus Fault Handler
  37. DCDUsageFaultException; Usage Fault Handler
  38. DCD0; Reserved
  39. DCD0; Reserved
  40. DCD0; Reserved
  41. DCD0; Reserved
  42. DCDSVCHandler; SVCall Handler
  43. DCDDebugMonitor; Debug Monitor Handler
  44. DCD0; Reserved
  45. DCDPendSVC; PendSV Handler
  46. DCDSysTickHandler; SysTick Handler//一大堆的异常处理函数地址
  47. ; External Interrupts
  48. EXTERNWWDG_IRQHandler
  49. EXTERNPVD_IRQHandler
  50. EXTERNTAMPER_IRQHandler
  51. EXTERNRTC_IRQHandler
  52. EXTERNFLASH_IRQHandler
  53. EXTERNRCC_IRQHandler
  54. EXTERNEXTI0_IRQHandler
  55. EXTERNEXTI1_IRQHandler
  56. EXTERNEXTI2_IRQHandler
  57. EXTERNEXTI3_IRQHandler
  58. EXTERNEXTI4_IRQHandler
  59. EXTERNDMAChannel1_IRQHandler
  60. EXTERNDMAChannel2_IRQHandler
  61. EXTERNDMAChannel3_IRQHandler
  62. EXTERNDMAChannel4_IRQHandler
  63. EXTERNDMAChannel5_IRQHandler
  64. EXTERNDMAChannel6_IRQHandler
  65. EXTERNDMAChannel7_IRQHandler
  66. EXTERNADC_IRQHandler
  67. EXTERNUSB_HP_CAN_TX_IRQHandler
  68. EXTERNUSB_LP_CAN_RX0_IRQHandler
  69. EXTERNCAN_RX1_IRQHandler
  70. EXTERNCAN_SCE_IRQHandler
  71. EXTERNEXTI9_5_IRQHandler
  72. EXTERNTIM1_BRK_IRQHandler
  73. EXTERNTIM1_UP_IRQHandler
  74. EXTERNTIM1_TRG_COM_IRQHandler
  75. EXTERNTIM1_CC_IRQHandler
  76. EXTERNTIM2_IRQHandler
  77. EXTERNTIM3_IRQHandler
  78. EXTERNTIM4_IRQHandler
  79. EXTERNI2C1_EV_IRQHandler
  80. EXTERNI2C1_ER_IRQHandler
  81. EXTERNI2C2_EV_IRQHandler
  82. EXTERNI2C2_ER_IRQHandler
  83. EXTERNSPI1_IRQHandler
  84. EXTERNSPI2_IRQHandler
  85. EXTERNUSART1_IRQHandler
  86. EXTERNUSART2_IRQHandler
  87. EXTERNUSART3_IRQHandler
  88. EXTERNEXTI15_10_IRQHandler
  89. EXTERNRTCAlarm_IRQHandler
  90. EXTERNUSBWakeUp_IRQHandler; //同上,
  91. DCDWWDG_IRQHandler; Window Watchdog
  92. DCDPVD_IRQHandler; PVD through EXTI Line detect
  93. DCDTAMPER_IRQHandler; Tamper
  94. DCDRTC_IRQHandler; RTC
  95. DCDFLASH_IRQHandler; Flash
  96. DCDRCC_IRQHandler; RCC
  97. DCDEXTI0_IRQHandler; EXTI Line 0
  98. DCDEXTI1_IRQHandler; EXTI Line 1
  99. DCDEXTI2_IRQHandler; EXTI Line 2
  100. DCDEXTI3_IRQHandler; EXTI Line 3
  101. DCDEXTI4_IRQHandler; EXTI Line 4
  102. DCDDMAChannel1_IRQHandler; DMA Channel 1
  103. DCDDMAChannel2_IRQHandler; DMA Channel 2
  104. DCDDMAChannel3_IRQHandler; DMA Channel 3
  105. DCDDMAChannel4_IRQHandler; DMA Channel 4
  106. DCDDMAChannel5_IRQHandler; DMA Channel 5
  107. DCDDMAChannel6_IRQHandler; DMA Channel 6
  108. DCDDMAChannel7_IRQHandler; DMA Channel 7
  109. DCDADC_IRQHandler; ADC
  110. DCDUSB_HP_CAN_TX_IRQHandler; USB High Priority or CAN TX
  111. DCDUSB_LP_CAN_RX0_IRQHandler ; USB LowPriority or CAN RX0
  112. DCDCAN_RX1_IRQHandler; CAN RX1
  113. DCDCAN_SCE_IRQHandler; CAN SCE
  114. DCDEXTI9_5_IRQHandler; EXTI Line 9..5
  115. DCDTIM1_BRK_IRQHandler; TIM1 Break
  116. DCDTIM1_UP_IRQHandler; TIM1 Update
  117. DCDTIM1_TRG_COM_IRQHandler; TIM1 Trigger and Commutation
  118. DCDTIM1_CC_IRQHandler; TIM1 Capture Compare
  119. DCDTIM2_IRQHandler; TIM2
  120. DCDTIM3_IRQHandler; TIM3
  121. DCDTIM4_IRQHandler; TIM4
  122. DCDI2C1_EV_IRQHandler; I2C1 Event
  123. DCDI2C1_ER_IRQHandler; I2C1 Error
  124. DCDI2C2_EV_IRQHandler; I2C2 Event
  125. DCDI2C2_ER_IRQHandler; I2C2 Error
  126. DCDSPI1_IRQHandler; SPI1
  127. DCDSPI2_IRQHandler; SPI2
  128. DCDUSART1_IRQHandler; USART1
  129. DCDUSART2_IRQHandler; USART2
  130. DCDUSART3_IRQHandler; USART3
  131. DCDEXTI15_10_IRQHandler; EXTI Line 15..10
  132. DCDRTCAlarm_IRQHandler; RTC Alarm through EXTI Line
  133. DCDUSBWakeUp_IRQHandler; USB Wakeup from suspend; //同上
  134. AREA|.text|, CODE, READONLY; //定义代码段
  135. ; Reset Handler
  136. Reset_HandlerPROC; //Rset_Handler的实现
  137. EXPORTReset_Handler[WEAK]; //在外部没有定义该符号时导出该符号,见HELP中[WEAK]
  138. IMPORT__main; //导入符号,__main为 运行时库提供的函数;完成堆栈,堆的初始话
  139. LDRR0, =__main; //等工作,会调用下面定义的__user_initial_stackheap;
  140. BXR0; //跳到__main,进入C的世界
  141. ENDP
  142. ALIGN
  143. ; User Initial Stack & Heap
  144. IF:DEF:__MICROLIB; //如果使用micro lib,micro lib 描述见armlib.chm
  145. EXPORT__initial_sp
  146. EXPORT__heap_base
  147. EXPORT__heap_limit; //只导出几个定义
  148. ELSE; //如果使用默认C运行时库
  149. IMPORT__use_two_region_memory
  150. EXPORT__user_initial_stackheap
  151. __user_initial_stackheap; //则进行堆栈和堆的赋值,在__main函数执行过程中调用。
  152. LDRR0, =Heap_Mem
  153. LDRR1, =(Stack_Mem + Stack_Size)
  154. LDRR2, = (Heap_Mem +Heap_Size)
  155. LDRR3, = Stack_Mem
  156. BXLR
  157. ALIGN
  158. ENDIF
  159. END; //OK ,完了


    推荐阅读