您的位置 首页 新品

Cortex-M3 (NXP LPC1788)之发动代码剖析

在KeiluVision4中新建一个基于NXP1788的工程后,会提示添加启动汇编代码startup_LPC177x_8x.S。该文件进行从汇编到C语言运行环境的…

在Keil uVision4中新建一个依据NXP1788的工程后,会提示增加发动汇编代码startup_LPC177x_8x.S。该文件进行从汇编到C言语运转环境的初始化作业。

  1. ;/*****************************************************************************
  2. ;*@file:startup_LPC177x_8x.s
  3. ;*@purpose:CMSISCortex-M3CoreDeviceStartupFile
  4. ;*fortheNXPLPC177x_8xDeviceSeries
  5. ;*@version:V1.20
  6. ;*@date:07.October2010
  7. ;*——-<<>>——————
  8. ;*
  9. ;*Copyright(C)2010ARMLimited.Allrightsreserved.
  10. ;*ARMLimited(ARM)issupplyingthissoftwareforusewithCortex-M3
  11. ;*processorbasedmicrocontrollers.Thisfilecanbefreelydistributed
  12. ;*withindevelopmenttoolsthataresupportingsuchARMbasedprocessors.
  13. ;*
  14. ;*THISSOFTWAREISPROVIDED”ASIS”.NOWARRANTIES,WHETHEREXPRESS,IMPLIED
  15. ;*ORSTATUTORY,INCLUDING,BUTNOTLIMITEDTO,IMPLIEDWARRANTIESOF
  16. ;*MERCHANTABILITYANDFITNESSFORAPARTICULARPURPOSEAPPLYTOTHISSOFTWARE.
  17. ;*ARMSHALLNOT,INANYCIRCUMSTANCES,BELIABLEFORSPECIAL,INCIDENTAL,OR
  18. ;*CONSEQUENTIALDAMAGES,FORANYREASONWHATSOEVER.
  19. ;*
  20. ;*****************************************************************************/
  21. ;StackConfiguration
  22. ;StackSize(inBytes)<0x0-0xFFFFFFFF:8>
  23. ;
  24. Stack_SizeEQU0x00000200
  25. AREASTACK,NOINIT,READWRITE,ALIGN=3
  26. Stack_MemSPACEStack_Size
  27. __initial_sp
  28. ;HeapConfiguration
  29. ;HeapSize(inBytes)<0x0-0xFFFFFFFF:8>
  30. ;
  31. Heap_SizeEQU0x00000400
  32. AREAHEAP,NOINIT,READWRITE,ALIGN=3
  33. __heap_base
  34. Heap_MemSPACEHeap_Size
  35. __heap_limit
  36. PRESERVE8
  37. THUMB
  38. ;VectorTableMappedtoAddress0atReset
  39. AREARESET,DATA,READONLY
  40. EXPORT__Vectors
  41. __VectorsDCD__initial_sp;TopofStack
  42. DCDReset_Handler;ResetHandler
  43. DCDNMI_Handler;NMIHandler
  44. DCDHardFault_Handler;HardFaultHandler
  45. DCDMemManage_Handler;MPUFaultHandler
  46. DCDBusFault_Handler;BusFaultHandler
  47. DCDUsageFault_Handler;UsageFaultHandler
  48. DCD0;Reserved
  49. DCD0;Reserved
  50. DCD0;Reserved
  51. DCD0;Reserved
  52. DCDSVC_Handler;SVCallHandler
  53. DCDDebugMon_Handler;DebugMonitorHandler
  54. DCD0;Reserved
  55. DCDPendSV_Handler;PendSVHandler
  56. DCDSysTick_Handler;SysTickHandler
  57. ;ExternalInterrupts
  58. DCDWDT_IRQHandler;16:WatchdogTimer
  59. DCDTIMER0_IRQHandler;17:Timer0
  60. DCDTIMER1_IRQHandler;18:Timer1
  61. DCDTIMER2_IRQHandler;19:Timer2
  62. DCDTIMER3_IRQHandler;20:Timer3
  63. DCDUART0_IRQHandler;21:UART0
  64. DCDUART1_IRQHandler;22:UART1
  65. DCDUART2_IRQHandler;23:UART2
  66. DCDUART3_IRQHandler;24:UART3
  67. DCDPWM1_IRQHandler;25:PWM1
  68. DCDI2C0_IRQHandler;26:I2C0
  69. DCDI2C1_IRQHandler;27:I2C1
  70. DCDI2C2_IRQHandler;28:I2C2
  71. DCDSPIFI_IRQHandler;29:SPIFI
  72. DCDSSP0_IRQHandler;30:SSP0
  73. DCDSSP1_IRQHandler;31:SSP1
  74. DCDPLL0_IRQHandler;32:PLL0Lock(MainPLL)
  75. DCDRTC_IRQHandler;33:RealTimeClock
  76. DCDEINT0_IRQHandler;34:ExternalInterrupt0
  77. DCDEINT1_IRQHandler;35:ExternalInterrupt1
  78. DCDEINT2_IRQHandler;36:ExternalInterrupt2
  79. DCDEINT3_IRQHandler;37:ExternalInterrupt3
  80. DCDADC_IRQHandler;38:A/DConverter
  81. DCDBOD_IRQHandler;39:Brown-OutDetect
  82. DCDUSB_IRQHandler;40:USB
  83. DCDCAN_IRQHandler;41:CAN
  84. DCDDMA_IRQHandler;42:GeneralPurposeDMA
  85. DCDI2S_IRQHandler;43:I2S
  86. DCDENET_IRQHandler;44:Ethernet
  87. DCDMCI_IRQHandler;45:SD/MMCcardI/F
  88. DCDMCPWM_IRQHandler;46:MotorControlPWM
  89. DCDQEI_IRQHandler;47:QuadratureEncoderInterface
  90. DCDPLL1_IRQHandler;48:PLL1Lock(USBPLL)
  91. DCDUSBActivity_IRQHandler;49:USBActivityinterrupttowakeup
  92. DCDCANActivity_IRQHandler;50:CANActivityinterrupttowakeup
  93. DCDUART4_IRQHandler;51:UART4
  94. DCDSSP2_IRQHandler;52:SSP2
  95. DCDLCD_IRQHandler;53:LCD
  96. DCDGPIO_IRQHandler;54:GPIO
  97. DCDPWM0_IRQHandler;55:PWM0
  98. DCDEEPROM_IRQHandler;56:EEPROM
  99. IF:LNOT::DEF:NO_CRP
  100. AREA|.ARM.__at_0x02FC|,CODE,READONLY
  101. CRP_KeyDCD0xFFFFFFFF
  102. ENDIF
  103. AREA|.text|,CODE,READONLY
  104. ;ResetHandler
  105. Reset_HandlerPROC
  106. EXPORTReset_Handler[WEAK]
  107. IMPORTSystemInit
  108. IMPORT__main
  109. LDRR0,=SystemInit
  110. BLXR0
  111. LDRR0,=__main
  112. BXR0
  113. ENDP
  114. ;DummyExceptionHandlers(infiniteloopswhichcanbemodified)
  115. NMI_HandlerPROC
  116. EXPORTNMI_Handler[WEAK]
  117. B.
  118. ENDP
  119. HardFault_Handler\
  120. PROC
  121. EXPORTHardFault_Handler[WEAK]
  122. B.
  123. ENDP
  124. MemManage_Handler\
  125. PROC
  126. EXPORTMemManage_Handler[WEAK]
  127. B.
  128. ENDP
  129. BusFault_Handler\
  130. PROC
  131. EXPORTBusFault_Handler[WEAK]
  132. B.
  133. ENDP
  134. UsageFault_Handler\
  135. PROC
  136. EXPORTUsageFault_Handler[WEAK]
  137. B.
  138. ENDP
  139. SVC_HandlerPROC
  140. EXPORTSVC_Handler[WEAK]
  141. B.
  142. ENDP
  143. DebugMon_Handler\
  144. PROC
  145. EXPORTDebugMon_Handler[WEAK]
  146. B.
  147. ENDP
  148. PendSV_HandlerPROC
  149. EXPORTPendSV_Handler[WEAK]
  150. B.
  151. ENDP
  152. SysTick_HandlerPROC
  153. EXPORTSysTick_Handler[WEAK]
  154. B.
  155. ENDP
  156. Default_HandlerPROC
  157. EXPORTWDT_IRQHandler[WEAK]
  158. EXPORTTIMER0_IRQHandler[WEAK]
  159. EXPORTTIMER1_IRQHandler[WEAK]
  160. EXPORTTIMER2_IRQHandler[WEAK]
  161. EXPORTTIMER3_IRQHandler[WEAK]
  162. EXPORTUART0_IRQHandler[WEAK]
  163. EXPORTUART1_IRQHandler[WEAK]
  164. EXPORTUART2_IRQHandler[WEAK]
  165. EXPORTUART3_IRQHandler[WEAK]
  166. EXPORTPWM1_IRQHandler[WEAK]
  167. EXPORTI2C0_IRQHandler[WEAK]
  168. EXPORTI2C1_IRQHandler[WEAK]
  169. EXPORTI2C2_IRQHandler[WEAK]
  170. EXPORTSPIFI_IRQHandler[WEAK]
  171. EXPORTSSP0_IRQHandler[WEAK]
  172. EXPORTSSP1_IRQHandler[WEAK]
  173. EXPORTPLL0_IRQHandler[WEAK]
  174. EXPORTRTC_IRQHandler[WEAK]
  175. EXPORTEINT0_IRQHandler[WEAK]
  176. EXPORTEINT1_IRQHandler[WEAK]
  177. EXPORTEINT2_IRQHandler[WEAK]
  178. EXPORTEINT3_IRQHandler[WEAK]
  179. EXPORTADC_IRQHandler[WEAK]
  180. EXPORTBOD_IRQHandler[WEAK]
  181. EXPORTUSB_IRQHandler[WEAK]
  182. EXPORTCAN_IRQHandler[WEAK]
  183. EXPORTDMA_IRQHandler[WEAK]
  184. EXPORTI2S_IRQHandler[WEAK]
  185. EXPORTENET_IRQHandler[WEAK]
  186. EXPORTMCI_IRQHandler[WEAK]
  187. EXPORTMCPWM_IRQHandler[WEAK]
  188. EXPORTQEI_IRQHandler[WEAK]
  189. EXPORTPLL1_IRQHandler[WEAK]
  190. EXPORTUSBActivity_IRQHandler[WEAK]
  191. EXPORTCANActivity_IRQHandler[WEAK]
  192. EXPORTUART4_IRQHandler[WEAK]
  193. EXPORTSSP2_IRQHandler[WEAK]
  194. EXPORTLCD_IRQHandler[WEAK]
  195. EXPORTGPIO_IRQHandler[WEAK]
  196. EXPORTPWM0_IRQHandler[WEAK]
  197. EXPORTEEPROM_IRQHandler[WEAK]
  198. WDT_IRQHandler
  199. TIMER0_IRQHandler
  200. TIMER1_IRQHandler
  201. TIMER2_IRQHandler
  202. TIMER3_IRQHandler
  203. UART0_IRQHandler
  204. UART1_IRQHandler
  205. UART2_IRQHandler
  206. UART3_IRQHandler
  207. PWM1_IRQHandler
  208. I2C0_IRQHandler
  209. I2C1_IRQHandler
  210. I2C2_IRQHandler
  211. SPIFI_IRQHandler
  212. SSP0_IRQHandler
  213. SSP1_IRQHandler
  214. PLL0_IRQHandler
  215. RTC_IRQHandler
  216. EINT0_IRQHandler
  217. EINT1_IRQHandler
  218. EINT2_IRQHandler
  219. EINT3_IRQHandler
  220. ADC_IRQHandler
  221. BOD_IRQHandler
  222. USB_IRQHandler
  223. CAN_IRQHandler
  224. DMA_IRQHandler
  225. I2S_IRQHandler
  226. ENET_IRQHandler
  227. MCI_IRQHandler
  228. MCPWM_IRQHandler
  229. QEI_IRQHandler
  230. PLL1_IRQHandler
  231. USBActivity_IRQHandler
  232. CANActivity_IRQHandler
  233. UART4_IRQHandler
  234. SSP2_IRQHandler
  235. LCD_IRQHandler
  236. GPIO_IRQHandler
  237. PWM0_IRQHandler
  238. EEPROM_IRQHandler
  239. B.
  240. ENDP
  241. ALIGN
  242. ;UserInitialStack&Heap
  243. IF:DEF:__MICROLIB
  244. EXPORT__initial_sp
  245. EXPORT__heap_base
  246. EXPORT__heap_limit
  247. ELSE
  248. IMPORT__use_two_region_memory
  249. EXPORT__user_initial_stackheap
  250. __user_initial_stackheap
  251. LDRR0,=Heap_Mem
  252. LDRR1,=(Stack_Mem+Stack_Size)
  253. LDRR2,=(Heap_Mem+Heap_Size)
  254. LDRR3,=Stack_Mem
  255. BXLR
  256. ALIGN
  257. ENDIF
  258. END

程序完结如下内容的作业:

拓荒一块巨细为Stack_Size的栈空间;

标号__initial_sp指向栈顶方位;

界说堆空间巨细为Heap_Size;

树立中止向量表Vectors,cortex-M3规则开始地址有必要寄存栈顶地址即__initial_sp,紧接着寄存复位进口地址,这样内核复位后就会主动从开始地址的下32位取出复位地址碑文复位中止服务函数。

Reset_Handler复位中止函数中先EXPORT声明Reset_Handler的全局性,然后别离碑文外部的函数SystemInit和__main。

下面临汇编程序中的几个关键字做阐明:

AREA伪指令:用于界说代码段和数据段,后跟特点标号。其间“READWRITE”一共可读写,“READONLY”只读特点。依据LPC1788的数据手册描绘的存储介质,可知可读写段保持在SRAM区,开始地址为0x1000 0000,代码中的仓库保存在SRAM空间。只读段保存在Flash区,开始地址为0x0000 0000,代码中的中止向量表保存在Flash空间。 因而能够总结出,在0x0000 0000 寄存的是栈顶的地址__initial_sp(即0x1000 0200),在0x0000 0004 寄存的是Reset_Handler的地址。

图1:LPC1788 地址映射

图2: debug中 0地址的值0x1000 0200 即栈顶地址, 0x0000 0004 地址值为0x0000 00F9(看反汇编可知该值 即Reset_Handler的进口如下图)。

DCD指令:拓荒内存空间,中止向量表树立中运用相当于C言语中的函数指针,每个成员都是函数指针,指向各个中止服务函数。

自此剖析了LPC1788的发动,首要包含仓库初始化,和中止向量表的初始化。LPC1788有内部Flash,所以上点从内部Flash发动,内部Flash的开始地址为0x0000 0000,寄存栈顶的地址0x1000 0200。 0x0000 0004寄存复位中止的进口地址。LPC1788复位后,从0x0000 0004取出复位进口地址,碑文中止复位函数,然后跳转到SystemInit和main C言语函数碑文。

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/xinpin/265675.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部