]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_EFM32_Gecko_Starter_Kit_Simplicity_Studio/Source/SilLabs_Code/Device/SiliconLabs/EFM32GG/Source/GCC/startup_efm32gg.c
Add Pearl Gecko demo.
[freertos] / FreeRTOS / Demo / CORTEX_EFM32_Gecko_Starter_Kit_Simplicity_Studio / Source / SilLabs_Code / Device / SiliconLabs / EFM32GG / Source / GCC / startup_efm32gg.c
1 /*\r
2  * @file startup_efm32gg.c\r
3  * @brief CMSIS Compatible EFM32GG 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 \r
151 \r
152 \r
153 /*----------------------------------------------------------------------------\r
154   Exception / Interrupt Vector table\r
155  *----------------------------------------------------------------------------*/\r
156 const pFunc __Vectors[] __attribute__ ((section(".vectors"))) = {\r
157   /* Cortex-M Exception Handlers */\r
158   (pFunc)&__StackTop,                       /*      Initial Stack Pointer     */\r
159   Reset_Handler,                            /*      Reset Handler             */\r
160   NMI_Handler,                              /*      NMI Handler               */\r
161   HardFault_Handler,                        /*      Hard Fault Handler        */\r
162   MemManage_Handler,                        /*      MPU Fault Handler         */\r
163   BusFault_Handler,                         /*      Bus Fault Handler         */\r
164   UsageFault_Handler,                       /*      Usage Fault Handler       */\r
165   Default_Handler,                          /*      Reserved                  */\r
166   Default_Handler,                          /*      Reserved                  */\r
167   Default_Handler,                          /*      Reserved                  */\r
168   Default_Handler,                          /*      Reserved                  */\r
169   SVC_Handler,                              /*      SVCall Handler            */\r
170   DebugMon_Handler,                         /*      Debug Monitor Handler     */\r
171   Default_Handler,                          /*      Reserved                  */\r
172   PendSV_Handler,                           /*      PendSV Handler            */\r
173   SysTick_Handler,                          /*      SysTick Handler           */\r
174 \r
175   /* External interrupts */\r
176 \r
177   DMA_IRQHandler,                       /*  0 - DMA       */\r
178   GPIO_EVEN_IRQHandler,                       /*  1 - GPIO_EVEN       */\r
179   TIMER0_IRQHandler,                       /*  2 - TIMER0       */\r
180   USART0_RX_IRQHandler,                       /*  3 - USART0_RX       */\r
181   USART0_TX_IRQHandler,                       /*  4 - USART0_TX       */\r
182   USB_IRQHandler,                       /*  5 - USB       */\r
183   ACMP0_IRQHandler,                       /*  6 - ACMP0       */\r
184   ADC0_IRQHandler,                       /*  7 - ADC0       */\r
185   DAC0_IRQHandler,                       /*  8 - DAC0       */\r
186   I2C0_IRQHandler,                       /*  9 - I2C0       */\r
187   I2C1_IRQHandler,                       /*  10 - I2C1       */\r
188   GPIO_ODD_IRQHandler,                       /*  11 - GPIO_ODD       */\r
189   TIMER1_IRQHandler,                       /*  12 - TIMER1       */\r
190   TIMER2_IRQHandler,                       /*  13 - TIMER2       */\r
191   TIMER3_IRQHandler,                       /*  14 - TIMER3       */\r
192   USART1_RX_IRQHandler,                       /*  15 - USART1_RX       */\r
193   USART1_TX_IRQHandler,                       /*  16 - USART1_TX       */\r
194   LESENSE_IRQHandler,                       /*  17 - LESENSE       */\r
195   USART2_RX_IRQHandler,                       /*  18 - USART2_RX       */\r
196   USART2_TX_IRQHandler,                       /*  19 - USART2_TX       */\r
197   UART0_RX_IRQHandler,                       /*  20 - UART0_RX       */\r
198   UART0_TX_IRQHandler,                       /*  21 - UART0_TX       */\r
199   UART1_RX_IRQHandler,                       /*  22 - UART1_RX       */\r
200   UART1_TX_IRQHandler,                       /*  23 - UART1_TX       */\r
201   LEUART0_IRQHandler,                       /*  24 - LEUART0       */\r
202   LEUART1_IRQHandler,                       /*  25 - LEUART1       */\r
203   LETIMER0_IRQHandler,                       /*  26 - LETIMER0       */\r
204   PCNT0_IRQHandler,                       /*  27 - PCNT0       */\r
205   PCNT1_IRQHandler,                       /*  28 - PCNT1       */\r
206   PCNT2_IRQHandler,                       /*  29 - PCNT2       */\r
207   RTC_IRQHandler,                       /*  30 - RTC       */\r
208   BURTC_IRQHandler,                       /*  31 - BURTC       */\r
209   CMU_IRQHandler,                       /*  32 - CMU       */\r
210   VCMP_IRQHandler,                       /*  33 - VCMP       */\r
211   LCD_IRQHandler,                       /*  34 - LCD       */\r
212   MSC_IRQHandler,                       /*  35 - MSC       */\r
213   AES_IRQHandler,                       /*  36 - AES       */\r
214   EBI_IRQHandler,                       /*  37 - EBI       */\r
215   EMU_IRQHandler,                       /*  38 - EMU       */\r
216 \r
217 };\r
218 \r
219 \r
220 /*----------------------------------------------------------------------------\r
221   Reset Handler called on controller reset\r
222  *----------------------------------------------------------------------------*/\r
223 void Reset_Handler(void) {\r
224   uint32_t *pSrc, *pDest;\r
225   uint32_t *pTable __attribute__((unused));\r
226 \r
227 #ifndef __NO_SYSTEM_INIT\r
228   SystemInit();\r
229 #endif\r
230 \r
231 /*  Firstly it copies data from read only memory to RAM. There are two schemes\r
232  *  to copy. One can copy more than one sections. Another can only copy\r
233  *  one section.  The former scheme needs more instructions and read-only\r
234  *  data to implement than the latter.\r
235  *  Macro __STARTUP_COPY_MULTIPLE is used to choose between two schemes.  */\r
236 \r
237 #ifdef __STARTUP_COPY_MULTIPLE\r
238 /*  Multiple sections scheme.\r
239  *\r
240  *  Between symbol address __copy_table_start__ and __copy_table_end__,\r
241  *  there are array of triplets, each of which specify:\r
242  *    offset 0: LMA of start of a section to copy from\r
243  *    offset 4: VMA of start of a section to copy to\r
244  *    offset 8: size of the section to copy. Must be multiply of 4\r
245  *\r
246  *  All addresses must be aligned to 4 bytes boundary.\r
247  */\r
248   pTable = &__copy_table_start__;\r
249 \r
250   for (; pTable < &__copy_table_end__; pTable = pTable + 3)\r
251   {\r
252     pSrc  = (uint32_t*)*(pTable + 0);\r
253     pDest = (uint32_t*)*(pTable + 1);\r
254     for (; pDest < (uint32_t*)(*(pTable + 1) + *(pTable + 2)) ; )\r
255     {\r
256       *pDest++ = *pSrc++;\r
257     }\r
258   }\r
259 #else\r
260 /*  Single section scheme.\r
261  *\r
262  *  The ranges of copy from/to are specified by following symbols\r
263  *    __etext: LMA of start of the section to copy from. Usually end of text\r
264  *    __data_start__: VMA of start of the section to copy to\r
265  *    __data_end__: VMA of end of the section to copy to\r
266  *\r
267  *  All addresses must be aligned to 4 bytes boundary.\r
268  */\r
269   pSrc  = &__etext;\r
270   pDest = &__data_start__;\r
271 \r
272   for ( ; pDest < &__data_end__ ; )\r
273   {\r
274     *pDest++ = *pSrc++;\r
275   }\r
276 #endif /*__STARTUP_COPY_MULTIPLE */\r
277 \r
278 /*  This part of work usually is done in C library startup code. Otherwise,\r
279  *  define this macro to enable it in this startup.\r
280  *\r
281  *  There are two schemes too. One can clear multiple BSS sections. Another\r
282  *  can only clear one section. The former is more size expensive than the\r
283  *  latter.\r
284  *\r
285  *  Define macro __STARTUP_CLEAR_BSS_MULTIPLE to choose the former.\r
286  *  Otherwise efine macro __STARTUP_CLEAR_BSS to choose the later.\r
287  */\r
288 #ifdef __STARTUP_CLEAR_BSS_MULTIPLE\r
289 /*  Multiple sections scheme.\r
290  *\r
291  *  Between symbol address __copy_table_start__ and __copy_table_end__,\r
292  *  there are array of tuples specifying:\r
293  *    offset 0: Start of a BSS section\r
294  *    offset 4: Size of this BSS section. Must be multiply of 4\r
295  */\r
296   pTable = &__zero_table_start__;\r
297 \r
298   for (; pTable < &__zero_table_end__; pTable = pTable + 2)\r
299   {\r
300     pDest = (uint32_t*)*(pTable + 0);\r
301     for (; pDest < (uint32_t*)(*(pTable + 0) + *(pTable + 1)) ; )\r
302     {\r
303       *pDest++ = 0;\r
304     }\r
305   }\r
306 #elif defined (__STARTUP_CLEAR_BSS)\r
307 /*  Single BSS section scheme.\r
308  *\r
309  *  The BSS section is specified by following symbols\r
310  *    __bss_start__: start of the BSS section.\r
311  *    __bss_end__: end of the BSS section.\r
312  *\r
313  *  Both addresses must be aligned to 4 bytes boundary.\r
314  */\r
315   pDest = &__bss_start__;\r
316 \r
317   for ( ; pDest < &__bss_end__ ; )\r
318   {\r
319     *pDest++ = 0ul;\r
320   }\r
321 #endif /* __STARTUP_CLEAR_BSS_MULTIPLE || __STARTUP_CLEAR_BSS */\r
322 \r
323 #ifndef __START\r
324 #define __START _start\r
325 #endif\r
326   __START();\r
327 }\r
328 \r
329 \r
330 /*----------------------------------------------------------------------------\r
331   Default Handler for Exceptions / Interrupts\r
332  *----------------------------------------------------------------------------*/\r
333 void Default_Handler(void)\r
334 {\r
335   while(1);\r
336 }\r
337 \r