startup_gcc.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. //*****************************************************************************
  2. //
  3. // startup_gcc.c - Startup code for use with GNU tools.
  4. //
  5. // Copyright (c) 2013-2014 Texas Instruments Incorporated. All rights reserved.
  6. // Software License Agreement
  7. //
  8. // Texas Instruments (TI) is supplying this software for use solely and
  9. // exclusively on TI's microcontroller products. The software is owned by
  10. // TI and/or its suppliers, and is protected under applicable copyright
  11. // laws. You may not combine this software with "viral" open-source
  12. // software in order to form a larger program.
  13. //
  14. // THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
  15. // NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
  16. // NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  17. // A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
  18. // CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
  19. // DAMAGES, FOR ANY REASON WHATSOEVER.
  20. //
  21. // This is part of revision 2.1.0.12573 of the DK-TM4C129X Firmware Package.
  22. //
  23. //*****************************************************************************
  24. #include <stdint.h>
  25. #include "inc/hw_nvic.h"
  26. #include "inc/hw_types.h"
  27. //*****************************************************************************
  28. //
  29. // Forward declaration of the default fault handlers.
  30. //
  31. //*****************************************************************************
  32. void ResetISR(void);
  33. static void NmiSR(void);
  34. static void FaultISR(void);
  35. static void IntDefaultHandler(void);
  36. //*****************************************************************************
  37. //
  38. // The entry point for the application.
  39. //
  40. //*****************************************************************************
  41. extern int main(void);
  42. extern void SysTick_Handler(void);
  43. extern void PendSV_Handler(void);
  44. extern void UART0_IRQHandler(void);
  45. extern void HardFault_Handler(void);
  46. //*****************************************************************************
  47. //
  48. // Reserve space for the system stack.
  49. //
  50. //*****************************************************************************
  51. static uint32_t pui32Stack[64];
  52. //*****************************************************************************
  53. //
  54. // The vector table. Note that the proper constructs must be placed on this to
  55. // ensure that it ends up at physical address 0x0000.0000.
  56. //
  57. //*****************************************************************************
  58. __attribute__ ((section(".isr_vector")))
  59. void (* const g_pfnVectors[])(void) =
  60. {
  61. (void (*)(void))((uint32_t)pui32Stack + sizeof(pui32Stack)),
  62. // The initial stack pointer
  63. ResetISR, // The reset handler
  64. NmiSR, // The NMI handler
  65. HardFault_Handler, // The hard fault handler
  66. IntDefaultHandler, // The MPU fault handler
  67. IntDefaultHandler, // The bus fault handler
  68. IntDefaultHandler, // The usage fault handler
  69. 0, // Reserved
  70. 0, // Reserved
  71. 0, // Reserved
  72. 0, // Reserved
  73. IntDefaultHandler, // SVCall handler
  74. IntDefaultHandler, // Debug monitor handler
  75. 0, // Reserved
  76. PendSV_Handler, // The PendSV handler
  77. SysTick_Handler, // The SysTick handler
  78. IntDefaultHandler, // GPIO Port A
  79. IntDefaultHandler, // GPIO Port B
  80. IntDefaultHandler, // GPIO Port C
  81. IntDefaultHandler, // GPIO Port D
  82. IntDefaultHandler, // GPIO Port E
  83. UART0_IRQHandler, // UART0 Rx and Tx
  84. IntDefaultHandler, // UART1 Rx and Tx
  85. IntDefaultHandler, // SSI0 Rx and Tx
  86. IntDefaultHandler, // I2C0 Master and Slave
  87. IntDefaultHandler, // PWM Fault
  88. IntDefaultHandler, // PWM Generator 0
  89. IntDefaultHandler, // PWM Generator 1
  90. IntDefaultHandler, // PWM Generator 2
  91. IntDefaultHandler, // Quadrature Encoder 0
  92. IntDefaultHandler, // ADC Sequence 0
  93. IntDefaultHandler, // ADC Sequence 1
  94. IntDefaultHandler, // ADC Sequence 2
  95. IntDefaultHandler, // ADC Sequence 3
  96. IntDefaultHandler, // Watchdog timer
  97. IntDefaultHandler, // Timer 0 subtimer A
  98. IntDefaultHandler, // Timer 0 subtimer B
  99. IntDefaultHandler, // Timer 1 subtimer A
  100. IntDefaultHandler, // Timer 1 subtimer B
  101. IntDefaultHandler, // Timer 2 subtimer A
  102. IntDefaultHandler, // Timer 2 subtimer B
  103. IntDefaultHandler, // Analog Comparator 0
  104. IntDefaultHandler, // Analog Comparator 1
  105. IntDefaultHandler, // Analog Comparator 2
  106. IntDefaultHandler, // System Control (PLL, OSC, BO)
  107. IntDefaultHandler, // FLASH Control
  108. IntDefaultHandler, // GPIO Port F
  109. IntDefaultHandler, // GPIO Port G
  110. IntDefaultHandler, // GPIO Port H
  111. IntDefaultHandler, // UART2 Rx and Tx
  112. IntDefaultHandler, // SSI1 Rx and Tx
  113. IntDefaultHandler, // Timer 3 subtimer A
  114. IntDefaultHandler, // Timer 3 subtimer B
  115. IntDefaultHandler, // I2C1 Master and Slave
  116. IntDefaultHandler, // CAN0
  117. IntDefaultHandler, // CAN1
  118. IntDefaultHandler, // Ethernet
  119. IntDefaultHandler, // Hibernate
  120. IntDefaultHandler, // USB0
  121. IntDefaultHandler, // PWM Generator 3
  122. IntDefaultHandler, // uDMA Software Transfer
  123. IntDefaultHandler, // uDMA Error
  124. IntDefaultHandler, // ADC1 Sequence 0
  125. IntDefaultHandler, // ADC1 Sequence 1
  126. IntDefaultHandler, // ADC1 Sequence 2
  127. IntDefaultHandler, // ADC1 Sequence 3
  128. IntDefaultHandler, // External Bus Interface 0
  129. IntDefaultHandler, // GPIO Port J
  130. IntDefaultHandler, // GPIO Port K
  131. IntDefaultHandler, // GPIO Port L
  132. IntDefaultHandler, // SSI2 Rx and Tx
  133. IntDefaultHandler, // SSI3 Rx and Tx
  134. IntDefaultHandler, // UART3 Rx and Tx
  135. IntDefaultHandler, // UART4 Rx and Tx
  136. IntDefaultHandler, // UART5 Rx and Tx
  137. IntDefaultHandler, // UART6 Rx and Tx
  138. IntDefaultHandler, // UART7 Rx and Tx
  139. IntDefaultHandler, // I2C2 Master and Slave
  140. IntDefaultHandler, // I2C3 Master and Slave
  141. IntDefaultHandler, // Timer 4 subtimer A
  142. IntDefaultHandler, // Timer 4 subtimer B
  143. IntDefaultHandler, // Timer 5 subtimer A
  144. IntDefaultHandler, // Timer 5 subtimer B
  145. IntDefaultHandler, // FPU
  146. 0, // Reserved
  147. 0, // Reserved
  148. IntDefaultHandler, // I2C4 Master and Slave
  149. IntDefaultHandler, // I2C5 Master and Slave
  150. IntDefaultHandler, // GPIO Port M
  151. IntDefaultHandler, // GPIO Port N
  152. 0, // Reserved
  153. IntDefaultHandler, // Tamper
  154. IntDefaultHandler, // GPIO Port P (Summary or P0)
  155. IntDefaultHandler, // GPIO Port P1
  156. IntDefaultHandler, // GPIO Port P2
  157. IntDefaultHandler, // GPIO Port P3
  158. IntDefaultHandler, // GPIO Port P4
  159. IntDefaultHandler, // GPIO Port P5
  160. IntDefaultHandler, // GPIO Port P6
  161. IntDefaultHandler, // GPIO Port P7
  162. IntDefaultHandler, // GPIO Port Q (Summary or Q0)
  163. IntDefaultHandler, // GPIO Port Q1
  164. IntDefaultHandler, // GPIO Port Q2
  165. IntDefaultHandler, // GPIO Port Q3
  166. IntDefaultHandler, // GPIO Port Q4
  167. IntDefaultHandler, // GPIO Port Q5
  168. IntDefaultHandler, // GPIO Port Q6
  169. IntDefaultHandler, // GPIO Port Q7
  170. IntDefaultHandler, // GPIO Port R
  171. IntDefaultHandler, // GPIO Port S
  172. IntDefaultHandler, // SHA/MD5 0
  173. IntDefaultHandler, // AES 0
  174. IntDefaultHandler, // DES3DES 0
  175. IntDefaultHandler, // LCD Controller 0
  176. IntDefaultHandler, // Timer 6 subtimer A
  177. IntDefaultHandler, // Timer 6 subtimer B
  178. IntDefaultHandler, // Timer 7 subtimer A
  179. IntDefaultHandler, // Timer 7 subtimer B
  180. IntDefaultHandler, // I2C6 Master and Slave
  181. IntDefaultHandler, // I2C7 Master and Slave
  182. IntDefaultHandler, // HIM Scan Matrix Keyboard 0
  183. IntDefaultHandler, // One Wire 0
  184. IntDefaultHandler, // HIM PS/2 0
  185. IntDefaultHandler, // HIM LED Sequencer 0
  186. IntDefaultHandler, // HIM Consumer IR 0
  187. IntDefaultHandler, // I2C8 Master and Slave
  188. IntDefaultHandler, // I2C9 Master and Slave
  189. IntDefaultHandler // GPIO Port T
  190. };
  191. //*****************************************************************************
  192. //
  193. // The following are constructs created by the linker, indicating where the
  194. // the "data" and "bss" segments reside in memory. The initializers for the
  195. // for the "data" segment resides immediately following the "text" segment.
  196. //
  197. //*****************************************************************************
  198. extern uint32_t _etext;
  199. extern uint32_t _data;
  200. extern uint32_t _edata;
  201. extern uint32_t _bss;
  202. extern uint32_t _ebss;
  203. //*****************************************************************************
  204. //
  205. // This is the code that gets called when the processor first starts execution
  206. // following a reset event. Only the absolutely necessary set is performed,
  207. // after which the application supplied entry() routine is called. Any fancy
  208. // actions (such as making decisions based on the reset cause register, and
  209. // resetting the bits in that register) are left solely in the hands of the
  210. // application.
  211. //
  212. //*****************************************************************************
  213. void
  214. ResetISR(void)
  215. {
  216. uint32_t *pui32Src, *pui32Dest;
  217. //
  218. // Copy the data segment initializers from flash to SRAM.
  219. //
  220. pui32Src = &_etext;
  221. for(pui32Dest = &_data; pui32Dest < &_edata; )
  222. {
  223. *pui32Dest++ = *pui32Src++;
  224. }
  225. //
  226. // Zero fill the bss segment.
  227. //
  228. __asm(" ldr r0, =_bss\n"
  229. " ldr r1, =_ebss\n"
  230. " mov r2, #0\n"
  231. " .thumb_func\n"
  232. "zero_loop:\n"
  233. " cmp r0, r1\n"
  234. " it lt\n"
  235. " strlt r2, [r0], #4\n"
  236. " blt zero_loop");
  237. //
  238. // Enable the floating-point unit. This must be done here to handle the
  239. // case where main() uses floating-point and the function prologue saves
  240. // floating-point registers (which will fault if floating-point is not
  241. // enabled). Any configuration of the floating-point unit using DriverLib
  242. // APIs must be done here prior to the floating-point unit being enabled.
  243. //
  244. // Note that this does not use DriverLib since it might not be included in
  245. // this project.
  246. //
  247. HWREG(NVIC_CPAC) = ((HWREG(NVIC_CPAC) &
  248. ~(NVIC_CPAC_CP10_M | NVIC_CPAC_CP11_M)) |
  249. NVIC_CPAC_CP10_FULL | NVIC_CPAC_CP11_FULL);
  250. //
  251. // Call the application's entry point.
  252. //
  253. main();
  254. }
  255. //*****************************************************************************
  256. //
  257. // This is the code that gets called when the processor receives a NMI. This
  258. // simply enters an infinite loop, preserving the system state for examination
  259. // by a debugger.
  260. //
  261. //*****************************************************************************
  262. static void
  263. NmiSR(void)
  264. {
  265. //
  266. // Enter an infinite loop.
  267. //
  268. while(1)
  269. {
  270. }
  271. }
  272. //*****************************************************************************
  273. //
  274. // This is the code that gets called when the processor receives a fault
  275. // interrupt. This simply enters an infinite loop, preserving the system state
  276. // for examination by a debugger.
  277. //
  278. //*****************************************************************************
  279. static void
  280. FaultISR(void)
  281. {
  282. //
  283. // Enter an infinite loop.
  284. //
  285. while(1)
  286. {
  287. }
  288. }
  289. //*****************************************************************************
  290. //
  291. // This is the code that gets called when the processor receives an unexpected
  292. // interrupt. This simply enters an infinite loop, preserving the system state
  293. // for examination by a debugger.
  294. //
  295. //*****************************************************************************
  296. static void
  297. IntDefaultHandler(void)
  298. {
  299. //
  300. // Go into an infinite loop.
  301. //
  302. while(1)
  303. {
  304. }
  305. }