iar_startup_lpc5410x-m0.s 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. ;/*****************************************************************************
  2. ; * @file: startup_LPC5410x-m0.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 0
  54. DCD 0
  55. DCD 0
  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 0
  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. __Vectors_End
  100. __Vectors EQU __vector_table
  101. __Vectors_Size EQU __Vectors_End - __Vectors
  102. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  103. ;;
  104. ;; Default interrupt handlers.
  105. ;;
  106. #if !defined(SLAVEBOOT)
  107. DATA
  108. cpu_id EQU 0xE000ED00
  109. cpu_ctrl EQU 0x40000300
  110. coproc_boot EQU 0x40000304
  111. coproc_stack EQU 0x40000308
  112. rel_vals
  113. DC32 cpu_id, cpu_ctrl, coproc_boot, coproc_stack
  114. DC16 0xFFF, 0xC24
  115. #endif
  116. THUMB
  117. PUBWEAK Reset_Handler
  118. SECTION .text:CODE:REORDER:NOROOT(2)
  119. ; Reset Handler - shared for both cores
  120. Reset_Handler
  121. #if !defined(SLAVEBOOT)
  122. ; Both the M0+ and M4 core come via this shared startup code,
  123. ; but the M0+ and M4 core have different vector tables.
  124. ; Determine if the core executing this code is the master or
  125. ; the slave and handle each core state individually.
  126. shared_boot_entry
  127. LDR r6, =rel_vals
  128. MOVS r4, #0 ; Flag for slave core (0)
  129. MOVS r5, #1
  130. ; Determine which core (M0+ or M4) this code is running on
  131. ; r2 = (((*cpu_id) >> 4) & 0xFFF); (M4 core == 0xC24)
  132. get_current_core_id
  133. LDR r0, [r6, #0]
  134. LDR r1, [r0] ; r1 = CPU ID status
  135. LSRS r1, r1, #4 ; Right justify 12 CPU ID bits
  136. LDRH r2, [r6, #16] ; Mask for CPU ID bits
  137. ANDS r2, r1, r2 ; r2 = ARM COrtex CPU ID
  138. LDRH r3, [r6, #18] ; Mask for CPU ID bits
  139. CMP r3, r2 ; Core ID matches M4 identifier
  140. BNE get_master_status
  141. MOV r4, r5 ; Set flag for master core (1)
  142. ; Determine if M4 core is the master or slave
  143. ; r3 = ((*cpu_ctrl) & 1); (0 == m0+, 1 == M4)
  144. get_master_status
  145. LDR r0, [r6, #4]
  146. LDR r3, [r0] ; r3 = SYSCON co-processor CPU control status
  147. ANDS r3, r3, r5 ; r3 = (Bit 0: 1 = M4 is master, 0 = M4 is slave)
  148. ; Select boot based on selected master core and core ID
  149. select_boot
  150. EORS r3, r3, r4 ; r4 = (Bit 0: 0 = master, 1 = slave)
  151. BNE slave_boot
  152. B normal_boot
  153. ; Slave boot
  154. slave_boot
  155. LDR r0, [r6, #8]
  156. LDR r2, [r0] ; r1 = SYSCON co-processor boot address
  157. CMP r2, #0 ; Slave boot address = 0 (not set up)?
  158. BEQ cpu_sleep
  159. LDR r0, [r6, #12]
  160. LDR r1, [r0] ; r5 = SYSCON co-processor stack address
  161. MOV sp, r1 ; Update slave CPU stack pointer
  162. ; Be sure to update VTOR for the slave MCU to point to the
  163. ; slave vector table in boot memory
  164. BX r2 ; Jump to slave boot address
  165. ; Slave isn't yet setup for system boot from the master
  166. ; so sleep until the master sets it up and then reboots it
  167. cpu_sleep
  168. MOV sp, r5 ; Will force exception if something happens
  169. cpu_sleep_wfi
  170. WFI ; Sleep forever until master reboots
  171. B cpu_sleep_wfi
  172. #endif ; defined(SLAVEBOOT)
  173. ; Normal boot for master/slave
  174. normal_boot
  175. LDR r0, =SystemInit
  176. BLX r0
  177. LDR r0, =__iar_program_start
  178. BX r0
  179. ; For cores with SystemInit() or __iar_program_start(), the code will sleep the MCU
  180. PUBWEAK SystemInit
  181. SECTION .text:CODE:REORDER:NOROOT(1)
  182. SystemInit
  183. BX LR
  184. PUBWEAK NMI_Handler
  185. SECTION .text:CODE:REORDER:NOROOT(1)
  186. NMI_Handler
  187. B .
  188. PUBWEAK HardFault_Handler
  189. SECTION .text:CODE:REORDER:NOROOT(1)
  190. HardFault_Handler
  191. B .
  192. PUBWEAK SVC_Handler
  193. SECTION .text:CODE:REORDER:NOROOT(1)
  194. SVC_Handler
  195. B .
  196. PUBWEAK PendSV_Handler
  197. SECTION .text:CODE:REORDER:NOROOT(1)
  198. PendSV_Handler
  199. B .
  200. PUBWEAK SysTick_Handler
  201. SECTION .text:CODE:REORDER:NOROOT(1)
  202. SysTick_Handler
  203. B .
  204. PUBWEAK Reserved_IRQHandler
  205. SECTION .text:CODE:REORDER:NOROOT(1)
  206. Reserved_IRQHandler
  207. B .
  208. PUBWEAK WDT_IRQHandler ; Watchdog
  209. PUBWEAK BOD_IRQHandler ; Brown Out Detect
  210. PUBWEAK DMA_IRQHandler ; DMA Controller
  211. PUBWEAK GINT0_IRQHandler ; GPIO Group0 Interrupt
  212. PUBWEAK PIN_INT0_IRQHandler ; PIO INT0
  213. PUBWEAK PIN_INT1_IRQHandler ; PIO INT1
  214. PUBWEAK PIN_INT2_IRQHandler ; PIO INT2
  215. PUBWEAK PIN_INT3_IRQHandler ; PIO INT3
  216. PUBWEAK UTICK_IRQHandler ; UTICK timer
  217. PUBWEAK MRT_IRQHandler ; Multi-Rate Timer
  218. PUBWEAK CT32B0_IRQHandler ; CT32B0
  219. PUBWEAK CT32B1_IRQHandler ; CT32B1
  220. PUBWEAK CT32B2_IRQHandler ; CT32B2
  221. PUBWEAK CT32B3_IRQHandler ; CT32B3
  222. PUBWEAK CT32B4_IRQHandler ; CT32B4
  223. PUBWEAK UART0_IRQHandler ; UART0
  224. PUBWEAK SCT0_IRQHandler ; Smart Counter Timer
  225. PUBWEAK UART1_IRQHandler ; UART1
  226. PUBWEAK UART2_IRQHandler ; UART2
  227. PUBWEAK UART3_IRQHandler ; UART3
  228. PUBWEAK I2C0_IRQHandler ; I2C0 controller
  229. PUBWEAK I2C1_IRQHandler ; I2C1 controller
  230. PUBWEAK I2C2_IRQHandler ; I2C2 controller
  231. PUBWEAK SPI0_IRQHandler ; SPI0 controller
  232. PUBWEAK SPI1_IRQHandler ; SPI1 controller
  233. PUBWEAK ADC_SEQA_IRQHandler ; ADC0 A sequence (A/D Converter) interrupt
  234. PUBWEAK ADC_SEQB_IRQHandler ; ADC0 B sequence (A/D Converter) interrupt
  235. PUBWEAK ADC_THCMP_IRQHandler ; ADC THCMP and OVERRUN ORed
  236. PUBWEAK RTC_IRQHandler ; RTC Timer
  237. PUBWEAK MAILBOX_IRQHandler ; Mailbox
  238. WDT_IRQHandler ; Watchdog
  239. BOD_IRQHandler ; Brown Out Detect
  240. DMA_IRQHandler ; DMA Controller
  241. GINT0_IRQHandler ; GPIO Group0 Interrupt
  242. PIN_INT0_IRQHandler ; PIO INT0
  243. PIN_INT1_IRQHandler ; PIO INT1
  244. PIN_INT2_IRQHandler ; PIO INT2
  245. PIN_INT3_IRQHandler ; PIO INT3
  246. UTICK_IRQHandler ; UTICK timer
  247. MRT_IRQHandler ; Multi-Rate Timer
  248. CT32B0_IRQHandler ; CT32B0
  249. CT32B1_IRQHandler ; CT32B1
  250. CT32B2_IRQHandler ; CT32B2
  251. CT32B3_IRQHandler ; CT32B3
  252. CT32B4_IRQHandler ; CT32B4
  253. UART0_IRQHandler ; UART0
  254. SCT0_IRQHandler ; Smart Counter Timer
  255. UART1_IRQHandler ; UART1
  256. UART2_IRQHandler ; UART2
  257. UART3_IRQHandler ; UART3
  258. I2C0_IRQHandler ; I2C0 controller
  259. I2C1_IRQHandler ; I2C1 controller
  260. I2C2_IRQHandler ; I2C2 controller
  261. SPI0_IRQHandler ; SPI0 controller
  262. SPI1_IRQHandler ; SPI1 controller
  263. ADC_SEQA_IRQHandler ; ADC0 A sequence (A/D Converter) interrupt
  264. ADC_SEQB_IRQHandler ; ADC0 B sequence (A/D Converter) interrupt
  265. ADC_THCMP_IRQHandler ; ADC THCMP and OVERRUN ORed
  266. RTC_IRQHandler ; RTC Timer
  267. MAILBOX_IRQHandler ; Mailbox
  268. Default_Handler:
  269. B .
  270. END