startup_lpc11u_gnumake.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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 "LPC11Uxx.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 SVC_Handler(void);
  50. WEAK void PendSV_Handler(void);
  51. WEAK void SysTick_Handler(void);
  52. WEAK void IntDefaultHandler(void);
  53. //*****************************************************************************
  54. //
  55. // Forward declaration of the specific IRQ handlers. These are aliased
  56. // to the IntDefaultHandler, which is a 'forever' loop. When the application
  57. // defines a handler (with the same name), this will automatically take
  58. // precedence over these weak definitions
  59. //
  60. //*****************************************************************************
  61. void FLEX_INT0_IRQHandler (void) ALIAS(IntDefaultHandler);
  62. void FLEX_INT1_IRQHandler (void) ALIAS(IntDefaultHandler);
  63. void FLEX_INT2_IRQHandler (void) ALIAS(IntDefaultHandler);
  64. void FLEX_INT3_IRQHandler (void) ALIAS(IntDefaultHandler);
  65. void FLEX_INT4_IRQHandler (void) ALIAS(IntDefaultHandler);
  66. void FLEX_INT5_IRQHandler (void) ALIAS(IntDefaultHandler);
  67. void FLEX_INT6_IRQHandler (void) ALIAS(IntDefaultHandler);
  68. void FLEX_INT7_IRQHandler (void) ALIAS(IntDefaultHandler);
  69. void GINT0_IRQHandler (void) ALIAS(IntDefaultHandler);
  70. void GINT1_IRQHandler (void) ALIAS(IntDefaultHandler);
  71. void SSP1_IRQHandler (void) ALIAS(IntDefaultHandler);
  72. void I2C_IRQHandler (void) ALIAS(IntDefaultHandler);
  73. void TIMER16_0_IRQHandler (void) ALIAS(IntDefaultHandler);
  74. void TIMER16_1_IRQHandler (void) ALIAS(IntDefaultHandler);
  75. void TIMER32_0_IRQHandler (void) ALIAS(IntDefaultHandler);
  76. void TIMER32_1_IRQHandler (void) ALIAS(IntDefaultHandler);
  77. void SSP0_IRQHandler (void) ALIAS(IntDefaultHandler);
  78. void UART_IRQHandler (void) ALIAS(IntDefaultHandler);
  79. void USB_IRQHandler (void) ALIAS(IntDefaultHandler);
  80. void USB_FIQHandler (void) ALIAS(IntDefaultHandler);
  81. void ADC_IRQHandler (void) ALIAS(IntDefaultHandler);
  82. void WDT_IRQHandler (void) ALIAS(IntDefaultHandler);
  83. void BOD_IRQHandler (void) ALIAS(IntDefaultHandler);
  84. void FMC_IRQHandler (void) ALIAS(IntDefaultHandler);
  85. void USBWakeup_IRQHandler (void) ALIAS(IntDefaultHandler);
  86. //*****************************************************************************
  87. //
  88. // The entry point for the application.
  89. // __main() is the entry point for Redlib based applications
  90. // main() is the entry point for Newlib based applications
  91. //
  92. //*****************************************************************************
  93. #if defined (__REDLIB__)
  94. extern void __main(void);
  95. #else
  96. extern int main(void);
  97. #endif
  98. //*****************************************************************************
  99. #if defined (__cplusplus)
  100. } // extern "C"
  101. #endif
  102. __attribute__ ((section(".isr_vector_table")))
  103. void (* const Vectors[])(void) = {
  104. #ifdef FIXED_STACKHEAP_SIZE
  105. (void (*)(void))(StackMem + STACK_SIZE), // The initial stack pointer
  106. #else
  107. (void (*)(void))&__StackTop,
  108. #endif
  109. Reset_Handler, // The reset handler
  110. NMI_Handler, // The NMI handler
  111. HardFault_Handler, // The hard fault handler
  112. 0, // Reserved
  113. 0, // Reserved
  114. 0, // Reserved
  115. 0, // Reserved
  116. 0, // Reserved
  117. 0, // Reserved
  118. 0, // Reserved
  119. SVC_Handler, // SVCall handler
  120. 0, // Reserved
  121. 0, // Reserved
  122. PendSV_Handler, // The PendSV handler
  123. SysTick_Handler, // The SysTick handler
  124. // LPC11U specific handlers
  125. FLEX_INT0_IRQHandler, // 0 - GPIO pin interrupt 0
  126. FLEX_INT1_IRQHandler, // 1 - GPIO pin interrupt 1
  127. FLEX_INT2_IRQHandler, // 2 - GPIO pin interrupt 2
  128. FLEX_INT3_IRQHandler, // 3 - GPIO pin interrupt 3
  129. FLEX_INT4_IRQHandler, // 4 - GPIO pin interrupt 4
  130. FLEX_INT5_IRQHandler, // 5 - GPIO pin interrupt 5
  131. FLEX_INT6_IRQHandler, // 6 - GPIO pin interrupt 6
  132. FLEX_INT7_IRQHandler, // 7 - GPIO pin interrupt 7
  133. GINT0_IRQHandler, // 8 - GPIO GROUP0 interrupt
  134. GINT1_IRQHandler, // 9 - GPIO GROUP1 interrupt
  135. 0, // 10 - Reserved
  136. 0, // 11 - Reserved
  137. 0, // 12 - Reserved
  138. 0, // 13 - Reserved
  139. SSP1_IRQHandler, // 14 - SPI/SSP1 Interrupt
  140. I2C_IRQHandler, // 15 - I2C0
  141. TIMER16_0_IRQHandler, // 16 - CT16B0 (16-bit Timer 0)
  142. TIMER16_1_IRQHandler, // 17 - CT16B1 (16-bit Timer 1)
  143. TIMER32_0_IRQHandler, // 18 - CT32B0 (32-bit Timer 0)
  144. TIMER32_1_IRQHandler, // 19 - CT32B1 (32-bit Timer 1)
  145. SSP0_IRQHandler, // 20 - SPI/SSP0 Interrupt
  146. UART_IRQHandler, // 21 - UART0
  147. USB_IRQHandler, // 22 - USB IRQ
  148. USB_FIQHandler, // 23 - USB FIQ
  149. ADC_IRQHandler, // 24 - ADC (A/D Converter)
  150. WDT_IRQHandler, // 25 - WDT (Watchdog Timer)
  151. BOD_IRQHandler, // 26 - BOD (Brownout Detect)
  152. FMC_IRQHandler, // 27 - IP2111 Flash Memory Controller
  153. 0, // 28 - Reserved
  154. 0, // 29 - Reserved
  155. USBWakeup_IRQHandler, // 30 - USB wake-up interrupt
  156. 0, // 31 - Reserved
  157. };
  158. //*****************************************************************************
  159. // Reset entry point for your code.
  160. // Sets up a simple runtime environment and initializes the C/C++
  161. // library.
  162. //*****************************************************************************
  163. __attribute__ ((section(".after_vectors")))
  164. void Reset_Handler(void)
  165. {
  166. /*
  167. * Only Initialize Internal SRAM
  168. * USB RAM is used for USB purpose
  169. */
  170. unsigned int *src, *dst;
  171. /* Copy data section from flash to RAM */
  172. src = &__data_load_addr;
  173. dst = &__data_start;
  174. while (dst < &__data_end)
  175. *dst++ = *src++;
  176. /* Zero fill the bss section */
  177. dst = &__bss_start;
  178. while (dst < &__bss_end)
  179. *dst++ = 0;
  180. SystemInit();
  181. #if defined (__cplusplus)
  182. //
  183. // Call C++ library initialisation
  184. //
  185. __libc_init_array();
  186. #endif
  187. #if defined (__REDLIB__)
  188. // Call the Redlib library, which in turn calls main()
  189. __main() ;
  190. #else
  191. main();
  192. #endif
  193. //
  194. // main() shouldn't return, but if it does, we'll just enter an infinite loop
  195. //
  196. while (1) {
  197. ;
  198. }
  199. }
  200. //*****************************************************************************
  201. // Default exception handlers. Override the ones here by defining your own
  202. // handler routines in your application code.
  203. //*****************************************************************************
  204. __attribute__ ((section(".after_vectors")))
  205. void NMI_Handler(void)
  206. {
  207. while(1)
  208. {
  209. }
  210. }
  211. __attribute__ ((section(".after_vectors")))
  212. void HardFault_Handler(void)
  213. {
  214. while(1)
  215. {
  216. }
  217. }
  218. __attribute__ ((section(".after_vectors")))
  219. void SVC_Handler(void)
  220. {
  221. while(1)
  222. {
  223. }
  224. }
  225. __attribute__ ((section(".after_vectors")))
  226. void PendSV_Handler(void)
  227. {
  228. while(1)
  229. {
  230. }
  231. }
  232. __attribute__ ((section(".after_vectors")))
  233. void SysTick_Handler(void)
  234. {
  235. while(1)
  236. {
  237. }
  238. }
  239. //*****************************************************************************
  240. //
  241. // Processor ends up here if an unexpected interrupt occurs or a specific
  242. // handler is not present in the application code.
  243. //
  244. //*****************************************************************************
  245. __attribute__ ((section(".after_vectors")))
  246. void IntDefaultHandler(void)
  247. {
  248. while(1)
  249. {
  250. }
  251. }