start_gcc.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. //*****************************************************************************
  2. //
  3. // startup_gcc.c - Startup code for use with GNU tools.
  4. //
  5. // Copyright (c) 2011 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 8049 of the EK-LM4F232 Firmware Package.
  22. //
  23. //*****************************************************************************
  24. //*****************************************************************************
  25. //
  26. // Forward declaration of the default fault handlers.
  27. //
  28. //*****************************************************************************
  29. void ResetISR(void);
  30. static void NmiSR(void);
  31. static void FaultISR(void);
  32. static void IntDefaultHandler(void);
  33. /* RT-Thread interface */
  34. static void HardFault_Handler(void);
  35. static void PendSV_Handler(void);
  36. static void rt_hw_timer_handler(void);
  37. //*****************************************************************************
  38. //
  39. // The entry point for the application.
  40. //
  41. //*****************************************************************************
  42. extern int main(void);
  43. //*****************************************************************************
  44. //
  45. // Reserve space for the system stack.
  46. //
  47. //*****************************************************************************
  48. static unsigned long pulStack[256];
  49. //*****************************************************************************
  50. //
  51. // The vector table. Note that the proper constructs must be placed on this to
  52. // ensure that it ends up at physical address 0x0000.0000.
  53. //
  54. //*****************************************************************************
  55. __attribute__ ((section(".isr_vector")))
  56. void (* const g_pfnVectors[])(void) =
  57. {
  58. (void (*)(void))((unsigned long)pulStack + sizeof(pulStack)),
  59. // The initial stack pointer
  60. ResetISR, // The reset handler
  61. NmiSR, // The NMI handler
  62. HardFault_Handler, // The hard fault handler
  63. IntDefaultHandler, // The MPU fault handler
  64. IntDefaultHandler, // The bus fault handler
  65. IntDefaultHandler, // The usage fault handler
  66. 0, // Reserved
  67. 0, // Reserved
  68. 0, // Reserved
  69. 0, // Reserved
  70. IntDefaultHandler, // SVCall handler
  71. IntDefaultHandler, // Debug monitor handler
  72. 0, // Reserved
  73. PendSV_Handler, // The PendSV handler
  74. rt_hw_timer_handler, // The SysTick handler
  75. IntDefaultHandler, // GPIO Port A
  76. IntDefaultHandler, // GPIO Port B
  77. IntDefaultHandler, // GPIO Port C
  78. IntDefaultHandler, // GPIO Port D
  79. IntDefaultHandler, // GPIO Port E
  80. IntDefaultHandler, // UART0 Rx and Tx
  81. IntDefaultHandler, // UART1 Rx and Tx
  82. IntDefaultHandler, // SSI0 Rx and Tx
  83. IntDefaultHandler, // I2C0 Master and Slave
  84. IntDefaultHandler, // PWM Fault
  85. IntDefaultHandler, // PWM Generator 0
  86. IntDefaultHandler, // PWM Generator 1
  87. IntDefaultHandler, // PWM Generator 2
  88. IntDefaultHandler, // Quadrature Encoder 0
  89. IntDefaultHandler, // ADC Sequence 0
  90. IntDefaultHandler, // ADC Sequence 1
  91. IntDefaultHandler, // ADC Sequence 2
  92. IntDefaultHandler, // ADC Sequence 3
  93. IntDefaultHandler, // Watchdog timer
  94. IntDefaultHandler, // Timer 0 subtimer A
  95. IntDefaultHandler, // Timer 0 subtimer B
  96. IntDefaultHandler, // Timer 1 subtimer A
  97. IntDefaultHandler, // Timer 1 subtimer B
  98. IntDefaultHandler, // Timer 2 subtimer A
  99. IntDefaultHandler, // Timer 2 subtimer B
  100. IntDefaultHandler, // Analog Comparator 0
  101. IntDefaultHandler, // Analog Comparator 1
  102. IntDefaultHandler, // Analog Comparator 2
  103. IntDefaultHandler, // System Control (PLL, OSC, BO)
  104. IntDefaultHandler, // FLASH Control
  105. IntDefaultHandler, // GPIO Port F
  106. IntDefaultHandler, // GPIO Port G
  107. IntDefaultHandler, // GPIO Port H
  108. IntDefaultHandler, // UART2 Rx and Tx
  109. IntDefaultHandler, // SSI1 Rx and Tx
  110. IntDefaultHandler, // Timer 3 subtimer A
  111. IntDefaultHandler, // Timer 3 subtimer B
  112. IntDefaultHandler, // I2C1 Master and Slave
  113. IntDefaultHandler, // Quadrature Encoder 1
  114. IntDefaultHandler, // CAN0
  115. IntDefaultHandler, // CAN1
  116. IntDefaultHandler, // CAN2
  117. IntDefaultHandler, // Ethernet
  118. IntDefaultHandler, // Hibernate
  119. IntDefaultHandler, // USB0
  120. IntDefaultHandler, // PWM Generator 3
  121. IntDefaultHandler, // uDMA Software Transfer
  122. IntDefaultHandler, // uDMA Error
  123. IntDefaultHandler, // ADC1 Sequence 0
  124. IntDefaultHandler, // ADC1 Sequence 1
  125. IntDefaultHandler, // ADC1 Sequence 2
  126. IntDefaultHandler, // ADC1 Sequence 3
  127. IntDefaultHandler, // I2S0
  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. 0, // Reserved
  140. 0, // Reserved
  141. 0, // Reserved
  142. 0, // Reserved
  143. IntDefaultHandler, // I2C2 Master and Slave
  144. IntDefaultHandler, // I2C3 Master and Slave
  145. IntDefaultHandler, // Timer 4 subtimer A
  146. IntDefaultHandler, // Timer 4 subtimer B
  147. 0, // Reserved
  148. 0, // Reserved
  149. 0, // Reserved
  150. 0, // Reserved
  151. 0, // Reserved
  152. 0, // Reserved
  153. 0, // Reserved
  154. 0, // Reserved
  155. 0, // Reserved
  156. 0, // Reserved
  157. 0, // Reserved
  158. 0, // Reserved
  159. 0, // Reserved
  160. 0, // Reserved
  161. 0, // Reserved
  162. 0, // Reserved
  163. 0, // Reserved
  164. 0, // Reserved
  165. 0, // Reserved
  166. 0, // Reserved
  167. IntDefaultHandler, // Timer 5 subtimer A
  168. IntDefaultHandler, // Timer 5 subtimer B
  169. IntDefaultHandler, // Wide Timer 0 subtimer A
  170. IntDefaultHandler, // Wide Timer 0 subtimer B
  171. IntDefaultHandler, // Wide Timer 1 subtimer A
  172. IntDefaultHandler, // Wide Timer 1 subtimer B
  173. IntDefaultHandler, // Wide Timer 2 subtimer A
  174. IntDefaultHandler, // Wide Timer 2 subtimer B
  175. IntDefaultHandler, // Wide Timer 3 subtimer A
  176. IntDefaultHandler, // Wide Timer 3 subtimer B
  177. IntDefaultHandler, // Wide Timer 4 subtimer A
  178. IntDefaultHandler, // Wide Timer 4 subtimer B
  179. IntDefaultHandler, // Wide Timer 5 subtimer A
  180. IntDefaultHandler, // Wide Timer 5 subtimer B
  181. IntDefaultHandler, // FPU
  182. IntDefaultHandler, // PECI 0
  183. IntDefaultHandler, // LPC 0
  184. IntDefaultHandler, // I2C4 Master and Slave
  185. IntDefaultHandler, // I2C5 Master and Slave
  186. IntDefaultHandler, // GPIO Port M
  187. IntDefaultHandler, // GPIO Port N
  188. IntDefaultHandler, // Quadrature Encoder 2
  189. IntDefaultHandler, // Fan 0
  190. 0, // Reserved
  191. IntDefaultHandler, // GPIO Port P (Summary or P0)
  192. IntDefaultHandler, // GPIO Port P1
  193. IntDefaultHandler, // GPIO Port P2
  194. IntDefaultHandler, // GPIO Port P3
  195. IntDefaultHandler, // GPIO Port P4
  196. IntDefaultHandler, // GPIO Port P5
  197. IntDefaultHandler, // GPIO Port P6
  198. IntDefaultHandler, // GPIO Port P7
  199. IntDefaultHandler, // GPIO Port Q (Summary or Q0)
  200. IntDefaultHandler, // GPIO Port Q1
  201. IntDefaultHandler, // GPIO Port Q2
  202. IntDefaultHandler, // GPIO Port Q3
  203. IntDefaultHandler, // GPIO Port Q4
  204. IntDefaultHandler, // GPIO Port Q5
  205. IntDefaultHandler, // GPIO Port Q6
  206. IntDefaultHandler, // GPIO Port Q7
  207. IntDefaultHandler, // GPIO Port R
  208. IntDefaultHandler, // GPIO Port S
  209. IntDefaultHandler, // PWM 1 Generator 0
  210. IntDefaultHandler, // PWM 1 Generator 1
  211. IntDefaultHandler, // PWM 1 Generator 2
  212. IntDefaultHandler, // PWM 1 Generator 3
  213. IntDefaultHandler // PWM 1 Fault
  214. };
  215. //*****************************************************************************
  216. //
  217. // The following are constructs created by the linker, indicating where the
  218. // the "data" and "bss" segments reside in memory. The initializers for the
  219. // for the "data" segment resides immediately following the "text" segment.
  220. //
  221. //*****************************************************************************
  222. extern unsigned long _etext;
  223. extern unsigned long _data;
  224. extern unsigned long _edata;
  225. extern unsigned long _bss;
  226. extern unsigned long _ebss;
  227. //*****************************************************************************
  228. //
  229. // This is the code that gets called when the processor first starts execution
  230. // following a reset event. Only the absolutely necessary set is performed,
  231. // after which the application supplied entry() routine is called. Any fancy
  232. // actions (such as making decisions based on the reset cause register, and
  233. // resetting the bits in that register) are left solely in the hands of the
  234. // application.
  235. //
  236. //*****************************************************************************
  237. void
  238. ResetISR(void)
  239. {
  240. unsigned long *pulSrc, *pulDest;
  241. //
  242. // Copy the data segment initializers from flash to SRAM.
  243. //
  244. pulSrc = &_etext;
  245. for(pulDest = &_data; pulDest < &_edata; )
  246. {
  247. *pulDest++ = *pulSrc++;
  248. }
  249. //
  250. // Zero fill the bss segment.
  251. //
  252. __asm(" ldr r0, =_bss\n"
  253. " ldr r1, =_ebss\n"
  254. " mov r2, #0\n"
  255. " .thumb_func\n"
  256. "zero_loop:\n"
  257. " cmp r0, r1\n"
  258. " it lt\n"
  259. " strlt r2, [r0], #4\n"
  260. " blt zero_loop");
  261. //
  262. // Call the application's entry point.
  263. //
  264. main();
  265. }
  266. //*****************************************************************************
  267. //
  268. // This is the code that gets called when the processor receives a NMI. This
  269. // simply enters an infinite loop, preserving the system state for examination
  270. // by a debugger.
  271. //
  272. //*****************************************************************************
  273. static void
  274. NmiSR(void)
  275. {
  276. //
  277. // Enter an infinite loop.
  278. //
  279. while(1)
  280. {
  281. }
  282. }
  283. //*****************************************************************************
  284. //
  285. // This is the code that gets called when the processor receives a fault
  286. // interrupt. This simply enters an infinite loop, preserving the system state
  287. // for examination by a debugger.
  288. //
  289. //*****************************************************************************
  290. static void
  291. FaultISR(void)
  292. {
  293. //
  294. // Enter an infinite loop.
  295. //
  296. while(1)
  297. {
  298. }
  299. }
  300. //*****************************************************************************
  301. //
  302. // This is the code that gets called when the processor receives an unexpected
  303. // interrupt. This simply enters an infinite loop, preserving the system state
  304. // for examination by a debugger.
  305. //
  306. //*****************************************************************************
  307. static void
  308. IntDefaultHandler(void)
  309. {
  310. //
  311. // Go into an infinite loop.
  312. //
  313. while(1)
  314. {
  315. }
  316. }