]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_EFM32_Gecko_Starter_Kit_Simplicity_Studio/Source/SilLabs_Code/Device/SiliconLabs/EFM32WG/Source/GCC/startup_efm32wg.c
Add files necessary to create a Pearl Gecko build configuration in the new EFM32...
[freertos] / FreeRTOS / Demo / CORTEX_EFM32_Gecko_Starter_Kit_Simplicity_Studio / Source / SilLabs_Code / Device / SiliconLabs / EFM32WG / Source / GCC / startup_efm32wg.c
1 /*\r
2  * @file startup_efm32wg.c\r
3  * @brief CMSIS Compatible EFM32WG startup file in C.\r
4  *        Should be used with GCC 'GNU Tools ARM Embedded'\r
5  * @version 4.2.1\r
6  * Date:    12 June 2014\r
7  *\r
8  */\r
9 /* Copyright (c) 2011 - 2014 ARM LIMITED\r
10 \r
11    All rights reserved.\r
12    Redistribution and use in source and binary forms, with or without\r
13    modification, are permitted provided that the following conditions are met:\r
14    - Redistributions of source code must retain the above copyright\r
15      notice, this list of conditions and the following disclaimer.\r
16    - Redistributions in binary form must reproduce the above copyright\r
17      notice, this list of conditions and the following disclaimer in the\r
18      documentation and/or other materials provided with the distribution.\r
19    - Neither the name of ARM nor the names of its contributors may be used\r
20      to endorse or promote products derived from this software without\r
21      specific prior written permission.\r
22    *\r
23    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\r
24    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
25    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
26    ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS AND CONTRIBUTORS BE\r
27    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\r
28    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\r
29    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
30    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
31    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\r
32    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\r
33    POSSIBILITY OF SUCH DAMAGE.\r
34    ---------------------------------------------------------------------------*/\r
35 \r
36 \r
37 #include <stdint.h>\r
38 \r
39 /*----------------------------------------------------------------------------\r
40   Linker generated Symbols\r
41  *----------------------------------------------------------------------------*/\r
42 extern uint32_t __etext;\r
43 extern uint32_t __data_start__;\r
44 extern uint32_t __data_end__;\r
45 extern uint32_t __copy_table_start__;\r
46 extern uint32_t __copy_table_end__;\r
47 extern uint32_t __zero_table_start__;\r
48 extern uint32_t __zero_table_end__;\r
49 extern uint32_t __bss_start__;\r
50 extern uint32_t __bss_end__;\r
51 extern uint32_t __StackTop;\r
52 \r
53 /*----------------------------------------------------------------------------\r
54   Exception / Interrupt Handler Function Prototype\r
55  *----------------------------------------------------------------------------*/\r
56 typedef void( *pFunc )( void );\r
57 \r
58 \r
59 /*----------------------------------------------------------------------------\r
60   External References\r
61  *----------------------------------------------------------------------------*/\r
62 #ifndef __START\r
63 extern void  _start(void) __attribute__((noreturn));    /* Pre Main (C library entry point) */\r
64 #else\r
65 extern int  __START(void) __attribute__((noreturn));    /* main entry point */\r
66 #endif\r
67 \r
68 #ifndef __NO_SYSTEM_INIT\r
69 extern void SystemInit (void);            /* CMSIS System Initialization      */\r
70 #endif\r
71 \r
72 \r
73 /*----------------------------------------------------------------------------\r
74   Internal References\r
75  *----------------------------------------------------------------------------*/\r
76 void Default_Handler(void);                          /* Default empty handler */\r
77 void Reset_Handler(void);                            /* Reset Handler */\r
78 \r
79 \r
80 /*----------------------------------------------------------------------------\r
81   User Initial Stack & Heap\r
82  *----------------------------------------------------------------------------*/\r
83 #ifndef __STACK_SIZE\r
84 #define __STACK_SIZE  0x00000400\r
85 #endif\r
86 static uint8_t stack[__STACK_SIZE] __attribute__ ((aligned(8), used, section(".stack")));\r
87 \r
88 #ifndef __HEAP_SIZE\r
89 #define __HEAP_SIZE   0x00000C00\r
90 #endif\r
91 #if __HEAP_SIZE > 0\r
92 static uint8_t heap[__HEAP_SIZE]   __attribute__ ((aligned(8), used, section(".heap")));\r
93 #endif\r
94 \r
95 \r
96 /*----------------------------------------------------------------------------\r
97   Exception / Interrupt Handler\r
98  *----------------------------------------------------------------------------*/\r
99 /* Cortex-M Processor Exceptions */\r
100 void NMI_Handler         (void) __attribute__ ((weak, alias("Default_Handler")));\r
101 void HardFault_Handler   (void) __attribute__ ((weak, alias("Default_Handler")));\r
102 void MemManage_Handler   (void) __attribute__ ((weak, alias("Default_Handler")));\r
103 void BusFault_Handler    (void) __attribute__ ((weak, alias("Default_Handler")));\r
104 void UsageFault_Handler  (void) __attribute__ ((weak, alias("Default_Handler")));\r
105 void DebugMon_Handler    (void) __attribute__ ((weak, alias("Default_Handler")));\r
106 void SVC_Handler         (void) __attribute__ ((weak, alias("Default_Handler")));\r
107 void PendSV_Handler      (void) __attribute__ ((weak, alias("Default_Handler")));\r
108 void SysTick_Handler     (void) __attribute__ ((weak, alias("Default_Handler")));\r
109 \r
110 /* Part Specific Interrupts */\r
111 void DMA_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
112 void GPIO_EVEN_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
113 void TIMER0_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
114 void USART0_RX_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
115 void USART0_TX_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
116 void USB_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
117 void ACMP0_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
118 void ADC0_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
119 void DAC0_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
120 void I2C0_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
121 void I2C1_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
122 void GPIO_ODD_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
123 void TIMER1_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
124 void TIMER2_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
125 void TIMER3_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
126 void USART1_RX_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
127 void USART1_TX_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
128 void LESENSE_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
129 void USART2_RX_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
130 void USART2_TX_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
131 void UART0_RX_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
132 void UART0_TX_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
133 void UART1_RX_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
134 void UART1_TX_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
135 void LEUART0_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
136 void LEUART1_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
137 void LETIMER0_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
138 void PCNT0_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
139 void PCNT1_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
140 void PCNT2_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
141 void RTC_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
142 void BURTC_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
143 void CMU_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
144 void VCMP_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
145 void LCD_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
146 void MSC_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
147 void AES_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
148 void EBI_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
149 void EMU_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
150 void FPUEH_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));\r
151 \r
152 \r
153 \r
154 /*----------------------------------------------------------------------------\r
155   Exception / Interrupt Vector table\r
156  *----------------------------------------------------------------------------*/\r
157 const pFunc __Vectors[] __attribute__ ((section(".vectors"))) = {\r
158   /* Cortex-M Exception Handlers */\r
159   (pFunc)&__StackTop,                       /*      Initial Stack Pointer     */\r
160   Reset_Handler,                            /*      Reset Handler             */\r
161   NMI_Handler,                              /*      NMI Handler               */\r
162   HardFault_Handler,                        /*      Hard Fault Handler        */\r
163   MemManage_Handler,                        /*      MPU Fault Handler         */\r
164   BusFault_Handler,                         /*      Bus Fault Handler         */\r
165   UsageFault_Handler,                       /*      Usage Fault Handler       */\r
166   Default_Handler,                          /*      Reserved                  */\r
167   Default_Handler,                          /*      Reserved                  */\r
168   Default_Handler,                          /*      Reserved                  */\r
169   Default_Handler,                          /*      Reserved                  */\r
170   SVC_Handler,                              /*      SVCall Handler            */\r
171   DebugMon_Handler,                         /*      Debug Monitor Handler     */\r
172   Default_Handler,                          /*      Reserved                  */\r
173   PendSV_Handler,                           /*      PendSV Handler            */\r
174   SysTick_Handler,                          /*      SysTick Handler           */\r
175 \r
176   /* External interrupts */\r
177 \r
178   DMA_IRQHandler,                       /*  0 - DMA       */\r
179   GPIO_EVEN_IRQHandler,                       /*  1 - GPIO_EVEN       */\r
180   TIMER0_IRQHandler,                       /*  2 - TIMER0       */\r
181   USART0_RX_IRQHandler,                       /*  3 - USART0_RX       */\r
182   USART0_TX_IRQHandler,                       /*  4 - USART0_TX       */\r
183   USB_IRQHandler,                       /*  5 - USB       */\r
184   ACMP0_IRQHandler,                       /*  6 - ACMP0       */\r
185   ADC0_IRQHandler,                       /*  7 - ADC0       */\r
186   DAC0_IRQHandler,                       /*  8 - DAC0       */\r
187   I2C0_IRQHandler,                       /*  9 - I2C0       */\r
188   I2C1_IRQHandler,                       /*  10 - I2C1       */\r
189   GPIO_ODD_IRQHandler,                       /*  11 - GPIO_ODD       */\r
190   TIMER1_IRQHandler,                       /*  12 - TIMER1       */\r
191   TIMER2_IRQHandler,                       /*  13 - TIMER2       */\r
192   TIMER3_IRQHandler,                       /*  14 - TIMER3       */\r
193   USART1_RX_IRQHandler,                       /*  15 - USART1_RX       */\r
194   USART1_TX_IRQHandler,                       /*  16 - USART1_TX       */\r
195   LESENSE_IRQHandler,                       /*  17 - LESENSE       */\r
196   USART2_RX_IRQHandler,                       /*  18 - USART2_RX       */\r
197   USART2_TX_IRQHandler,                       /*  19 - USART2_TX       */\r
198   UART0_RX_IRQHandler,                       /*  20 - UART0_RX       */\r
199   UART0_TX_IRQHandler,                       /*  21 - UART0_TX       */\r
200   UART1_RX_IRQHandler,                       /*  22 - UART1_RX       */\r
201   UART1_TX_IRQHandler,                       /*  23 - UART1_TX       */\r
202   LEUART0_IRQHandler,                       /*  24 - LEUART0       */\r
203   LEUART1_IRQHandler,                       /*  25 - LEUART1       */\r
204   LETIMER0_IRQHandler,                       /*  26 - LETIMER0       */\r
205   PCNT0_IRQHandler,                       /*  27 - PCNT0       */\r
206   PCNT1_IRQHandler,                       /*  28 - PCNT1       */\r
207   PCNT2_IRQHandler,                       /*  29 - PCNT2       */\r
208   RTC_IRQHandler,                       /*  30 - RTC       */\r
209   BURTC_IRQHandler,                       /*  31 - BURTC       */\r
210   CMU_IRQHandler,                       /*  32 - CMU       */\r
211   VCMP_IRQHandler,                       /*  33 - VCMP       */\r
212   LCD_IRQHandler,                       /*  34 - LCD       */\r
213   MSC_IRQHandler,                       /*  35 - MSC       */\r
214   AES_IRQHandler,                       /*  36 - AES       */\r
215   EBI_IRQHandler,                       /*  37 - EBI       */\r
216   EMU_IRQHandler,                       /*  38 - EMU       */\r
217   FPUEH_IRQHandler,                       /*  39 - FPUEH       */\r
218 \r
219 };\r
220 \r
221 \r
222 /*----------------------------------------------------------------------------\r
223   Reset Handler called on controller reset\r
224  *----------------------------------------------------------------------------*/\r
225 void Reset_Handler(void) {\r
226   uint32_t *pSrc, *pDest;\r
227   uint32_t *pTable __attribute__((unused));\r
228 \r
229 #ifndef __NO_SYSTEM_INIT\r
230   SystemInit();\r
231 #endif\r
232 \r
233 /*  Firstly it copies data from read only memory to RAM. There are two schemes\r
234  *  to copy. One can copy more than one sections. Another can only copy\r
235  *  one section.  The former scheme needs more instructions and read-only\r
236  *  data to implement than the latter.\r
237  *  Macro __STARTUP_COPY_MULTIPLE is used to choose between two schemes.  */\r
238 \r
239 #ifdef __STARTUP_COPY_MULTIPLE\r
240 /*  Multiple sections scheme.\r
241  *\r
242  *  Between symbol address __copy_table_start__ and __copy_table_end__,\r
243  *  there are array of triplets, each of which specify:\r
244  *    offset 0: LMA of start of a section to copy from\r
245  *    offset 4: VMA of start of a section to copy to\r
246  *    offset 8: size of the section to copy. Must be multiply of 4\r
247  *\r
248  *  All addresses must be aligned to 4 bytes boundary.\r
249  */\r
250   pTable = &__copy_table_start__;\r
251 \r
252   for (; pTable < &__copy_table_end__; pTable = pTable + 3)\r
253   {\r
254     pSrc  = (uint32_t*)*(pTable + 0);\r
255     pDest = (uint32_t*)*(pTable + 1);\r
256     for (; pDest < (uint32_t*)(*(pTable + 1) + *(pTable + 2)) ; )\r
257     {\r
258       *pDest++ = *pSrc++;\r
259     }\r
260   }\r
261 #else\r
262 /*  Single section scheme.\r
263  *\r
264  *  The ranges of copy from/to are specified by following symbols\r
265  *    __etext: LMA of start of the section to copy from. Usually end of text\r
266  *    __data_start__: VMA of start of the section to copy to\r
267  *    __data_end__: VMA of end of the section to copy to\r
268  *\r
269  *  All addresses must be aligned to 4 bytes boundary.\r
270  */\r
271   pSrc  = &__etext;\r
272   pDest = &__data_start__;\r
273 \r
274   for ( ; pDest < &__data_end__ ; )\r
275   {\r
276     *pDest++ = *pSrc++;\r
277   }\r
278 #endif /*__STARTUP_COPY_MULTIPLE */\r
279 \r
280 /*  This part of work usually is done in C library startup code. Otherwise,\r
281  *  define this macro to enable it in this startup.\r
282  *\r
283  *  There are two schemes too. One can clear multiple BSS sections. Another\r
284  *  can only clear one section. The former is more size expensive than the\r
285  *  latter.\r
286  *\r
287  *  Define macro __STARTUP_CLEAR_BSS_MULTIPLE to choose the former.\r
288  *  Otherwise efine macro __STARTUP_CLEAR_BSS to choose the later.\r
289  */\r
290 #ifdef __STARTUP_CLEAR_BSS_MULTIPLE\r
291 /*  Multiple sections scheme.\r
292  *\r
293  *  Between symbol address __copy_table_start__ and __copy_table_end__,\r
294  *  there are array of tuples specifying:\r
295  *    offset 0: Start of a BSS section\r
296  *    offset 4: Size of this BSS section. Must be multiply of 4\r
297  */\r
298   pTable = &__zero_table_start__;\r
299 \r
300   for (; pTable < &__zero_table_end__; pTable = pTable + 2)\r
301   {\r
302     pDest = (uint32_t*)*(pTable + 0);\r
303     for (; pDest < (uint32_t*)(*(pTable + 0) + *(pTable + 1)) ; )\r
304     {\r
305       *pDest++ = 0;\r
306     }\r
307   }\r
308 #elif defined (__STARTUP_CLEAR_BSS)\r
309 /*  Single BSS section scheme.\r
310  *\r
311  *  The BSS section is specified by following symbols\r
312  *    __bss_start__: start of the BSS section.\r
313  *    __bss_end__: end of the BSS section.\r
314  *\r
315  *  Both addresses must be aligned to 4 bytes boundary.\r
316  */\r
317   pDest = &__bss_start__;\r
318 \r
319   for ( ; pDest < &__bss_end__ ; )\r
320   {\r
321     *pDest++ = 0ul;\r
322   }\r
323 #endif /* __STARTUP_CLEAR_BSS_MULTIPLE || __STARTUP_CLEAR_BSS */\r
324 \r
325 #ifndef __START\r
326 #define __START _start\r
327 #endif\r
328   __START();\r
329 }\r
330 \r
331 \r
332 /*----------------------------------------------------------------------------\r
333   Default Handler for Exceptions / Interrupts\r
334  *----------------------------------------------------------------------------*/\r
335 void Default_Handler(void)\r
336 {\r
337   while(1);\r
338 }\r
339 \r