keil_startup_lpc5410x-m0.s 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. ;/*
  2. ; * @brief LPC5410x M0 core 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 0x00000000
  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 ; NMI Handler
  54. DCD HardFault_Handler ; Hard Fault Handler
  55. DCD 0
  56. DCD 0
  57. DCD 0
  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 ; SVCall Handler
  64. DCD 0
  65. DCD 0
  66. DCD PendSV_Handler ; PendSV Handler
  67. DCD SysTick_Handler ; 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. ;// <h> Code Read Protection level (CRP)
  102. ;// <o> CRP_Level:
  103. ;// <0xFFFFFFFF=> Disabled
  104. ;// <0x4E697370=> NO_ISP
  105. ;// <0x12345678=> CRP1
  106. ;// <0x87654321=> CRP2
  107. ;// <0x43218765=> CRP3 (Are you sure?)
  108. ;// </h>
  109. CRP_Level EQU 0xFFFFFFFF
  110. IF :LNOT::DEF:NO_CRP
  111. AREA |.ARM.__at_0x02FC|, CODE, READONLY
  112. CRP_Key DCD 0xFFFFFFFF
  113. ENDIF
  114. AREA |.text|, CODE, READONLY
  115. cpu_id EQU 0xE000ED00
  116. cpu_ctrl EQU 0x40000300
  117. coproc_boot EQU 0x40000304
  118. coproc_stack EQU 0x40000308
  119. rel_vals
  120. DCD cpu_id, cpu_ctrl, coproc_boot, coproc_stack
  121. DCW 0xFFF, 0xC24
  122. ; Reset Handler - shared for both cores
  123. Reset_Handler PROC
  124. EXPORT Reset_Handler [WEAK]
  125. EXPORT SystemInit [WEAK]
  126. IMPORT __main
  127. IF :LNOT::DEF:SLAVEBOOT
  128. ; Both the M0+ and M4 core come via this shared startup code,
  129. ; but the M0+ and M4 core have different vector tables.
  130. ; Determine if the core executing this code is the master or
  131. ; the slave and handle each core state individually.
  132. shared_boot_entry
  133. LDR r6, =rel_vals
  134. MOVS r4, #0 ; Flag for slave core (0)
  135. MOVS r5, #1
  136. ; Determine which core (M0+ or M4) this code is running on
  137. ; r2 = (((*cpu_id) >> 4) & 0xFFF); (M4 core == 0xC24)
  138. get_current_core_id
  139. LDR r0, [r6, #0]
  140. LDR r1, [r0] ; r1 = CPU ID status
  141. LSRS r1, r1, #4 ; Right justify 12 CPU ID bits
  142. LDRH r2, [r6, #16] ; Mask for CPU ID bits
  143. ANDS r2, r1, r2 ; r2 = ARM COrtex CPU ID
  144. LDRH r3, [r6, #18] ; Mask for CPU ID bits
  145. CMP r3, r2 ; Core ID matches M4 identifier
  146. BNE get_master_status
  147. MOV r4, r5 ; Set flag for master core (1)
  148. ; Determine if M4 core is the master or slave
  149. ; r3 = ((*cpu_ctrl) & 1); (0 == m0+, 1 == M4)
  150. get_master_status
  151. LDR r0, [r6, #4]
  152. LDR r3, [r0] ; r3 = SYSCON co-processor CPU control status
  153. ANDS r3, r3, r5 ; r3 = (Bit 0: 1 = M4 is master, 0 = M4 is slave)
  154. ; Select boot based on selected master core and core ID
  155. select_boot
  156. EORS r3, r3, r4 ; r4 = (Bit 0: 0 = master, 1 = slave)
  157. BNE slave_boot
  158. B normal_boot
  159. ; Slave boot
  160. slave_boot
  161. LDR r0, [r6, #8]
  162. LDR r2, [r0] ; r1 = SYSCON co-processor boot address
  163. CMP r2, #0 ; Slave boot address = 0 (not set up)?
  164. BEQ cpu_sleep
  165. LDR r0, [r6, #12]
  166. LDR r1, [r0] ; r5 = SYSCON co-processor stack address
  167. MOV sp, r1 ; Update slave CPU stack pointer
  168. ; Be sure to update VTOR for the slave MCU to point to the
  169. ; slave vector table in boot memory
  170. BX r2 ; Jump to slave boot address
  171. ; Slave isn't yet setup for system boot from the master
  172. ; so sleep until the master sets it up and then reboots it
  173. cpu_sleep
  174. MOV sp, r5 ; Will force exception if something happens
  175. cpu_sleep_wfi
  176. WFI ; Sleep forever until master reboots
  177. B cpu_sleep_wfi
  178. ENDIF
  179. ; Normal boot for master/slave
  180. normal_boot
  181. LDR r0, =SystemInit
  182. BLX r0
  183. LDR r0, =__main
  184. BX r0
  185. ENDP
  186. ; For cores with SystemInit() or __main(), the code will sleep the MCU
  187. SystemInit PROC
  188. EXPORT SystemInit [WEAK]
  189. BX lr
  190. ENDP
  191. ; Dummy Exception Handlers (infinite loops which can be modified)
  192. NMI_Handler PROC
  193. EXPORT NMI_Handler [WEAK]
  194. B .
  195. ENDP
  196. HardFault_Handler\
  197. PROC
  198. EXPORT HardFault_Handler [WEAK]
  199. B .
  200. ENDP
  201. SVC_Handler PROC
  202. EXPORT SVC_Handler [WEAK]
  203. B .
  204. ENDP
  205. PendSV_Handler PROC
  206. EXPORT PendSV_Handler [WEAK]
  207. B .
  208. ENDP
  209. SysTick_Handler PROC
  210. EXPORT SysTick_Handler [WEAK]
  211. B .
  212. ENDP
  213. Default_Handler PROC
  214. EXPORT WDT_IRQHandler [WEAK] ; Watchdog
  215. EXPORT BOD_IRQHandler [WEAK] ; Brown Out Detect
  216. EXPORT DMA_IRQHandler [WEAK] ; DMA Controller
  217. EXPORT GINT0_IRQHandler [WEAK] ; GPIO Group0 Interrupt
  218. EXPORT PIN_INT0_IRQHandler [WEAK] ; PIO INT0
  219. EXPORT PIN_INT1_IRQHandler [WEAK] ; PIO INT1
  220. EXPORT PIN_INT2_IRQHandler [WEAK] ; PIO INT2
  221. EXPORT PIN_INT3_IRQHandler [WEAK] ; PIO INT3
  222. EXPORT UTICK_IRQHandler [WEAK] ; UTICK timer
  223. EXPORT MRT_IRQHandler [WEAK] ; Multi-Rate Timer
  224. EXPORT CT32B0_IRQHandler [WEAK] ; CT32B0
  225. EXPORT CT32B1_IRQHandler [WEAK] ; CT32B1
  226. EXPORT CT32B2_IRQHandler [WEAK] ; CT32B2
  227. EXPORT CT32B3_IRQHandler [WEAK] ; CT32B3
  228. EXPORT CT32B4_IRQHandler [WEAK] ; CT32B4
  229. EXPORT UART0_IRQHandler [WEAK] ; UART0
  230. EXPORT SCT0_IRQHandler [WEAK] ; Smart Counter Timer
  231. EXPORT UART1_IRQHandler [WEAK] ; UART1
  232. EXPORT UART2_IRQHandler [WEAK] ; UART2
  233. EXPORT UART3_IRQHandler [WEAK] ; UART3
  234. EXPORT I2C0_IRQHandler [WEAK] ; I2C0 controller
  235. EXPORT I2C1_IRQHandler [WEAK] ; I2C1 controller
  236. EXPORT I2C2_IRQHandler [WEAK] ; I2C2 controller
  237. EXPORT SPI0_IRQHandler [WEAK] ; SPI0 controller
  238. EXPORT SPI1_IRQHandler [WEAK] ; SPI1 controller
  239. EXPORT ADC_SEQA_IRQHandler [WEAK] ; ADC0 A sequence (A/D Converter) interrupt
  240. EXPORT ADC_SEQB_IRQHandler [WEAK] ; ADC0 B sequence (A/D Converter) interrupt
  241. EXPORT ADC_THCMP_IRQHandler [WEAK] ; ADC THCMP and OVERRUN ORed
  242. EXPORT RTC_IRQHandler [WEAK] ; RTC Timer
  243. EXPORT MAILBOX_IRQHandler [WEAK] ; Mailbox
  244. EXPORT Reserved_IRQHandler [WEAK] ; Reserved
  245. WDT_IRQHandler ; Watchdog
  246. BOD_IRQHandler ; Brown Out Detect
  247. DMA_IRQHandler ; DMA Controller
  248. GINT0_IRQHandler ; GPIO Group0 Interrupt
  249. PIN_INT0_IRQHandler ; PIO INT0
  250. PIN_INT1_IRQHandler ; PIO INT1
  251. PIN_INT2_IRQHandler ; PIO INT2
  252. PIN_INT3_IRQHandler ; PIO INT3
  253. UTICK_IRQHandler ; UTICK timer
  254. MRT_IRQHandler ; Multi-Rate Timer
  255. CT32B0_IRQHandler ; CT32B0
  256. CT32B1_IRQHandler ; CT32B1
  257. CT32B2_IRQHandler ; CT32B2
  258. CT32B3_IRQHandler ; CT32B3
  259. CT32B4_IRQHandler ; CT32B4
  260. UART0_IRQHandler ; UART0
  261. SCT0_IRQHandler ; Smart Counter Timer
  262. UART1_IRQHandler ; UART1
  263. UART2_IRQHandler ; UART2
  264. UART3_IRQHandler ; UART3
  265. I2C0_IRQHandler ; I2C0 controller
  266. I2C1_IRQHandler ; I2C1 controller
  267. I2C2_IRQHandler ; I2C2 controller
  268. SPI0_IRQHandler ; SPI0 controller
  269. SPI1_IRQHandler ; SPI1 controller
  270. ADC_SEQA_IRQHandler ; ADC0 A sequence (A/D Converter) interrupt
  271. ADC_SEQB_IRQHandler ; ADC0 B sequence (A/D Converter) interrupt
  272. ADC_THCMP_IRQHandler ; ADC THCMP and OVERRUN ORed
  273. RTC_IRQHandler ; RTC Timer
  274. MAILBOX_IRQHandler ; Mailbox
  275. Reserved_IRQHandler ; Reserved
  276. B .
  277. ENDP
  278. ALIGN
  279. ; User Initial Stack & Heap
  280. IF :DEF:__MICROLIB
  281. EXPORT __initial_sp
  282. EXPORT __heap_base
  283. EXPORT __heap_limit
  284. ELSE
  285. IMPORT __use_two_region_memory
  286. EXPORT __user_initial_stackheap
  287. __user_initial_stackheap
  288. LDR R0, = Heap_Mem
  289. LDR R1, =(Stack_Mem + Stack_Size)
  290. LDR R2, = (Heap_Mem + Heap_Size)
  291. LDR R3, = Stack_Mem
  292. BX LR
  293. ALIGN
  294. ENDIF
  295. END