keil_startup_lpc5410x.s 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. ;/*
  2. ; * @brief LPC5410x startup code for Keil
  3. ; *
  4. ; * @note
  5. ; * Copyright(C) NXP Semiconductors, 2014
  6. ; * All rights reserved.
  7. ; *
  8. ; * @par
  9. ; * Software that is described herein is for illustrative purposes only
  10. ; * which provides customers with programming information regarding the
  11. ; * LPC products. This software is supplied "AS IS" without any warranties of
  12. ; * any kind, and NXP Semiconductors and its licensor disclaim any and
  13. ; * all warranties, express or implied, including all implied warranties of
  14. ; * merchantability, fitness for a particular purpose and non-infringement of
  15. ; * intellectual property rights. NXP Semiconductors assumes no responsibility
  16. ; * or liability for the use of the software, conveys no license or rights under any
  17. ; * patent, copyright, mask work right, or any other intellectual property rights in
  18. ; * or to any products. NXP Semiconductors reserves the right to make changes
  19. ; * in the software without notification. NXP Semiconductors also makes no
  20. ; * representation or warranty that such application will be suitable for the
  21. ; * specified use without further testing or modification.
  22. ; *
  23. ; * @par
  24. ; * Permission to use, copy, modify, and distribute this software and its
  25. ; * documentation is hereby granted, under NXP Semiconductors' and its
  26. ; * licensor's relevant copyrights in the software, without fee, provided that it
  27. ; * is used in conjunction with NXP Semiconductors microcontrollers. This
  28. ; * copyright, permission, and disclaimer notice must appear in all copies of
  29. ; * this code.
  30. ; */
  31. ; <h> Stack Configuration
  32. ; <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
  33. ; </h>
  34. Stack_Size EQU 0x00000200
  35. AREA STACK, NOINIT, READWRITE, ALIGN=3
  36. Stack_Mem SPACE Stack_Size
  37. __initial_sp
  38. ; <h> Heap Configuration
  39. ; <o> Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
  40. ; </h>
  41. Heap_Size EQU 0x00000100
  42. AREA HEAP, NOINIT, READWRITE, ALIGN=3
  43. __heap_base
  44. Heap_Mem SPACE Heap_Size
  45. __heap_limit
  46. PRESERVE8
  47. THUMB
  48. ; Vector Table Mapped to Address 0 at Reset
  49. AREA RESET, DATA, READONLY
  50. EXPORT __Vectors
  51. __Vectors DCD __initial_sp ; Top of Stack
  52. DCD Reset_Handler ; Reset Handler
  53. DCD NMI_Handler
  54. DCD HardFault_Handler
  55. DCD MemManage_Handler
  56. DCD BusFault_Handler
  57. DCD UsageFault_Handler
  58. __vector_table_0x1c
  59. DCD 0 ; Checksum of the first 7 words
  60. DCD 0
  61. DCD 0 ; Enhanced image marker, set to 0x0 for legacy boot
  62. DCD 0 ; Pointer to enhanced boot block, set to 0x0 for legacy boot
  63. DCD SVC_Handler
  64. DCD DebugMon_Handler
  65. DCD 0
  66. DCD PendSV_Handler
  67. DCD SysTick_Handler
  68. ; External Interrupts
  69. DCD WDT_IRQHandler ; Watchdog
  70. DCD BOD_IRQHandler ; Brown Out Detect
  71. DCD Reserved_IRQHandler ; Reserved
  72. DCD DMA_IRQHandler ; DMA Controller
  73. DCD GINT0_IRQHandler ; GPIO Group0 Interrupt
  74. DCD PIN_INT0_IRQHandler ; PIO INT0
  75. DCD PIN_INT1_IRQHandler ; PIO INT1
  76. DCD PIN_INT2_IRQHandler ; PIO INT2
  77. DCD PIN_INT3_IRQHandler ; PIO INT3
  78. DCD UTICK_IRQHandler ; UTICK timer
  79. DCD MRT_IRQHandler ; Multi-Rate Timer
  80. DCD CT32B0_IRQHandler ; CT32B0
  81. DCD CT32B1_IRQHandler ; CT32B1
  82. DCD CT32B2_IRQHandler ; CT32B2
  83. DCD CT32B3_IRQHandler ; CT32B3
  84. DCD CT32B4_IRQHandler ; CT32B4
  85. DCD SCT0_IRQHandler ; Smart Counter Timer
  86. DCD UART0_IRQHandler ; UART0
  87. DCD UART1_IRQHandler ; UART1
  88. DCD UART2_IRQHandler ; UART2
  89. DCD UART3_IRQHandler ; UART3
  90. DCD I2C0_IRQHandler ; I2C0 controller
  91. DCD I2C1_IRQHandler ; I2C1 controller
  92. DCD I2C2_IRQHandler ; I2C2 controller
  93. DCD SPI0_IRQHandler ; SPI0 controller
  94. DCD SPI1_IRQHandler ; SPI1 controller
  95. DCD ADC_SEQA_IRQHandler ; ADC0 A sequence (A/D Converter) interrupt
  96. DCD ADC_SEQB_IRQHandler ; ADC0 B sequence (A/D Converter) interrupt
  97. DCD ADC_THCMP_IRQHandler ; ADC THCMP and OVERRUN ORed
  98. DCD RTC_IRQHandler ; RTC Timer
  99. DCD Reserved_IRQHandler ; Reserved
  100. DCD MAILBOX_IRQHandler ; Mailbox
  101. DCD GINT1_IRQHandler ; GPIO Group1 Interrupt
  102. DCD PIN_INT4_IRQHandler ; PIO INT4
  103. DCD PIN_INT5_IRQHandler ; PIO INT5
  104. DCD PIN_INT6_IRQHandler ; PIO INT6
  105. DCD PIN_INT7_IRQHandler ; PIO INT7
  106. DCD Reserved_IRQHandler ; Reserved
  107. DCD Reserved_IRQHandler ; Reserved
  108. DCD Reserved_IRQHandler ; Reserved
  109. DCD RIT_IRQHandler ; RITimer
  110. DCD Reserved41_IRQHandler ; Reserved
  111. DCD Reserved42_IRQHandler ; Reserved
  112. DCD Reserved43_IRQHandler ; Reserved
  113. DCD Reserved44_IRQHandler ; Reserved
  114. ;// <h> Code Read Protection level (CRP)
  115. ;// <o> CRP_Level:
  116. ;// <0xFFFFFFFF=> Disabled
  117. ;// <0x4E697370=> NO_ISP
  118. ;// <0x12345678=> CRP1
  119. ;// <0x87654321=> CRP2
  120. ;// <0x43218765=> CRP3 (Are you sure?)
  121. ;// </h>
  122. ;CRP_Level EQU 0xFFFFFFFF
  123. ;IF :LNOT::DEF:NO_CRP
  124. ;AREA |.ARM.__at_0x02FC|, CODE, READONLY
  125. ;CRP_Key DCD 0xFFFFFFFF
  126. ;ENDIF
  127. AREA |.text|, CODE, READONLY
  128. ;cpu_id EQU 0xE000ED00
  129. ;cpu_ctrl EQU 0x40000300
  130. ;coproc_boot EQU 0x40000304
  131. ;coproc_stack EQU 0x40000308
  132. ;rel_vals
  133. ;DCD cpu_id, cpu_ctrl, coproc_boot, coproc_stack
  134. ;DCW 0xFFF, 0xC24
  135. ; Reset Handler - shared for both cores
  136. Reset_Handler PROC
  137. EXPORT Reset_Handler [WEAK]
  138. EXPORT SystemInit [WEAK]
  139. IMPORT __main
  140. ;IF :LNOT::DEF:SLAVEBOOT
  141. ;Both the M0+ and M4 core come via this shared startup code,
  142. ;but the M0+ and M4 core have different vector tables.
  143. ;Determine if the core executing this code is the master or
  144. ;the slave and handle each core state individually.
  145. ;shared_boot_entry
  146. ;LDR r6, =rel_vals
  147. ;MOVS r4, #0 ; Flag for slave core (0)
  148. ;MOVS r5, #1
  149. ;; Determine which core (M0+ or M4) this code is running on
  150. ;; r2 = (((*cpu_id) >> 4) & 0xFFF); (M4 core == 0xC24)
  151. ;get_current_core_id
  152. ;LDR r0, [r6, #0]
  153. ;LDR r1, [r0] ; r1 = CPU ID status
  154. ;LSRS r1, r1, #4 ; Right justify 12 CPU ID bits
  155. ;LDRH r2, [r6, #16] ; Mask for CPU ID bits
  156. ;ANDS r2, r1, r2 ; r2 = ARM COrtex CPU ID
  157. ;LDRH r3, [r6, #18] ; Mask for CPU ID bits
  158. ;CMP r3, r2 ; Core ID matches M4 identifier
  159. ;BNE get_master_status
  160. ;MOV r4, r5 ; Set flag for master core (1)
  161. ;; Determine if M4 core is the master or slave
  162. ;; r3 = ((*cpu_ctrl) & 1); (0 == m0+, 1 == M4)
  163. ;get_master_status
  164. ;LDR r0, [r6, #4]
  165. ;LDR r3, [r0] ; r3 = SYSCON co-processor CPU control status
  166. ;ANDS r3, r3, r5 ; r3 = (Bit 0: 1 = M4 is master, 0 = M4 is slave)
  167. ;; Select boot based on selected master core and core ID
  168. ;select_boot
  169. ;EORS r3, r3, r4 ; r4 = (Bit 0: 0 = master, 1 = slave)
  170. ;BNE slave_boot
  171. ;B normal_boot
  172. ;; Slave boot
  173. ;slave_boot
  174. ;LDR r0, [r6, #8]
  175. ;LDR r2, [r0] ; r1 = SYSCON co-processor boot address
  176. ;CMP r2, #0 ; Slave boot address = 0 (not set up)?
  177. ;BEQ cpu_sleep
  178. ;LDR r0, [r6, #12]
  179. ;LDR r1, [r0] ; r5 = SYSCON co-processor stack address
  180. ;MOV sp, r1 ; Update slave CPU stack pointer
  181. ;; Be sure to update VTOR for the slave MCU to point to the
  182. ;; slave vector table in boot memory
  183. ;BX r2 ; Jump to slave boot address
  184. ;; Slave isn't yet setup for system boot from the master
  185. ;; so sleep until the master sets it up and then reboots it
  186. ;cpu_sleep
  187. ;MOV sp, r5 ; Will force exception if something happens
  188. ;cpu_sleep_wfi
  189. ;WFI ; Sleep forever until master reboots
  190. ;B cpu_sleep_wfi
  191. ;ENDIF
  192. ; Normal boot for master/slave
  193. ;normal_boot
  194. LDR r0, =SystemInit
  195. BLX r0
  196. LDR r0, =__main
  197. BX r0
  198. ENDP
  199. ; For cores with SystemInit() or __main(), the code will sleep the MCU
  200. SystemInit PROC
  201. EXPORT SystemInit [WEAK]
  202. BX lr
  203. ENDP
  204. ; Dummy Exception Handlers (infinite loops which can be modified)
  205. NMI_Handler PROC
  206. EXPORT NMI_Handler [WEAK]
  207. B .
  208. ENDP
  209. HardFault_Handler\
  210. PROC
  211. EXPORT HardFault_Handler [WEAK]
  212. B .
  213. ENDP
  214. MemManage_Handler PROC
  215. EXPORT MemManage_Handler [WEAK]
  216. B .
  217. ENDP
  218. BusFault_Handler PROC
  219. EXPORT BusFault_Handler [WEAK]
  220. B .
  221. ENDP
  222. UsageFault_Handler PROC
  223. EXPORT UsageFault_Handler [WEAK]
  224. B .
  225. ENDP
  226. SVC_Handler PROC
  227. EXPORT SVC_Handler [WEAK]
  228. B .
  229. ENDP
  230. DebugMon_Handler PROC
  231. EXPORT DebugMon_Handler [WEAK]
  232. B .
  233. ENDP
  234. PendSV_Handler PROC
  235. EXPORT PendSV_Handler [WEAK]
  236. B .
  237. ENDP
  238. SysTick_Handler PROC
  239. EXPORT SysTick_Handler [WEAK]
  240. B .
  241. ENDP
  242. Default_Handler PROC
  243. EXPORT WDT_IRQHandler [WEAK] ; Watchdog
  244. EXPORT BOD_IRQHandler [WEAK] ; Brown Out Detect
  245. EXPORT DMA_IRQHandler [WEAK] ; DMA Controller
  246. EXPORT GINT0_IRQHandler [WEAK] ; GPIO Group0 Interrupt
  247. EXPORT PIN_INT0_IRQHandler [WEAK] ; PIO INT0
  248. EXPORT PIN_INT1_IRQHandler [WEAK] ; PIO INT1
  249. EXPORT PIN_INT2_IRQHandler [WEAK] ; PIO INT2
  250. EXPORT PIN_INT3_IRQHandler [WEAK] ; PIO INT3
  251. EXPORT UTICK_IRQHandler [WEAK] ; UTICK timer
  252. EXPORT MRT_IRQHandler [WEAK] ; Multi-Rate Timer
  253. EXPORT CT32B0_IRQHandler [WEAK] ; CT32B0
  254. EXPORT CT32B1_IRQHandler [WEAK] ; CT32B1
  255. EXPORT CT32B2_IRQHandler [WEAK] ; CT32B2
  256. EXPORT CT32B3_IRQHandler [WEAK] ; CT32B3
  257. EXPORT CT32B4_IRQHandler [WEAK] ; CT32B4
  258. EXPORT UART0_IRQHandler [WEAK] ; UART0
  259. EXPORT SCT0_IRQHandler [WEAK] ; Smart Counter Timer
  260. EXPORT UART1_IRQHandler [WEAK] ; UART1
  261. EXPORT UART2_IRQHandler [WEAK] ; UART2
  262. EXPORT UART3_IRQHandler [WEAK] ; UART3
  263. EXPORT I2C0_IRQHandler [WEAK] ; I2C0 controller
  264. EXPORT I2C1_IRQHandler [WEAK] ; I2C1 controller
  265. EXPORT I2C2_IRQHandler [WEAK] ; I2C2 controller
  266. EXPORT SPI0_IRQHandler [WEAK] ; SPI0 controller
  267. EXPORT SPI1_IRQHandler [WEAK] ; SPI1 controller
  268. EXPORT ADC_SEQA_IRQHandler [WEAK] ; ADC0 A sequence (A/D Converter) interrupt
  269. EXPORT ADC_SEQB_IRQHandler [WEAK] ; ADC0 B sequence (A/D Converter) interrupt
  270. EXPORT ADC_THCMP_IRQHandler [WEAK] ; ADC THCMP and OVERRUN ORed
  271. EXPORT RTC_IRQHandler [WEAK] ; RTC Timer
  272. EXPORT MAILBOX_IRQHandler [WEAK] ; Mailbox
  273. EXPORT GINT1_IRQHandler [WEAK] ; GPIO Group1 Interrupt
  274. EXPORT PIN_INT4_IRQHandler [WEAK] ; PIO INT4
  275. EXPORT PIN_INT5_IRQHandler [WEAK] ; PIO INT5
  276. EXPORT PIN_INT6_IRQHandler [WEAK] ; PIO INT6
  277. EXPORT PIN_INT7_IRQHandler [WEAK] ; PIO INT7
  278. EXPORT RIT_IRQHandler [WEAK] ; RITimer
  279. EXPORT Reserved41_IRQHandler [WEAK] ; Reserved
  280. EXPORT Reserved42_IRQHandler [WEAK] ; Reserved
  281. EXPORT Reserved43_IRQHandler [WEAK] ; Reserved
  282. EXPORT Reserved44_IRQHandler [WEAK] ; Reserved
  283. EXPORT Reserved_IRQHandler [WEAK] ; Reserved
  284. WDT_IRQHandler ; Watchdog
  285. BOD_IRQHandler ; Brown Out Detect
  286. DMA_IRQHandler ; DMA Controller
  287. GINT0_IRQHandler ; GPIO Group0 Interrupt
  288. PIN_INT0_IRQHandler ; PIO INT0
  289. PIN_INT1_IRQHandler ; PIO INT1
  290. PIN_INT2_IRQHandler ; PIO INT2
  291. PIN_INT3_IRQHandler ; PIO INT3
  292. UTICK_IRQHandler ; UTICK timer
  293. MRT_IRQHandler ; Multi-Rate Timer
  294. CT32B0_IRQHandler ; CT32B0
  295. CT32B1_IRQHandler ; CT32B1
  296. CT32B2_IRQHandler ; CT32B2
  297. CT32B3_IRQHandler ; CT32B3
  298. CT32B4_IRQHandler ; CT32B4
  299. UART0_IRQHandler ; UART0
  300. SCT0_IRQHandler ; Smart Counter Timer
  301. UART1_IRQHandler ; UART1
  302. UART2_IRQHandler ; UART2
  303. UART3_IRQHandler ; UART3
  304. I2C0_IRQHandler ; I2C0 controller
  305. I2C1_IRQHandler ; I2C1 controller
  306. I2C2_IRQHandler ; I2C2 controller
  307. SPI0_IRQHandler ; SPI0 controller
  308. SPI1_IRQHandler ; SPI1 controller
  309. ADC_SEQA_IRQHandler ; ADC0 A sequence (A/D Converter) interrupt
  310. ADC_SEQB_IRQHandler ; ADC0 B sequence (A/D Converter) interrupt
  311. ADC_THCMP_IRQHandler ; ADC THCMP and OVERRUN ORed
  312. RTC_IRQHandler ; RTC Timer
  313. MAILBOX_IRQHandler ; Mailbox
  314. GINT1_IRQHandler ; GPIO Group1 Interrupt
  315. PIN_INT4_IRQHandler ; PIO INT4
  316. PIN_INT5_IRQHandler ; PIO INT5
  317. PIN_INT6_IRQHandler ; PIO INT6
  318. PIN_INT7_IRQHandler ; PIO INT7
  319. RIT_IRQHandler ; RITimer
  320. Reserved41_IRQHandler ; Reserved
  321. Reserved42_IRQHandler ; Reserved
  322. Reserved43_IRQHandler ; Reserved
  323. Reserved44_IRQHandler ; Reserved
  324. Reserved_IRQHandler ; Reserved
  325. B .
  326. ENDP
  327. ALIGN
  328. ; User Initial Stack & Heap
  329. IF :DEF:__MICROLIB
  330. EXPORT __initial_sp
  331. EXPORT __heap_base
  332. EXPORT __heap_limit
  333. ELSE
  334. IMPORT __use_two_region_memory
  335. EXPORT __user_initial_stackheap
  336. __user_initial_stackheap
  337. LDR R0, = Heap_Mem
  338. LDR R1, =(Stack_Mem + Stack_Size)
  339. LDR R2, = (Heap_Mem + Heap_Size)
  340. LDR R3, = Stack_Mem
  341. BX LR
  342. ALIGN
  343. ENDIF
  344. END