iar_startup_lpc5410x.s 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. ;/*****************************************************************************
  2. ; * @file: startup_LPC5410x.s
  3. ; * @purpose: CMSIS Cortex-M4/M0+ Core Device Startup File
  4. ; * for the NXP LPC5410x Device Series (manually edited)
  5. ; * @version: V1.00
  6. ; * @date: 19. October 2009
  7. ; *----------------------------------------------------------------------------
  8. ; *
  9. ; * Copyright (C) 2009 ARM Limited. All rights reserved.
  10. ; *
  11. ; * ARM Limited (ARM) is supplying this software for use with Cortex-Mx
  12. ; * processor based microcontrollers. This file can be freely distributed
  13. ; * within development tools that are supporting such ARM based processors.
  14. ; *
  15. ; * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED
  16. ; * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
  17. ; * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
  18. ; * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
  19. ; * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
  20. ; *
  21. ; ******************************************************************************/
  22. ;
  23. ; The modules in this file are included in the libraries, and may be replaced
  24. ; by any user-defined modules that define the PUBLIC symbol _program_start or
  25. ; a user defined start symbol.
  26. ; To override the cstartup defined in the library, simply add your modified
  27. ; version to the workbench project.
  28. ;
  29. ; The vector table is normally located at address 0.
  30. ; When debugging in RAM, it can be located in RAM, aligned to at least 2^6.
  31. ; The name "__vector_table" has special meaning for C-SPY:
  32. ; it is where the SP start value is found, and the NVIC vector
  33. ; table register (VTOR) is initialized to this address if != 0.
  34. ;
  35. ; Cortex-M version
  36. ;
  37. MODULE ?cstartup
  38. ;; Forward declaration of sections.
  39. SECTION CSTACK:DATA:NOROOT(3)
  40. SECTION .intvec:CODE:NOROOT(2)
  41. EXTERN __iar_program_start
  42. PUBLIC __vector_table
  43. PUBLIC __vector_table_0x1c
  44. PUBLIC __Vectors
  45. PUBLIC __Vectors_End
  46. PUBLIC __Vectors_Size
  47. DATA
  48. __vector_table
  49. DCD sfe(CSTACK)
  50. DCD Reset_Handler
  51. DCD NMI_Handler
  52. DCD HardFault_Handler
  53. DCD MemManage_Handler
  54. DCD BusFault_Handler
  55. DCD UsageFault_Handler
  56. __vector_table_0x1c
  57. DCD 0 ; Checksum of the first 7 words
  58. DCD 0
  59. DCD 0 ; Enhanced image marker, set to 0x0 for legacy boot
  60. DCD 0 ; Pointer to enhanced boot block, set to 0x0 for legacy boot
  61. DCD SVC_Handler
  62. DCD DebugMon_Handler
  63. DCD 0
  64. DCD PendSV_Handler
  65. DCD SysTick_Handler
  66. ; External Interrupts
  67. DCD WDT_IRQHandler ; Watchdog
  68. DCD BOD_IRQHandler ; Brown Out Detect
  69. DCD Reserved_IRQHandler ; Reserved
  70. DCD DMA_IRQHandler ; DMA Controller
  71. DCD GINT0_IRQHandler ; GPIO Group0 Interrupt
  72. DCD PIN_INT0_IRQHandler ; PIO INT0
  73. DCD PIN_INT1_IRQHandler ; PIO INT1
  74. DCD PIN_INT2_IRQHandler ; PIO INT2
  75. DCD PIN_INT3_IRQHandler ; PIO INT3
  76. DCD UTICK_IRQHandler ; UTICK timer
  77. DCD MRT_IRQHandler ; Multi-Rate Timer
  78. DCD CT32B0_IRQHandler ; CT32B0
  79. DCD CT32B1_IRQHandler ; CT32B1
  80. DCD CT32B2_IRQHandler ; CT32B2
  81. DCD CT32B3_IRQHandler ; CT32B3
  82. DCD CT32B4_IRQHandler ; CT32B4
  83. DCD SCT0_IRQHandler ; Smart Counter Timer
  84. DCD UART0_IRQHandler ; UART0
  85. DCD UART1_IRQHandler ; UART1
  86. DCD UART2_IRQHandler ; UART2
  87. DCD UART3_IRQHandler ; UART3
  88. DCD I2C0_IRQHandler ; I2C0 controller
  89. DCD I2C1_IRQHandler ; I2C1 controller
  90. DCD I2C2_IRQHandler ; I2C2 controller
  91. DCD SPI0_IRQHandler ; SPI0 controller
  92. DCD SPI1_IRQHandler ; SPI1 controller
  93. DCD ADC_SEQA_IRQHandler ; ADC0 A sequence (A/D Converter) interrupt
  94. DCD ADC_SEQB_IRQHandler ; ADC0 B sequence (A/D Converter) interrupt
  95. DCD ADC_THCMP_IRQHandler ; ADC THCMP and OVERRUN ORed
  96. DCD RTC_IRQHandler ; RTC Timer
  97. DCD Reserved_IRQHandler ; Reserved
  98. DCD MAILBOX_IRQHandler ; Mailbox
  99. DCD GINT1_IRQHandler ; GPIO Group1 Interrupt
  100. DCD PIN_INT4_IRQHandler ; PIO INT4
  101. DCD PIN_INT5_IRQHandler ; PIO INT5
  102. DCD PIN_INT6_IRQHandler ; PIO INT6
  103. DCD PIN_INT7_IRQHandler ; PIO INT7
  104. DCD Reserved_IRQHandler ; Reserved
  105. DCD Reserved_IRQHandler ; Reserved
  106. DCD Reserved_IRQHandler ; Reserved
  107. DCD RIT_IRQHandler ; RITimer
  108. DCD Reserved41_IRQHandler ; Reserved
  109. DCD Reserved42_IRQHandler ; Reserved
  110. DCD Reserved43_IRQHandler ; Reserved
  111. DCD Reserved44_IRQHandler ; Reserved
  112. __Vectors_End
  113. __Vectors EQU __vector_table
  114. __Vectors_Size EQU __Vectors_End - __Vectors
  115. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  116. ;;
  117. ;; Default interrupt handlers.
  118. ;;
  119. #if !defined(SLAVEBOOT)
  120. DATA
  121. cpu_id EQU 0xE000ED00
  122. cpu_ctrl EQU 0x40000300
  123. coproc_boot EQU 0x40000304
  124. coproc_stack EQU 0x40000308
  125. rel_vals
  126. DC32 cpu_id, cpu_ctrl, coproc_boot, coproc_stack
  127. DC16 0xFFF, 0xC24
  128. #endif
  129. THUMB
  130. PUBWEAK Reset_Handler
  131. SECTION .text:CODE:REORDER:NOROOT(2)
  132. ; Reset Handler - shared for both cores
  133. Reset_Handler
  134. #if !defined(SLAVEBOOT)
  135. ; Both the M0+ and M4 core come via this shared startup code,
  136. ; but the M0+ and M4 core have different vector tables.
  137. ; Determine if the core executing this code is the master or
  138. ; the slave and handle each core state individually.
  139. shared_boot_entry
  140. LDR r6, =rel_vals
  141. MOVS r4, #0 ; Flag for slave core (0)
  142. MOVS r5, #1
  143. ; Determine which core (M0+ or M4) this code is running on
  144. ; r2 = (((*cpu_id) >> 4) & 0xFFF); (M4 core == 0xC24)
  145. get_current_core_id
  146. LDR r0, [r6, #0]
  147. LDR r1, [r0] ; r1 = CPU ID status
  148. LSRS r1, r1, #4 ; Right justify 12 CPU ID bits
  149. LDRH r2, [r6, #16] ; Mask for CPU ID bits
  150. ANDS r2, r1, r2 ; r2 = ARM COrtex CPU ID
  151. LDRH r3, [r6, #18] ; Mask for CPU ID bits
  152. CMP r3, r2 ; Core ID matches M4 identifier
  153. BNE get_master_status
  154. MOV r4, r5 ; Set flag for master core (1)
  155. ; Determine if M4 core is the master or slave
  156. ; r3 = ((*cpu_ctrl) & 1); (0 == m0+, 1 == M4)
  157. get_master_status
  158. LDR r0, [r6, #4]
  159. LDR r3, [r0] ; r3 = SYSCON co-processor CPU control status
  160. ANDS r3, r3, r5 ; r3 = (Bit 0: 1 = M4 is master, 0 = M4 is slave)
  161. ; Select boot based on selected master core and core ID
  162. select_boot
  163. EORS r3, r3, r4 ; r4 = (Bit 0: 0 = master, 1 = slave)
  164. BNE slave_boot
  165. B normal_boot
  166. ; Slave boot
  167. slave_boot
  168. LDR r0, [r6, #8]
  169. LDR r2, [r0] ; r1 = SYSCON co-processor boot address
  170. CMP r2, #0 ; Slave boot address = 0 (not set up)?
  171. BEQ cpu_sleep
  172. LDR r0, [r6, #12]
  173. LDR r1, [r0] ; r5 = SYSCON co-processor stack address
  174. MOV sp, r1 ; Update slave CPU stack pointer
  175. ; Be sure to update VTOR for the slave MCU to point to the
  176. ; slave vector table in boot memory
  177. BX r2 ; Jump to slave boot address
  178. ; Slave isn't yet setup for system boot from the master
  179. ; so sleep until the master sets it up and then reboots it
  180. cpu_sleep
  181. MOV sp, r5 ; Will force exception if something happens
  182. cpu_sleep_wfi
  183. WFI ; Sleep forever until master reboots
  184. B cpu_sleep_wfi
  185. #endif ; defined(SLAVEBOOT)
  186. ; Normal boot for master/slave
  187. normal_boot
  188. LDR r0, =SystemInit
  189. BLX r0
  190. LDR r0, =__iar_program_start
  191. BX r0
  192. ; For cores with SystemInit() or __iar_program_start(), the code will sleep the MCU
  193. PUBWEAK SystemInit
  194. SECTION .text:CODE:REORDER:NOROOT(1)
  195. SystemInit
  196. BX LR
  197. PUBWEAK NMI_Handler
  198. SECTION .text:CODE:REORDER:NOROOT(1)
  199. NMI_Handler
  200. B .
  201. PUBWEAK HardFault_Handler
  202. SECTION .text:CODE:REORDER:NOROOT(1)
  203. HardFault_Handler
  204. B .
  205. PUBWEAK MemManage_Handler
  206. SECTION .text:CODE:REORDER:NOROOT(1)
  207. MemManage_Handler
  208. B .
  209. PUBWEAK BusFault_Handler
  210. SECTION .text:CODE:REORDER:NOROOT(1)
  211. BusFault_Handler
  212. B .
  213. PUBWEAK UsageFault_Handler
  214. SECTION .text:CODE:REORDER:NOROOT(1)
  215. UsageFault_Handler
  216. B .
  217. PUBWEAK SVC_Handler
  218. SECTION .text:CODE:REORDER:NOROOT(1)
  219. SVC_Handler
  220. B .
  221. PUBWEAK DebugMon_Handler
  222. SECTION .text:CODE:REORDER:NOROOT(1)
  223. DebugMon_Handler
  224. B .
  225. PUBWEAK PendSV_Handler
  226. SECTION .text:CODE:REORDER:NOROOT(1)
  227. PendSV_Handler
  228. B .
  229. PUBWEAK SysTick_Handler
  230. SECTION .text:CODE:REORDER:NOROOT(1)
  231. SysTick_Handler
  232. B .
  233. PUBWEAK Reserved_IRQHandler
  234. SECTION .text:CODE:REORDER:NOROOT(1)
  235. Reserved_IRQHandler
  236. B .
  237. PUBWEAK WDT_IRQHandler ; Watchdog
  238. PUBWEAK BOD_IRQHandler ; Brown Out Detect
  239. PUBWEAK DMA_IRQHandler ; DMA Controller
  240. PUBWEAK GINT0_IRQHandler ; GPIO Group0 Interrupt
  241. PUBWEAK PIN_INT0_IRQHandler ; PIO INT0
  242. PUBWEAK PIN_INT1_IRQHandler ; PIO INT1
  243. PUBWEAK PIN_INT2_IRQHandler ; PIO INT2
  244. PUBWEAK PIN_INT3_IRQHandler ; PIO INT3
  245. PUBWEAK UTICK_IRQHandler ; UTICK timer
  246. PUBWEAK MRT_IRQHandler ; Multi-Rate Timer
  247. PUBWEAK CT32B0_IRQHandler ; CT32B0
  248. PUBWEAK CT32B1_IRQHandler ; CT32B1
  249. PUBWEAK CT32B2_IRQHandler ; CT32B2
  250. PUBWEAK CT32B3_IRQHandler ; CT32B3
  251. PUBWEAK CT32B4_IRQHandler ; CT32B4
  252. PUBWEAK UART0_IRQHandler ; UART0
  253. PUBWEAK SCT0_IRQHandler ; Smart Counter Timer
  254. PUBWEAK UART1_IRQHandler ; UART1
  255. PUBWEAK UART2_IRQHandler ; UART2
  256. PUBWEAK UART3_IRQHandler ; UART3
  257. PUBWEAK I2C0_IRQHandler ; I2C0 controller
  258. PUBWEAK I2C1_IRQHandler ; I2C1 controller
  259. PUBWEAK I2C2_IRQHandler ; I2C2 controller
  260. PUBWEAK SPI0_IRQHandler ; SPI0 controller
  261. PUBWEAK SPI1_IRQHandler ; SPI1 controller
  262. PUBWEAK ADC_SEQA_IRQHandler ; ADC0 A sequence (A/D Converter) interrupt
  263. PUBWEAK ADC_SEQB_IRQHandler ; ADC0 B sequence (A/D Converter) interrupt
  264. PUBWEAK ADC_THCMP_IRQHandler ; ADC THCMP and OVERRUN ORed
  265. PUBWEAK RTC_IRQHandler ; RTC Timer
  266. PUBWEAK MAILBOX_IRQHandler ; Mailbox
  267. PUBWEAK GINT1_IRQHandler ; GPIO Group1 Interrupt
  268. PUBWEAK PIN_INT4_IRQHandler ; PIO INT4
  269. PUBWEAK PIN_INT5_IRQHandler ; PIO INT5
  270. PUBWEAK PIN_INT6_IRQHandler ; PIO INT6
  271. PUBWEAK PIN_INT7_IRQHandler ; PIO INT7
  272. PUBWEAK RIT_IRQHandler ; RITimer
  273. PUBWEAK Reserved41_IRQHandler ; Reserved
  274. PUBWEAK Reserved42_IRQHandler ; Reserved
  275. PUBWEAK Reserved43_IRQHandler ; Reserved
  276. PUBWEAK Reserved44_IRQHandler ; Reserved
  277. WDT_IRQHandler ; Watchdog
  278. BOD_IRQHandler ; Brown Out Detect
  279. DMA_IRQHandler ; DMA Controller
  280. GINT0_IRQHandler ; GPIO Group0 Interrupt
  281. PIN_INT0_IRQHandler ; PIO INT0
  282. PIN_INT1_IRQHandler ; PIO INT1
  283. PIN_INT2_IRQHandler ; PIO INT2
  284. PIN_INT3_IRQHandler ; PIO INT3
  285. UTICK_IRQHandler ; UTICK timer
  286. MRT_IRQHandler ; Multi-Rate Timer
  287. CT32B0_IRQHandler ; CT32B0
  288. CT32B1_IRQHandler ; CT32B1
  289. CT32B2_IRQHandler ; CT32B2
  290. CT32B3_IRQHandler ; CT32B3
  291. CT32B4_IRQHandler ; CT32B4
  292. UART0_IRQHandler ; UART0
  293. SCT0_IRQHandler ; Smart Counter Timer
  294. UART1_IRQHandler ; UART1
  295. UART2_IRQHandler ; UART2
  296. UART3_IRQHandler ; UART3
  297. I2C0_IRQHandler ; I2C0 controller
  298. I2C1_IRQHandler ; I2C1 controller
  299. I2C2_IRQHandler ; I2C2 controller
  300. SPI0_IRQHandler ; SPI0 controller
  301. SPI1_IRQHandler ; SPI1 controller
  302. ADC_SEQA_IRQHandler ; ADC0 A sequence (A/D Converter) interrupt
  303. ADC_SEQB_IRQHandler ; ADC0 B sequence (A/D Converter) interrupt
  304. ADC_THCMP_IRQHandler ; ADC THCMP and OVERRUN ORed
  305. RTC_IRQHandler ; RTC Timer
  306. MAILBOX_IRQHandler ; Mailbox
  307. GINT1_IRQHandler ; GPIO Group1 Interrupt
  308. PIN_INT4_IRQHandler ; PIO INT4
  309. PIN_INT5_IRQHandler ; PIO INT5
  310. PIN_INT6_IRQHandler ; PIO INT6
  311. PIN_INT7_IRQHandler ; PIO INT7
  312. RIT_IRQHandler ; RITimer
  313. Reserved41_IRQHandler ; Reserved
  314. Reserved42_IRQHandler ; Reserved
  315. Reserved43_IRQHandler ; Reserved
  316. Reserved44_IRQHandler ; Reserved
  317. Default_Handler:
  318. B .
  319. END