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
9 /* Copyright (c) 2011 - 2014 ARM LIMITED
\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
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
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
53 /*----------------------------------------------------------------------------
\r
54 Exception / Interrupt Handler Function Prototype
\r
55 *----------------------------------------------------------------------------*/
\r
56 typedef void( *pFunc )( void );
\r
59 /*----------------------------------------------------------------------------
\r
61 *----------------------------------------------------------------------------*/
\r
63 extern void _start(void) __attribute__((noreturn)); /* Pre Main (C library entry point) */
\r
65 extern int __START(void) __attribute__((noreturn)); /* main entry point */
\r
68 #ifndef __NO_SYSTEM_INIT
\r
69 extern void SystemInit (void); /* CMSIS System Initialization */
\r
73 /*----------------------------------------------------------------------------
\r
75 *----------------------------------------------------------------------------*/
\r
76 void Default_Handler(void); /* Default empty handler */
\r
77 void Reset_Handler(void); /* Reset Handler */
\r
80 /*----------------------------------------------------------------------------
\r
81 User Initial Stack & Heap
\r
82 *----------------------------------------------------------------------------*/
\r
83 #ifndef __STACK_SIZE
\r
84 #define __STACK_SIZE 0x00000400
\r
86 static uint8_t stack[__STACK_SIZE] __attribute__ ((aligned(8), used, section(".stack")));
\r
89 #define __HEAP_SIZE 0x00000C00
\r
92 static uint8_t heap[__HEAP_SIZE] __attribute__ ((aligned(8), used, section(".heap")));
\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
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
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
175 /* External interrupts */
\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
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
227 #ifndef __NO_SYSTEM_INIT
\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
237 #ifdef __STARTUP_COPY_MULTIPLE
\r
238 /* Multiple sections scheme.
\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
246 * All addresses must be aligned to 4 bytes boundary.
\r
248 pTable = &__copy_table_start__;
\r
250 for (; pTable < &__copy_table_end__; pTable = pTable + 3)
\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
256 *pDest++ = *pSrc++;
\r
260 /* Single section scheme.
\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
267 * All addresses must be aligned to 4 bytes boundary.
\r
270 pDest = &__data_start__;
\r
272 for ( ; pDest < &__data_end__ ; )
\r
274 *pDest++ = *pSrc++;
\r
276 #endif /*__STARTUP_COPY_MULTIPLE */
\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
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
285 * Define macro __STARTUP_CLEAR_BSS_MULTIPLE to choose the former.
\r
286 * Otherwise efine macro __STARTUP_CLEAR_BSS to choose the later.
\r
288 #ifdef __STARTUP_CLEAR_BSS_MULTIPLE
\r
289 /* Multiple sections scheme.
\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
296 pTable = &__zero_table_start__;
\r
298 for (; pTable < &__zero_table_end__; pTable = pTable + 2)
\r
300 pDest = (uint32_t*)*(pTable + 0);
\r
301 for (; pDest < (uint32_t*)(*(pTable + 0) + *(pTable + 1)) ; )
\r
306 #elif defined (__STARTUP_CLEAR_BSS)
\r
307 /* Single BSS section scheme.
\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
313 * Both addresses must be aligned to 4 bytes boundary.
\r
315 pDest = &__bss_start__;
\r
317 for ( ; pDest < &__bss_end__ ; )
\r
321 #endif /* __STARTUP_CLEAR_BSS_MULTIPLE || __STARTUP_CLEAR_BSS */
\r
324 #define __START _start
\r
330 /*----------------------------------------------------------------------------
\r
331 Default Handler for Exceptions / Interrupts
\r
332 *----------------------------------------------------------------------------*/
\r
333 void Default_Handler(void)
\r