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
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
150 void FPUEH_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
\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
176 /* 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
216 FPUEH_IRQHandler, /* 39 - FPUEH */
\r
221 /*----------------------------------------------------------------------------
\r
222 Reset Handler called on controller reset
\r
223 *----------------------------------------------------------------------------*/
\r
224 void Reset_Handler(void) {
\r
225 uint32_t *pSrc, *pDest;
\r
226 uint32_t *pTable __attribute__((unused));
\r
228 #ifndef __NO_SYSTEM_INIT
\r
232 /* Firstly it copies data from read only memory to RAM. There are two schemes
\r
233 * to copy. One can copy more than one sections. Another can only copy
\r
234 * one section. The former scheme needs more instructions and read-only
\r
235 * data to implement than the latter.
\r
236 * Macro __STARTUP_COPY_MULTIPLE is used to choose between two schemes. */
\r
238 #ifdef __STARTUP_COPY_MULTIPLE
\r
239 /* Multiple sections scheme.
\r
241 * Between symbol address __copy_table_start__ and __copy_table_end__,
\r
242 * there are array of triplets, each of which specify:
\r
243 * offset 0: LMA of start of a section to copy from
\r
244 * offset 4: VMA of start of a section to copy to
\r
245 * offset 8: size of the section to copy. Must be multiply of 4
\r
247 * All addresses must be aligned to 4 bytes boundary.
\r
249 pTable = &__copy_table_start__;
\r
251 for (; pTable < &__copy_table_end__; pTable = pTable + 3)
\r
253 pSrc = (uint32_t*)*(pTable + 0);
\r
254 pDest = (uint32_t*)*(pTable + 1);
\r
255 for (; pDest < (uint32_t*)(*(pTable + 1) + *(pTable + 2)) ; )
\r
257 *pDest++ = *pSrc++;
\r
261 /* Single section scheme.
\r
263 * The ranges of copy from/to are specified by following symbols
\r
264 * __etext: LMA of start of the section to copy from. Usually end of text
\r
265 * __data_start__: VMA of start of the section to copy to
\r
266 * __data_end__: VMA of end of the section to copy to
\r
268 * All addresses must be aligned to 4 bytes boundary.
\r
271 pDest = &__data_start__;
\r
273 for ( ; pDest < &__data_end__ ; )
\r
275 *pDest++ = *pSrc++;
\r
277 #endif /*__STARTUP_COPY_MULTIPLE */
\r
279 /* This part of work usually is done in C library startup code. Otherwise,
\r
280 * define this macro to enable it in this startup.
\r
282 * There are two schemes too. One can clear multiple BSS sections. Another
\r
283 * can only clear one section. The former is more size expensive than the
\r
286 * Define macro __STARTUP_CLEAR_BSS_MULTIPLE to choose the former.
\r
287 * Otherwise efine macro __STARTUP_CLEAR_BSS to choose the later.
\r
289 #ifdef __STARTUP_CLEAR_BSS_MULTIPLE
\r
290 /* Multiple sections scheme.
\r
292 * Between symbol address __copy_table_start__ and __copy_table_end__,
\r
293 * there are array of tuples specifying:
\r
294 * offset 0: Start of a BSS section
\r
295 * offset 4: Size of this BSS section. Must be multiply of 4
\r
297 pTable = &__zero_table_start__;
\r
299 for (; pTable < &__zero_table_end__; pTable = pTable + 2)
\r
301 pDest = (uint32_t*)*(pTable + 0);
\r
302 for (; pDest < (uint32_t*)(*(pTable + 0) + *(pTable + 1)) ; )
\r
307 #elif defined (__STARTUP_CLEAR_BSS)
\r
308 /* Single BSS section scheme.
\r
310 * The BSS section is specified by following symbols
\r
311 * __bss_start__: start of the BSS section.
\r
312 * __bss_end__: end of the BSS section.
\r
314 * Both addresses must be aligned to 4 bytes boundary.
\r
316 pDest = &__bss_start__;
\r
318 for ( ; pDest < &__bss_end__ ; )
\r
322 #endif /* __STARTUP_CLEAR_BSS_MULTIPLE || __STARTUP_CLEAR_BSS */
\r
325 #define __START _start
\r
331 /*----------------------------------------------------------------------------
\r
332 Default Handler for Exceptions / Interrupts
\r
333 *----------------------------------------------------------------------------*/
\r
334 void Default_Handler(void)
\r