startup_sam4l.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. /**
  2. * \file
  3. *
  4. * \brief gcc starttup file for SAM4L
  5. *
  6. * Copyright (c) 2014 Atmel Corporation. All rights reserved.
  7. *
  8. * \asf_license_start
  9. *
  10. * \page License
  11. *
  12. * Redistribution and use in source and binary forms, with or without
  13. * modification, are permitted provided that the following conditions are met:
  14. *
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. *
  18. * 2. Redistributions in binary form must reproduce the above copyright notice,
  19. * this list of conditions and the following disclaimer in the documentation
  20. * and/or other materials provided with the distribution.
  21. *
  22. * 3. The name of Atmel may not be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * 4. This software may only be redistributed and used in connection with an
  26. * Atmel microcontroller product.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
  29. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  30. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  31. * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
  32. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  33. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  34. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  36. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  37. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  38. * POSSIBILITY OF SUCH DAMAGE.
  39. *
  40. * \asf_license_stop
  41. *
  42. */
  43. #include "sam4l.h"
  44. /* Initialize segments */
  45. extern uint32_t _sfixed;
  46. extern uint32_t _efixed;
  47. extern uint32_t _etext;
  48. extern uint32_t _srelocate;
  49. extern uint32_t _erelocate;
  50. extern uint32_t _szero;
  51. extern uint32_t _ezero;
  52. extern uint32_t _sstack;
  53. extern uint32_t _estack;
  54. /** \cond DOXYGEN_SHOULD_SKIP_THIS */
  55. int main(void);
  56. /** \endcond */
  57. void __libc_init_array(void);
  58. /* Default empty handler */
  59. void Dummy_Handler(void);
  60. /* Cortex-M4 core handlers */
  61. void NMI_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  62. void HardFault_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  63. void MemManage_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  64. void BusFault_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  65. void UsageFault_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  66. void SVC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  67. void DebugMon_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  68. void PendSV_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  69. void SysTick_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  70. /* Peripherals handlers */
  71. void HFLASHC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  72. void PDCA_0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  73. void PDCA_1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  74. void PDCA_2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  75. void PDCA_3_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  76. void PDCA_4_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  77. void PDCA_5_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  78. void PDCA_6_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  79. void PDCA_7_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  80. void PDCA_8_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  81. void PDCA_9_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  82. void PDCA_10_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  83. void PDCA_11_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  84. void PDCA_12_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  85. void PDCA_13_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  86. void PDCA_14_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  87. void PDCA_15_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  88. void CRCCU_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  89. #ifdef ID_USBC
  90. void USBC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  91. #endif
  92. void PEVC_TR_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  93. void PEVC_OV_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  94. #ifdef ID_AESA
  95. void AESA_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  96. #endif
  97. void PM_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  98. void SCIF_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  99. void FREQM_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  100. void GPIO_0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  101. void GPIO_1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  102. void GPIO_2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  103. void GPIO_3_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  104. void GPIO_4_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  105. void GPIO_5_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  106. void GPIO_6_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  107. void GPIO_7_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  108. void GPIO_8_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  109. void GPIO_9_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  110. void GPIO_10_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  111. void GPIO_11_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  112. void BPM_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  113. void BSCIF_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  114. void AST_ALARM_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  115. void AST_PER_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  116. void AST_OVF_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  117. void AST_READY_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  118. void AST_CLKREADY_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  119. void WDT_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  120. void EIC_1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  121. void EIC_2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  122. void EIC_3_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  123. void EIC_4_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  124. void EIC_5_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  125. void EIC_6_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  126. void EIC_7_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  127. void EIC_8_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  128. void IISC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  129. void SPI_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  130. void TC00_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  131. void TC01_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  132. void TC02_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  133. void TC10_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  134. void TC11_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  135. void TC12_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  136. void TWIM0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  137. void TWIS0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  138. void TWIM1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  139. void TWIS1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  140. void USART0_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  141. void USART1_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  142. void USART2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  143. void USART3_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  144. void ADCIFE_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  145. void DACC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  146. void ACIFC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  147. void ABDACB_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  148. void TRNG_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  149. void PARC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  150. void CATB_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  151. void PTC_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  152. void TWIM2_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  153. void TWIM3_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  154. #ifdef ID_LCDCA
  155. void LCDCA_Handler ( void ) __attribute__ ((weak, alias("Dummy_Handler")));
  156. #endif
  157. /* Exception Table */
  158. __attribute__ ((section(".vectors")))
  159. const DeviceVectors exception_table = {
  160. /* Configure Initial Stack Pointer, using linker-generated symbols */
  161. (void*) (&_estack),
  162. (void*) Reset_Handler,
  163. (void*) NMI_Handler,
  164. (void*) HardFault_Handler,
  165. (void*) MemManage_Handler,
  166. (void*) BusFault_Handler,
  167. (void*) UsageFault_Handler,
  168. (void*) (0UL), /* Reserved */
  169. (void*) (0UL), /* Reserved */
  170. (void*) (0UL), /* Reserved */
  171. (void*) (0UL), /* Reserved */
  172. (void*) SVC_Handler,
  173. (void*) DebugMon_Handler,
  174. (void*) (0UL), /* Reserved */
  175. (void*) PendSV_Handler,
  176. (void*) SysTick_Handler,
  177. /* Configurable interrupts */
  178. (void*) HFLASHC_Handler, /* 0 Flash Controller */
  179. (void*) PDCA_0_Handler, /* 1 Peripheral DMA Controller */
  180. (void*) PDCA_1_Handler, /* 2 Peripheral DMA Controller */
  181. (void*) PDCA_2_Handler, /* 3 Peripheral DMA Controller */
  182. (void*) PDCA_3_Handler, /* 4 Peripheral DMA Controller */
  183. (void*) PDCA_4_Handler, /* 5 Peripheral DMA Controller */
  184. (void*) PDCA_5_Handler, /* 6 Peripheral DMA Controller */
  185. (void*) PDCA_6_Handler, /* 7 Peripheral DMA Controller */
  186. (void*) PDCA_7_Handler, /* 8 Peripheral DMA Controller */
  187. (void*) PDCA_8_Handler, /* 9 Peripheral DMA Controller */
  188. (void*) PDCA_9_Handler, /* 10 Peripheral DMA Controller */
  189. (void*) PDCA_10_Handler, /* 11 Peripheral DMA Controller */
  190. (void*) PDCA_11_Handler, /* 12 Peripheral DMA Controller */
  191. (void*) PDCA_12_Handler, /* 13 Peripheral DMA Controller */
  192. (void*) PDCA_13_Handler, /* 14 Peripheral DMA Controller */
  193. (void*) PDCA_14_Handler, /* 15 Peripheral DMA Controller */
  194. (void*) PDCA_15_Handler, /* 16 Peripheral DMA Controller */
  195. (void*) CRCCU_Handler, /* 17 CRC Calculation Unit */
  196. #ifdef ID_USBC
  197. (void*) USBC_Handler, /* 18 USB 2.0 Interface */
  198. #else
  199. (void*) (0UL), /* Reserved */
  200. #endif
  201. (void*) PEVC_TR_Handler, /* 19 Peripheral Event Controller */
  202. (void*) PEVC_OV_Handler, /* 20 Peripheral Event Controller */
  203. #ifdef ID_AESA
  204. (void*) AESA_Handler, /* 21 Advanced Encryption Standard */
  205. #else
  206. (void*) (0UL), /* Reserved */
  207. #endif
  208. (void*) PM_Handler, /* 22 Power Manager */
  209. (void*) SCIF_Handler, /* 23 System Control Interface */
  210. (void*) FREQM_Handler, /* 24 Frequency Meter */
  211. (void*) GPIO_0_Handler, /* 25 General-Purpose Input/Output Controller */
  212. (void*) GPIO_1_Handler, /* 26 General-Purpose Input/Output Controller */
  213. (void*) GPIO_2_Handler, /* 27 General-Purpose Input/Output Controller */
  214. (void*) GPIO_3_Handler, /* 28 General-Purpose Input/Output Controller */
  215. (void*) GPIO_4_Handler, /* 29 General-Purpose Input/Output Controller */
  216. (void*) GPIO_5_Handler, /* 30 General-Purpose Input/Output Controller */
  217. (void*) GPIO_6_Handler, /* 31 General-Purpose Input/Output Controller */
  218. (void*) GPIO_7_Handler, /* 32 General-Purpose Input/Output Controller */
  219. (void*) GPIO_8_Handler, /* 33 General-Purpose Input/Output Controller */
  220. (void*) GPIO_9_Handler, /* 34 General-Purpose Input/Output Controller */
  221. (void*) GPIO_10_Handler, /* 35 General-Purpose Input/Output Controller */
  222. (void*) GPIO_11_Handler, /* 36 General-Purpose Input/Output Controller */
  223. (void*) BPM_Handler, /* 37 Backup Power Manager */
  224. (void*) BSCIF_Handler, /* 38 Backup System Control Interface */
  225. (void*) AST_ALARM_Handler, /* 39 Asynchronous Timer */
  226. (void*) AST_PER_Handler, /* 40 Asynchronous Timer */
  227. (void*) AST_OVF_Handler, /* 41 Asynchronous Timer */
  228. (void*) AST_READY_Handler, /* 42 Asynchronous Timer */
  229. (void*) AST_CLKREADY_Handler, /* 43 Asynchronous Timer */
  230. (void*) WDT_Handler, /* 44 Watchdog Timer */
  231. (void*) EIC_1_Handler, /* 45 External Interrupt Controller */
  232. (void*) EIC_2_Handler, /* 46 External Interrupt Controller */
  233. (void*) EIC_3_Handler, /* 47 External Interrupt Controller */
  234. (void*) EIC_4_Handler, /* 48 External Interrupt Controller */
  235. (void*) EIC_5_Handler, /* 49 External Interrupt Controller */
  236. (void*) EIC_6_Handler, /* 50 External Interrupt Controller */
  237. (void*) EIC_7_Handler, /* 51 External Interrupt Controller */
  238. (void*) EIC_8_Handler, /* 52 External Interrupt Controller */
  239. (void*) IISC_Handler, /* 53 Inter-IC Sound (I2S) Controller */
  240. (void*) SPI_Handler, /* 54 Serial Peripheral Interface */
  241. (void*) TC00_Handler, /* 55 Timer/Counter 0 */
  242. (void*) TC01_Handler, /* 56 Timer/Counter 0 */
  243. (void*) TC02_Handler, /* 57 Timer/Counter 0 */
  244. (void*) TC10_Handler, /* 58 Timer/Counter 1 */
  245. (void*) TC11_Handler, /* 59 Timer/Counter 1 */
  246. (void*) TC12_Handler, /* 60 Timer/Counter 1 */
  247. (void*) TWIM0_Handler, /* 61 Two-wire Master Interface 0 */
  248. (void*) TWIS0_Handler, /* 62 Two-wire Slave Interface 0 */
  249. (void*) TWIM1_Handler, /* 63 Two-wire Master Interface 1 */
  250. (void*) TWIS1_Handler, /* 64 Two-wire Slave Interface 1 */
  251. (void*) USART0_Handler, /* 65 Universal Synchronous Asynchronous Receiver Transmitter 0 */
  252. (void*) USART1_Handler, /* 66 Universal Synchronous Asynchronous Receiver Transmitter 1 */
  253. (void*) USART2_Handler, /* 67 Universal Synchronous Asynchronous Receiver Transmitter 2 */
  254. (void*) USART3_Handler, /* 68 Universal Synchronous Asynchronous Receiver Transmitter 3 */
  255. (void*) ADCIFE_Handler, /* 69 ADC controller interface */
  256. (void*) DACC_Handler, /* 70 DAC Controller */
  257. (void*) ACIFC_Handler, /* 71 Analog Comparator Interface */
  258. (void*) ABDACB_Handler, /* 72 Audio Bitstream DAC */
  259. (void*) TRNG_Handler, /* 73 True Random Number Generator */
  260. (void*) PARC_Handler, /* 74 Parallel Capture */
  261. (void*) CATB_Handler, /* 75 Capacitive Touch Module B */
  262. (void*) PTC_Handler, /* 76 */
  263. (void*) TWIM2_Handler, /* 77 Two-wire Master Interface 2 */
  264. (void*) TWIM3_Handler, /* 78 Two-wire Master Interface 3 */
  265. #ifdef ID_LCDCA
  266. (void*) LCDCA_Handler /* 79 LCD Controller */
  267. #else
  268. (void*) (0UL) /* Reserved */
  269. #endif
  270. };
  271. /**
  272. * \brief This is the code that gets called on processor reset.
  273. * To initialize the device, and call the main() routine.
  274. */
  275. void Reset_Handler(void)
  276. {
  277. uint32_t *pSrc, *pDest;
  278. /* Initialize the relocate segment */
  279. pSrc = &_etext;
  280. pDest = &_srelocate;
  281. if (pSrc != pDest) {
  282. for (; pDest < &_erelocate;) {
  283. *pDest++ = *pSrc++;
  284. }
  285. }
  286. /* Clear the zero segment */
  287. for (pDest = &_szero; pDest < &_ezero;) {
  288. *pDest++ = 0;
  289. }
  290. /* Set the vector table base address */
  291. pSrc = (uint32_t *) & _sfixed;
  292. SCB->VTOR = ((uint32_t) pSrc & SCB_VTOR_TBLOFF_Msk);
  293. /* Initialize the C library */
  294. __libc_init_array();
  295. /* Branch to main function */
  296. main();
  297. /* Infinite loop */
  298. while (1);
  299. }
  300. /**
  301. * \brief Default interrupt handler for unused IRQs.
  302. */
  303. void Dummy_Handler(void)
  304. {
  305. while (1) {
  306. }
  307. }