startup_MK64F12.S 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. /* K64F startup ARM GCC
  2. * Purpose: startup file for Cortex-M4 devices. Should use with
  3. * GCC for ARM Embedded Processors
  4. * Version: V1.2
  5. * Date: 15 Nov 2011
  6. *
  7. * Copyright (c) 2011, ARM Limited
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions are met:
  12. * Redistributions of source code must retain the above copyright
  13. notice, this list of conditions and the following disclaimer.
  14. * Redistributions in binary form must reproduce the above copyright
  15. notice, this list of conditions and the following disclaimer in the
  16. documentation and/or other materials provided with the distribution.
  17. * Neither the name of the ARM Limited nor the
  18. names of its contributors may be used to endorse or promote products
  19. derived from this software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  22. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  23. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  24. * DISCLAIMED. IN NO EVENT SHALL ARM LIMITED BE LIABLE FOR ANY
  25. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  26. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  27. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  28. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  30. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. */
  32. .syntax unified
  33. .arch armv7-m
  34. /* Memory Model
  35. The HEAP starts at the end of the DATA section and grows upward.
  36. The STACK starts at the end of the RAM and grows downward.
  37. The HEAP and stack STACK are only checked at compile time:
  38. (DATA_SIZE + HEAP_SIZE + STACK_SIZE) < RAM_SIZE
  39. This is just a check for the bare minimum for the Heap+Stack area before
  40. aborting compilation, it is not the run time limit:
  41. Heap_Size + Stack_Size = 0x80 + 0x80 = 0x100
  42. */
  43. .section .stack
  44. .align 3
  45. #ifdef __STACK_SIZE
  46. .equ Stack_Size, __STACK_SIZE
  47. #else
  48. .equ Stack_Size, 0xC00
  49. #endif
  50. .globl __StackTop
  51. .globl __StackLimit
  52. __StackLimit:
  53. .space Stack_Size
  54. .size __StackLimit, . - __StackLimit
  55. __StackTop:
  56. .size __StackTop, . - __StackTop
  57. .section .heap
  58. .align 3
  59. #ifdef __HEAP_SIZE
  60. .equ Heap_Size, __HEAP_SIZE
  61. #else
  62. .equ Heap_Size, 0x400
  63. #endif
  64. .globl __HeapBase
  65. .globl __HeapLimit
  66. __HeapBase:
  67. .space Heap_Size
  68. .size __HeapBase, . - __HeapBase
  69. __HeapLimit:
  70. .size __HeapLimit, . - __HeapLimit
  71. .section .vector_table,"a",%progbits
  72. .align 2
  73. .globl __isr_vector
  74. __isr_vector:
  75. .long __StackTop /* Top of Stack */
  76. .long Reset_Handler /* Reset Handler */
  77. .long NMI_Handler /* NMI Handler */
  78. .long HardFault_Handler /* Hard Fault Handler */
  79. .long MemManage_Handler /* MPU Fault Handler */
  80. .long BusFault_Handler /* Bus Fault Handler */
  81. .long UsageFault_Handler /* Usage Fault Handler */
  82. .long 0 /* Reserved */
  83. .long 0 /* Reserved */
  84. .long 0 /* Reserved */
  85. .long 0 /* Reserved */
  86. .long SVC_Handler /* SVCall Handler */
  87. .long DebugMon_Handler /* Debug Monitor Handler */
  88. .long 0 /* Reserved */
  89. .long PendSV_Handler /* PendSV Handler */
  90. .long SysTick_Handler /* SysTick Handler */
  91. /* External Interrupts */
  92. .long DMA0_IRQHandler /* DMA Channel 0 Transfer Complete */
  93. .long DMA1_IRQHandler /* DMA Channel 1 Transfer Complete */
  94. .long DMA2_IRQHandler /* DMA Channel 2 Transfer Complete */
  95. .long DMA3_IRQHandler /* DMA Channel 3 Transfer Complete */
  96. .long DMA4_IRQHandler /* DMA Channel 4 Transfer Complete */
  97. .long DMA5_IRQHandler /* DMA Channel 5 Transfer Complete */
  98. .long DMA6_IRQHandler /* DMA Channel 6 Transfer Complete */
  99. .long DMA7_IRQHandler /* DMA Channel 7 Transfer Complete */
  100. .long DMA8_IRQHandler /* DMA Channel 8 Transfer Complete */
  101. .long DMA9_IRQHandler /* DMA Channel 9 Transfer Complete */
  102. .long DMA10_IRQHandler /* DMA Channel 10 Transfer Complete */
  103. .long DMA11_IRQHandler /* DMA Channel 11 Transfer Complete */
  104. .long DMA12_IRQHandler /* DMA Channel 12 Transfer Complete */
  105. .long DMA13_IRQHandler /* DMA Channel 13 Transfer Complete */
  106. .long DMA14_IRQHandler /* DMA Channel 14 Transfer Complete */
  107. .long DMA15_IRQHandler /* DMA Channel 15 Transfer Complete */
  108. .long DMA_Error_IRQHandler /* DMA Error Interrupt */
  109. .long MCM_IRQHandler /* Normal Interrupt */
  110. .long FTFE_IRQHandler /* FTFE Command complete interrupt */
  111. .long Read_Collision_IRQHandler /* Read Collision Interrupt */
  112. .long LVD_LVW_IRQHandler /* Low Voltage Detect, Low Voltage Warning */
  113. .long LLW_IRQHandler /* Low Leakage Wakeup */
  114. .long Watchdog_IRQHandler /* WDOG Interrupt */
  115. .long RNG_IRQHandler /* RNG Interrupt */
  116. .long I2C0_IRQHandler /* I2C0 interrupt */
  117. .long I2C1_IRQHandler /* I2C1 interrupt */
  118. .long SPI0_IRQHandler /* SPI0 Interrupt */
  119. .long SPI1_IRQHandler /* SPI1 Interrupt */
  120. .long I2S0_Tx_IRQHandler /* I2S0 transmit interrupt */
  121. .long I2S0_Rx_IRQHandler /* I2S0 receive interrupt */
  122. .long UART0_LON_IRQHandler /* UART0 LON interrupt */
  123. .long UART0_RX_TX_IRQHandler /* UART0 Receive/Transmit interrupt */
  124. .long UART0_ERR_IRQHandler /* UART0 Error interrupt */
  125. .long UART1_RX_TX_IRQHandler /* UART1 Receive/Transmit interrupt */
  126. .long UART1_ERR_IRQHandler /* UART1 Error interrupt */
  127. .long UART2_RX_TX_IRQHandler /* UART2 Receive/Transmit interrupt */
  128. .long UART2_ERR_IRQHandler /* UART2 Error interrupt */
  129. .long UART3_RX_TX_IRQHandler /* UART3 Receive/Transmit interrupt */
  130. .long UART3_ERR_IRQHandler /* UART3 Error interrupt */
  131. .long ADC0_IRQHandler /* ADC0 interrupt */
  132. .long CMP0_IRQHandler /* CMP0 interrupt */
  133. .long CMP1_IRQHandler /* CMP1 interrupt */
  134. .long FTM0_IRQHandler /* FTM0 fault, overflow and channels interrupt */
  135. .long FTM1_IRQHandler /* FTM1 fault, overflow and channels interrupt */
  136. .long FTM2_IRQHandler /* FTM2 fault, overflow and channels interrupt */
  137. .long CMT_IRQHandler /* CMT interrupt */
  138. .long RTC_IRQHandler /* RTC interrupt */
  139. .long RTC_Seconds_IRQHandler /* RTC seconds interrupt */
  140. .long PIT0_IRQHandler /* PIT timer channel 0 interrupt */
  141. .long PIT1_IRQHandler /* PIT timer channel 1 interrupt */
  142. .long PIT2_IRQHandler /* PIT timer channel 2 interrupt */
  143. .long PIT3_IRQHandler /* PIT timer channel 3 interrupt */
  144. .long PDB0_IRQHandler /* PDB0 Interrupt */
  145. .long USB0_IRQHandler /* USB0 interrupt */
  146. .long USBDCD_IRQHandler /* USBDCD Interrupt */
  147. .long Reserved71_IRQHandler /* Reserved interrupt 71 */
  148. .long DAC0_IRQHandler /* DAC0 interrupt */
  149. .long MCG_IRQHandler /* MCG Interrupt */
  150. .long LPTimer_IRQHandler /* LPTimer interrupt */
  151. .long PORTA_IRQHandler /* Port A interrupt */
  152. .long PORTB_IRQHandler /* Port B interrupt */
  153. .long PORTC_IRQHandler /* Port C interrupt */
  154. .long PORTD_IRQHandler /* Port D interrupt */
  155. .long PORTE_IRQHandler /* Port E interrupt */
  156. .long SWI_IRQHandler /* Software interrupt */
  157. .long SPI2_IRQHandler /* SPI2 Interrupt */
  158. .long UART4_RX_TX_IRQHandler /* UART4 Receive/Transmit interrupt */
  159. .long UART4_ERR_IRQHandler /* UART4 Error interrupt */
  160. .long UART5_RX_TX_IRQHandler /* UART5 Receive/Transmit interrupt */
  161. .long UART5_ERR_IRQHandler /* UART5 Error interrupt */
  162. .long CMP2_IRQHandler /* CMP2 interrupt */
  163. .long FTM3_IRQHandler /* FTM3 fault, overflow and channels interrupt */
  164. .long DAC1_IRQHandler /* DAC1 interrupt */
  165. .long ADC1_IRQHandler /* ADC1 interrupt */
  166. .long I2C2_IRQHandler /* I2C2 interrupt */
  167. .long CAN0_ORed_Message_buffer_IRQHandler /* CAN0 OR'd message buffers interrupt */
  168. .long CAN0_Bus_Off_IRQHandler /* CAN0 bus off interrupt */
  169. .long CAN0_Error_IRQHandler /* CAN0 error interrupt */
  170. .long CAN0_Tx_Warning_IRQHandler /* CAN0 Tx warning interrupt */
  171. .long CAN0_Rx_Warning_IRQHandler /* CAN0 Rx warning interrupt */
  172. .long CAN0_Wake_Up_IRQHandler /* CAN0 wake up interrupt */
  173. .long SDHC_IRQHandler /* SDHC interrupt */
  174. .long ENET_1588_Timer_IRQHandler /* Ethernet MAC IEEE 1588 Timer Interrupt */
  175. .long ENET_Transmit_IRQHandler /* Ethernet MAC Transmit Interrupt */
  176. .long ENET_Receive_IRQHandler /* Ethernet MAC Receive Interrupt */
  177. .long ENET_Error_IRQHandler /* Ethernet MAC Error and miscelaneous Interrupt */
  178. .size __isr_vector, . - __isr_vector
  179. .section .text.Reset_Handler
  180. .thumb
  181. .thumb_func
  182. .align 2
  183. .globl Reset_Handler
  184. .type Reset_Handler, %function
  185. Reset_Handler:
  186. /* Loop to copy data from read only memory to RAM. The ranges
  187. * of copy from/to are specified by following symbols evaluated in
  188. * linker script.
  189. * __etext: End of code section, i.e., begin of data sections to copy from.
  190. * __data_start__/__data_end__: RAM address range that data should be
  191. * copied to. Both must be aligned to 4 bytes boundary. */
  192. disable_watchdog:
  193. /* unlock */
  194. ldr r1, =0x4005200e
  195. ldr r0, =0xc520
  196. strh r0, [r1]
  197. ldr r0, =0xd928
  198. strh r0, [r1]
  199. /* disable */
  200. ldr r1, =0x40052000
  201. ldr r0, =0x01d2
  202. strh r0, [r1]
  203. ldr r1, =__etext
  204. ldr r2, =__data_start__
  205. ldr r3, =__data_end__
  206. subs r3, r2
  207. ble .Lflash_to_ram_loop_end
  208. movs r4, 0
  209. .Lflash_to_ram_loop:
  210. ldr r0, [r1,r4]
  211. str r0, [r2,r4]
  212. adds r4, 4
  213. cmp r4, r3
  214. blt .Lflash_to_ram_loop
  215. .Lflash_to_ram_loop_end:
  216. ldr r0, =SystemInit
  217. blx r0
  218. ldr r0, =init_data_bss
  219. blx r0
  220. ldr r0, =main
  221. bx r0
  222. .pool
  223. .size Reset_Handler, . - Reset_Handler
  224. .text
  225. /* Macro to define default handlers. Default handler
  226. * will be weak symbol and just dead loops. They can be
  227. * overwritten by other handlers */
  228. .macro def_default_handler handler_name
  229. .align 1
  230. .thumb_func
  231. .weak \handler_name
  232. .type \handler_name, %function
  233. \handler_name :
  234. b .
  235. .size \handler_name, . - \handler_name
  236. .endm
  237. /* Exception Handlers */
  238. def_default_handler NMI_Handler
  239. def_default_handler HardFault_Handler
  240. def_default_handler MemManage_Handler
  241. def_default_handler BusFault_Handler
  242. def_default_handler UsageFault_Handler
  243. def_default_handler SVC_Handler
  244. def_default_handler DebugMon_Handler
  245. def_default_handler PendSV_Handler
  246. def_default_handler SysTick_Handler
  247. def_default_handler Default_Handler
  248. .macro def_irq_default_handler handler_name
  249. .weak \handler_name
  250. .set \handler_name, Default_Handler
  251. .endm
  252. /* IRQ Handlers */
  253. def_irq_default_handler DMA0_IRQHandler
  254. def_irq_default_handler DMA1_IRQHandler
  255. def_irq_default_handler DMA2_IRQHandler
  256. def_irq_default_handler DMA3_IRQHandler
  257. def_irq_default_handler DMA4_IRQHandler
  258. def_irq_default_handler DMA5_IRQHandler
  259. def_irq_default_handler DMA6_IRQHandler
  260. def_irq_default_handler DMA7_IRQHandler
  261. def_irq_default_handler DMA8_IRQHandler
  262. def_irq_default_handler DMA9_IRQHandler
  263. def_irq_default_handler DMA10_IRQHandler
  264. def_irq_default_handler DMA11_IRQHandler
  265. def_irq_default_handler DMA12_IRQHandler
  266. def_irq_default_handler DMA13_IRQHandler
  267. def_irq_default_handler DMA14_IRQHandler
  268. def_irq_default_handler DMA15_IRQHandler
  269. def_irq_default_handler DMA_Error_IRQHandler
  270. def_irq_default_handler MCM_IRQHandler
  271. def_irq_default_handler FTFE_IRQHandler
  272. def_irq_default_handler Read_Collision_IRQHandler
  273. def_irq_default_handler LVD_LVW_IRQHandler
  274. def_irq_default_handler LLW_IRQHandler
  275. def_irq_default_handler Watchdog_IRQHandler
  276. def_irq_default_handler RNG_IRQHandler
  277. def_irq_default_handler I2C0_IRQHandler
  278. def_irq_default_handler I2C1_IRQHandler
  279. def_irq_default_handler SPI0_IRQHandler
  280. def_irq_default_handler SPI1_IRQHandler
  281. def_irq_default_handler I2S0_Tx_IRQHandler
  282. def_irq_default_handler I2S0_Rx_IRQHandler
  283. def_irq_default_handler UART0_LON_IRQHandler
  284. def_irq_default_handler UART0_RX_TX_IRQHandler
  285. def_irq_default_handler UART0_ERR_IRQHandler
  286. def_irq_default_handler UART1_RX_TX_IRQHandler
  287. def_irq_default_handler UART1_ERR_IRQHandler
  288. def_irq_default_handler UART2_RX_TX_IRQHandler
  289. def_irq_default_handler UART2_ERR_IRQHandler
  290. def_irq_default_handler UART3_RX_TX_IRQHandler
  291. def_irq_default_handler UART3_ERR_IRQHandler
  292. def_irq_default_handler ADC0_IRQHandler
  293. def_irq_default_handler CMP0_IRQHandler
  294. def_irq_default_handler CMP1_IRQHandler
  295. def_irq_default_handler FTM0_IRQHandler
  296. def_irq_default_handler FTM1_IRQHandler
  297. def_irq_default_handler FTM2_IRQHandler
  298. def_irq_default_handler CMT_IRQHandler
  299. def_irq_default_handler RTC_IRQHandler
  300. def_irq_default_handler RTC_Seconds_IRQHandler
  301. def_irq_default_handler PIT0_IRQHandler
  302. def_irq_default_handler PIT1_IRQHandler
  303. def_irq_default_handler PIT2_IRQHandler
  304. def_irq_default_handler PIT3_IRQHandler
  305. def_irq_default_handler PDB0_IRQHandler
  306. def_irq_default_handler USB0_IRQHandler
  307. def_irq_default_handler USBDCD_IRQHandler
  308. def_irq_default_handler Reserved71_IRQHandler
  309. def_irq_default_handler DAC0_IRQHandler
  310. def_irq_default_handler MCG_IRQHandler
  311. def_irq_default_handler LPTimer_IRQHandler
  312. def_irq_default_handler PORTA_IRQHandler
  313. def_irq_default_handler PORTB_IRQHandler
  314. def_irq_default_handler PORTC_IRQHandler
  315. def_irq_default_handler PORTD_IRQHandler
  316. def_irq_default_handler PORTE_IRQHandler
  317. def_irq_default_handler SWI_IRQHandler
  318. def_irq_default_handler SPI2_IRQHandler
  319. def_irq_default_handler UART4_RX_TX_IRQHandler
  320. def_irq_default_handler UART4_ERR_IRQHandler
  321. def_irq_default_handler UART5_RX_TX_IRQHandler
  322. def_irq_default_handler UART5_ERR_IRQHandler
  323. def_irq_default_handler CMP2_IRQHandler
  324. def_irq_default_handler FTM3_IRQHandler
  325. def_irq_default_handler DAC1_IRQHandler
  326. def_irq_default_handler ADC1_IRQHandler
  327. def_irq_default_handler I2C2_IRQHandler
  328. def_irq_default_handler CAN0_ORed_Message_buffer_IRQHandler
  329. def_irq_default_handler CAN0_Bus_Off_IRQHandler
  330. def_irq_default_handler CAN0_Error_IRQHandler
  331. def_irq_default_handler CAN0_Tx_Warning_IRQHandler
  332. def_irq_default_handler CAN0_Rx_Warning_IRQHandler
  333. def_irq_default_handler CAN0_Wake_Up_IRQHandler
  334. def_irq_default_handler SDHC_IRQHandler
  335. def_irq_default_handler ENET_1588_Timer_IRQHandler
  336. def_irq_default_handler ENET_Transmit_IRQHandler
  337. def_irq_default_handler ENET_Receive_IRQHandler
  338. def_irq_default_handler ENET_Error_IRQHandler
  339. def_irq_default_handler DefaultISR
  340. /* Flash protection region, placed at 0x400 */
  341. .text
  342. .thumb
  343. .align 2
  344. .section .kinetis_flash_config_field,"a",%progbits
  345. kinetis_flash_config:
  346. .long 0xffffffff
  347. .long 0xffffffff
  348. .long 0xffffffff
  349. .long 0xfffffffe
  350. .end