新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > Cortex-M3 (NXP LPC1788)之啟動代碼分析

Cortex-M3 (NXP LPC1788)之啟動代碼分析

作者: 時間:2016-11-19 來源:網(wǎng)絡(luò) 收藏
在Keil uVision4中新建一個基于NXP1788的工程后,會提示添加啟動匯編代碼startup_LPC177x_8x.S。該文件進(jìn)行從匯編到C語言運(yùn)行環(huán)境的初始化工作。

本文引用地址:http://m.butianyuan.cn/article/201611/318444.htm
  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

程序完成如下內(nèi)容的工作:

開辟一塊大小為Stack_Size的??臻g;

標(biāo)號__initial_sp指向棧頂位置;

定義堆空間大小為Heap_Size;

建立中斷向量表Vectors,cortex-M3規(guī)定起始地址必須存放棧頂?shù)刂芳確_initial_sp,緊接著存放復(fù)位入口地址,這樣內(nèi)核復(fù)位后就會自動從起始地址的下32位取出復(fù)位地址執(zhí)行復(fù)位中斷服務(wù)函數(shù)。

Reset_Handler復(fù)位中斷函數(shù)中先EXPORT聲明Reset_Handler的全局性,然后分別執(zhí)行外部的函數(shù)SystemInit和__main。

下面對匯編程序中的幾個關(guān)鍵字做說明:

AREA偽指令:用于定義代碼段和數(shù)據(jù)段,后跟屬性標(biāo)號。其中“READWRITE”表示可讀寫,“READONLY”只讀屬性。根據(jù)LPC1788的數(shù)據(jù)手冊描述的存儲介質(zhì),可知可讀寫段保持在SRAM區(qū),起始地址為0x1000 0000,代碼中的堆棧保存在SRAM空間。只讀段保存在Flash區(qū),起始地址為0x0000 0000,代碼中的中斷向量表保存在Flash空間。 因此可以總結(jié)出,在0x0000 0000 存放的是棧頂?shù)牡刂穇_initial_sp(即0x1000 0200),在0x0000 0004 存放的是Reset_Handler的地址。

圖1:LPC1788 地址映射

圖2: debug中 0地址的值0x1000 0200 即棧頂?shù)刂罚?0x0000 0004 地址值為0x0000 00F9(看反匯編可知該值 即Reset_Handler的入口如下圖)。

DCD指令:開辟內(nèi)存空間,中斷向量表建立中使用相當(dāng)于C語言中的函數(shù)指針,每個成員都是函數(shù)指針,指向各個中斷服務(wù)函數(shù)。

自此分析了LPC1788的啟動,主要包括堆棧初始化,和中斷向量表的初始化。LPC1788有內(nèi)部Flash,所以上點(diǎn)從內(nèi)部Flash啟動,內(nèi)部Flash的起始地址為0x0000 0000,存放棧頂?shù)牡刂?x1000 0200。 0x0000 0004存放復(fù)位中斷的入口地址。LPC1788復(fù)位后,從0x0000 0004取出復(fù)位入口地址,執(zhí)行中斷復(fù)位函數(shù),從而跳轉(zhuǎn)到SystemInit和main C語言函數(shù)執(zhí)行。



關(guān)鍵詞: Cortex-M3NXPLPC1788啟動代

評論


相關(guān)推薦

技術(shù)專區(qū)

關(guān)閉