startup_lpc13u_gnumake.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. /*================================*/
  2. /*=====LPC11XX GNU STARTUP========*/
  3. /*==A CODERED COMPATIBLE STARTUP==*/
  4. /*================================*/
  5. #if defined (__cplusplus)
  6. #ifdef __REDLIB__
  7. #error Redlib does not support C++
  8. #else
  9. //*****************************************************************************
  10. //
  11. // The entry point for the C++ library startup
  12. //
  13. //*****************************************************************************
  14. extern "C"
  15. {
  16. extern void __libc_init_array(void);
  17. }
  18. #endif
  19. #endif
  20. #define WEAK __attribute__ ((weak))
  21. #define ALIAS(f) __attribute__ ((weak, alias (#f)))
  22. #include "LPC13Uxx.h"
  23. //*****************************************************************************
  24. #if defined (__cplusplus)
  25. extern "C" {
  26. #endif
  27. extern unsigned int __data_load_addr;
  28. extern unsigned int __data_start;
  29. extern unsigned int __data_end;
  30. extern unsigned int __bss_start;
  31. extern unsigned int __bss_end;
  32. extern unsigned int __StackTop;
  33. #ifdef FIXED_STACKHEAP_SIZE
  34. #define STACK_SIZE (800)
  35. #define HEAP_SIZE (200)
  36. unsigned char StackMem[STACK_SIZE] __attribute__ ((section(".stack")));
  37. unsigned char HeapMem[HEAP_SIZE] __attribute__ ((section(".heap"), align(8)));
  38. #endif
  39. //*****************************************************************************
  40. //
  41. // Forward declaration of the default handlers. These are aliased.
  42. // When the application defines a handler (with the same name), this will
  43. // automatically take precedence over these weak definitions
  44. //
  45. //*****************************************************************************
  46. void Reset_Handler(void);
  47. WEAK void NMI_Handler(void);
  48. WEAK void HardFault_Handler(void);
  49. WEAK void MemManage_Handler(void);
  50. WEAK void BusFault_Handler(void);
  51. WEAK void UsageFault_Handler(void);
  52. WEAK void SVC_Handler(void);
  53. WEAK void DebugMon_Handler(void);
  54. WEAK void PendSV_Handler(void);
  55. WEAK void SysTick_Handler(void);
  56. WEAK void IntDefaultHandler(void);
  57. //*****************************************************************************
  58. //
  59. // Forward declaration of the specific IRQ handlers. These are aliased
  60. // to the IntDefaultHandler, which is a 'forever' loop. When the application
  61. // defines a handler (with the same name), this will automatically take
  62. // precedence over these weak definitions
  63. //
  64. //*****************************************************************************
  65. void PIN_INT0_IRQHandler (void) ALIAS(IntDefaultHandler);
  66. void PIN_INT1_IRQHandler (void) ALIAS(IntDefaultHandler);
  67. void PIN_INT2_IRQHandler (void) ALIAS(IntDefaultHandler);
  68. void PIN_INT3_IRQHandler (void) ALIAS(IntDefaultHandler);
  69. void PIN_INT4_IRQHandler (void) ALIAS(IntDefaultHandler);
  70. void PIN_INT5_IRQHandler (void) ALIAS(IntDefaultHandler);
  71. void PIN_INT6_IRQHandler (void) ALIAS(IntDefaultHandler);
  72. void PIN_INT7_IRQHandler (void) ALIAS(IntDefaultHandler);
  73. void GINT0_IRQHandler (void) ALIAS(IntDefaultHandler);
  74. void GINT1_IRQHandler (void) ALIAS(IntDefaultHandler);
  75. void OSTIMER_IRQHandler (void) ALIAS(IntDefaultHandler);
  76. void SSP1_IRQHandler (void) ALIAS(IntDefaultHandler);
  77. void I2C_IRQHandler (void) ALIAS(IntDefaultHandler);
  78. void CT16B0_IRQHandler (void) ALIAS(IntDefaultHandler);
  79. void CT16B1_IRQHandler (void) ALIAS(IntDefaultHandler);
  80. void CT32B0_IRQHandler (void) ALIAS(IntDefaultHandler);
  81. void CT32B1_IRQHandler (void) ALIAS(IntDefaultHandler);
  82. void SSP0_IRQHandler (void) ALIAS(IntDefaultHandler);
  83. void USART_IRQHandler (void) ALIAS(IntDefaultHandler);
  84. void USB_IRQHandler (void) ALIAS(IntDefaultHandler);
  85. void USB_FIQHandler (void) ALIAS(IntDefaultHandler);
  86. void ADC_IRQHandler (void) ALIAS(IntDefaultHandler);
  87. void WDT_IRQHandler (void) ALIAS(IntDefaultHandler);
  88. void BOD_IRQHandler (void) ALIAS(IntDefaultHandler);
  89. void FMC_IRQHandler (void) ALIAS(IntDefaultHandler);
  90. void OSCFAIL_IRQHandler (void) ALIAS(IntDefaultHandler);
  91. void PVTCIRCUIT_IRQHandler (void) ALIAS(IntDefaultHandler);
  92. void USBWakeup_IRQHandler (void) ALIAS(IntDefaultHandler);
  93. //*****************************************************************************
  94. //
  95. // The entry point for the application.
  96. // __main() is the entry point for Redlib based applications
  97. // main() is the entry point for Newlib based applications
  98. //
  99. //*****************************************************************************
  100. #if defined (__REDLIB__)
  101. extern void __main(void);
  102. #else
  103. extern int main(void);
  104. #endif
  105. //*****************************************************************************
  106. #if defined (__cplusplus)
  107. } // extern "C"
  108. #endif
  109. //*****************************************************************************
  110. //
  111. // The vector table. Note that the proper constructs must be placed on this to
  112. // ensure that it ends up at physical address 0x0000.0000.
  113. //
  114. //*****************************************************************************
  115. __attribute__ ((section(".isr_vector_table")))
  116. void (* const Vectors[])(void) = {
  117. #ifdef FIXED_STACKHEAP_SIZE
  118. (void (*)(void))(StackMem + STACK_SIZE), // The initial stack pointer
  119. #else
  120. (void (*)(void))&__StackTop,
  121. #endif
  122. Reset_Handler, // The reset handler
  123. NMI_Handler, // The NMI handler
  124. HardFault_Handler, // The hard fault handler
  125. MemManage_Handler, // The MPU fault handler
  126. BusFault_Handler, // The bus fault handler
  127. UsageFault_Handler, // The usage fault handler
  128. 0, // Reserved
  129. 0, // Reserved
  130. 0, // Reserved
  131. 0, // Reserved
  132. SVC_Handler, // SVCall handler
  133. DebugMon_Handler, // Debug monitor handler
  134. 0, // Reserved
  135. PendSV_Handler, // The PendSV handler
  136. SysTick_Handler, // The SysTick handler
  137. // LPC13U External Interrupts
  138. PIN_INT0_IRQHandler, // All GPIO pin can be routed to PIN_INTx
  139. PIN_INT1_IRQHandler,
  140. PIN_INT2_IRQHandler,
  141. PIN_INT3_IRQHandler,
  142. PIN_INT4_IRQHandler,
  143. PIN_INT5_IRQHandler,
  144. PIN_INT6_IRQHandler,
  145. PIN_INT7_IRQHandler,
  146. GINT0_IRQHandler,
  147. GINT1_IRQHandler, // PIO0 (0:7)
  148. 0,
  149. 0,
  150. OSTIMER_IRQHandler,
  151. 0,
  152. SSP1_IRQHandler, // SSP1
  153. I2C_IRQHandler, // I2C
  154. CT16B0_IRQHandler, // 16-bit Timer0
  155. CT16B1_IRQHandler, // 16-bit Timer1
  156. CT32B0_IRQHandler, // 32-bit Timer0
  157. CT32B1_IRQHandler, // 32-bit Timer1
  158. SSP0_IRQHandler, // SSP0
  159. USART_IRQHandler, // USART
  160. USB_IRQHandler, // USB IRQ
  161. USB_FIQHandler, // USB FIQ
  162. ADC_IRQHandler, // A/D Converter
  163. WDT_IRQHandler, // Watchdog timer
  164. BOD_IRQHandler, // Brown Out Detect
  165. FMC_IRQHandler, // IP2111 Flash Memory Controller
  166. OSCFAIL_IRQHandler, // OSC FAIL
  167. PVTCIRCUIT_IRQHandler, // PVT CIRCUIT
  168. USBWakeup_IRQHandler, // USB wake up
  169. 0,
  170. };
  171. //*****************************************************************************
  172. // Reset entry point for your code.
  173. // Sets up a simple runtime environment and initializes the C/C++
  174. // library.
  175. //*****************************************************************************
  176. __attribute__ ((section(".after_vectors")))
  177. void Reset_Handler(void)
  178. {
  179. /*
  180. * Only Initialize Internal SRAM
  181. * USB RAM is used for USB purpose
  182. */
  183. unsigned int *src, *dst;
  184. /* Copy data section from flash to RAM */
  185. src = &__data_load_addr;
  186. dst = &__data_start;
  187. while (dst < &__data_end)
  188. *dst++ = *src++;
  189. /* Zero fill the bss section */
  190. dst = &__bss_start;
  191. while (dst < &__bss_end)
  192. *dst++ = 0;
  193. SystemInit();
  194. #if defined (__cplusplus)
  195. //
  196. // Call C++ library initialisation
  197. //
  198. __libc_init_array();
  199. #endif
  200. #if defined (__REDLIB__)
  201. // Call the Redlib library, which in turn calls main()
  202. __main() ;
  203. #else
  204. main();
  205. #endif
  206. //
  207. // main() shouldn't return, but if it does, we'll just enter an infinite loop
  208. //
  209. while (1) {
  210. ;
  211. }
  212. }
  213. //*****************************************************************************
  214. //
  215. // This is the code that gets called when the processor receives a NMI. This
  216. // simply enters an infinite loop, preserving the system state for examination
  217. // by a debugger.
  218. //
  219. //*****************************************************************************
  220. __attribute__ ((section(".after_vectors")))
  221. void NMI_Handler(void)
  222. {
  223. while(1)
  224. {
  225. }
  226. }
  227. __attribute__ ((section(".after_vectors")))
  228. void HardFault_Handler(void)
  229. {
  230. while(1)
  231. {
  232. }
  233. }
  234. __attribute__ ((section(".after_vectors")))
  235. void MemManage_Handler(void)
  236. {
  237. while(1)
  238. {
  239. }
  240. }
  241. __attribute__ ((section(".after_vectors")))
  242. void BusFault_Handler(void)
  243. {
  244. while(1)
  245. {
  246. }
  247. }
  248. __attribute__ ((section(".after_vectors")))
  249. void UsageFault_Handler(void)
  250. {
  251. while(1)
  252. {
  253. }
  254. }
  255. __attribute__ ((section(".after_vectors")))
  256. void SVCall_Handler(void)
  257. {
  258. while(1)
  259. {
  260. }
  261. }
  262. __attribute__ ((section(".after_vectors")))
  263. void DebugMon_Handler(void)
  264. {
  265. while(1)
  266. {
  267. }
  268. }
  269. __attribute__ ((section(".after_vectors")))
  270. void PendSV_Handler(void)
  271. {
  272. while(1)
  273. {
  274. }
  275. }
  276. __attribute__ ((section(".after_vectors")))
  277. void SysTick_Handler(void)
  278. {
  279. while(1)
  280. {
  281. }
  282. }
  283. //*****************************************************************************
  284. //
  285. // Processor ends up here if an unexpected interrupt occurs or a handler
  286. // is not present in the application code.
  287. //
  288. //*****************************************************************************
  289. __attribute__ ((section(".after_vectors")))
  290. void IntDefaultHandler(void)
  291. {
  292. while(1)
  293. {
  294. }
  295. }