2 * @file startup_efm32pg1b.c
\r
3 * @brief CMSIS Compatible EFM32PG1B 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
38 /*----------------------------------------------------------------------------
\r
39 Linker generated Symbols
\r
40 *----------------------------------------------------------------------------*/
\r
41 extern uint32_t __etext;
\r
42 extern uint32_t __data_start__;
\r
43 extern uint32_t __data_end__;
\r
44 extern uint32_t __copy_table_start__;
\r
45 extern uint32_t __copy_table_end__;
\r
46 extern uint32_t __zero_table_start__;
\r
47 extern uint32_t __zero_table_end__;
\r
48 extern uint32_t __bss_start__;
\r
49 extern uint32_t __bss_end__;
\r
50 extern uint32_t __StackTop;
\r
52 /*----------------------------------------------------------------------------
\r
53 Exception / Interrupt Handler Function Prototype
\r
54 *----------------------------------------------------------------------------*/
\r
55 typedef void( *pFunc )( void );
\r
58 /*----------------------------------------------------------------------------
\r
60 *----------------------------------------------------------------------------*/
\r
62 extern void _start(void) __attribute__((noreturn)); /* Pre Main (C library entry point) */
\r
64 extern int __START(void) __attribute__((noreturn)); /* main entry point */
\r
67 #ifndef __NO_SYSTEM_INIT
\r
68 extern void SystemInit (void); /* CMSIS System Initialization */
\r
72 /*----------------------------------------------------------------------------
\r
74 *----------------------------------------------------------------------------*/
\r
75 void Default_Handler(void); /* Default empty handler */
\r
76 void Reset_Handler(void); /* Reset Handler */
\r
79 /*----------------------------------------------------------------------------
\r
80 User Initial Stack & Heap
\r
81 *----------------------------------------------------------------------------*/
\r
82 #ifndef __STACK_SIZE
\r
83 #define __STACK_SIZE 0x00000400
\r
85 static uint8_t stack[__STACK_SIZE] __attribute__ ((aligned(8), used, section(".stack")));
\r
88 #define __HEAP_SIZE 0x00000C00
\r
91 static uint8_t heap[__HEAP_SIZE] __attribute__ ((aligned(8), used, section(".heap")));
\r
95 /*----------------------------------------------------------------------------
\r
96 Exception / Interrupt Handler
\r
97 *----------------------------------------------------------------------------*/
\r
98 /* Cortex-M Processor Exceptions */
\r
99 void NMI_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
\r
100 void HardFault_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
\r
101 void MemManage_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
\r
102 void BusFault_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
\r
103 void UsageFault_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
\r
104 void DebugMon_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
\r
105 void SVC_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
\r
106 void PendSV_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
\r
107 void SysTick_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
\r
109 /* Part Specific Interrupts */
\r
111 void EMU_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
\r
112 void WDOG0_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
\r
113 void LDMA_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
\r
114 void GPIO_EVEN_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
\r
115 void TIMER0_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
\r
116 void USART0_RX_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
\r
117 void USART0_TX_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
\r
118 void ACMP0_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
\r
119 void ADC0_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
\r
120 void IDAC0_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
\r
121 void I2C0_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 USART1_RX_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
\r
125 void USART1_TX_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
\r
126 void LEUART0_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
\r
127 void PCNT0_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
\r
128 void CMU_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
\r
129 void MSC_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
\r
130 void CRYPTO_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
\r
131 void LETIMER0_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
\r
132 void RTCC_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
\r
133 void CRYOTIMER_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
\r
134 void FPUEH_IRQHandler(void) __attribute__ ((weak, alias("Default_Handler")));
\r
137 /*----------------------------------------------------------------------------
\r
138 Exception / Interrupt Vector table
\r
139 *----------------------------------------------------------------------------*/
\r
140 const pFunc __Vectors[] __attribute__ ((section(".vectors"))) = {
\r
141 /* Cortex-M Exception Handlers */
\r
142 (pFunc)&__StackTop, /* Initial Stack Pointer */
\r
143 Reset_Handler, /* Reset Handler */
\r
144 NMI_Handler, /* NMI Handler */
\r
145 HardFault_Handler, /* Hard Fault Handler */
\r
146 MemManage_Handler, /* MPU Fault Handler */
\r
147 BusFault_Handler, /* Bus Fault Handler */
\r
148 UsageFault_Handler, /* Usage Fault Handler */
\r
149 Default_Handler, /* Reserved */
\r
150 Default_Handler, /* Reserved */
\r
151 Default_Handler, /* Reserved */
\r
152 Default_Handler, /* Reserved */
\r
153 SVC_Handler, /* SVCall Handler */
\r
154 DebugMon_Handler, /* Debug Monitor Handler */
\r
155 Default_Handler, /* Reserved */
\r
156 PendSV_Handler, /* PendSV Handler */
\r
157 SysTick_Handler, /* SysTick Handler */
\r
159 /* External interrupts */
\r
161 EMU_IRQHandler, /* 0 - EMU */
\r
162 Default_Handler, /* 1 - Reserved */
\r
163 WDOG0_IRQHandler, /* 2 - WDOG0 */
\r
164 Default_Handler, /* 3 - Reserved */
\r
165 Default_Handler, /* 4 - Reserved */
\r
166 Default_Handler, /* 5 - Reserved */
\r
167 Default_Handler, /* 6 - Reserved */
\r
168 Default_Handler, /* 7 - Reserved */
\r
169 LDMA_IRQHandler, /* 8 - LDMA */
\r
170 GPIO_EVEN_IRQHandler, /* 9 - GPIO_EVEN */
\r
171 TIMER0_IRQHandler, /* 10 - TIMER0 */
\r
172 USART0_RX_IRQHandler, /* 11 - USART0_RX */
\r
173 USART0_TX_IRQHandler, /* 12 - USART0_TX */
\r
174 ACMP0_IRQHandler, /* 13 - ACMP0 */
\r
175 ADC0_IRQHandler, /* 14 - ADC0 */
\r
176 IDAC0_IRQHandler, /* 15 - IDAC0 */
\r
177 I2C0_IRQHandler, /* 16 - I2C0 */
\r
178 GPIO_ODD_IRQHandler, /* 17 - GPIO_ODD */
\r
179 TIMER1_IRQHandler, /* 18 - TIMER1 */
\r
180 USART1_RX_IRQHandler, /* 19 - USART1_RX */
\r
181 USART1_TX_IRQHandler, /* 20 - USART1_TX */
\r
182 LEUART0_IRQHandler, /* 21 - LEUART0 */
\r
183 PCNT0_IRQHandler, /* 22 - PCNT0 */
\r
184 CMU_IRQHandler, /* 23 - CMU */
\r
185 MSC_IRQHandler, /* 24 - MSC */
\r
186 CRYPTO_IRQHandler, /* 25 - CRYPTO */
\r
187 LETIMER0_IRQHandler, /* 26 - LETIMER0 */
\r
188 Default_Handler, /* 27 - Reserved */
\r
189 Default_Handler, /* 28 - Reserved */
\r
190 RTCC_IRQHandler, /* 29 - RTCC */
\r
191 Default_Handler, /* 30 - Reserved */
\r
192 CRYOTIMER_IRQHandler, /* 31 - CRYOTIMER */
\r
193 Default_Handler, /* 32 - Reserved */
\r
194 FPUEH_IRQHandler, /* 33 - FPUEH */
\r
198 /*----------------------------------------------------------------------------
\r
199 Reset Handler called on controller reset
\r
200 *----------------------------------------------------------------------------*/
\r
201 void Reset_Handler(void) {
\r
202 uint32_t *pSrc, *pDest;
\r
203 uint32_t *pTable __attribute__((unused));
\r
205 #ifndef __NO_SYSTEM_INIT
\r
209 /* Firstly it copies data from read only memory to RAM. There are two schemes
\r
210 * to copy. One can copy more than one sections. Another can only copy
\r
211 * one section. The former scheme needs more instructions and read-only
\r
212 * data to implement than the latter.
\r
213 * Macro __STARTUP_COPY_MULTIPLE is used to choose between two schemes. */
\r
215 #ifdef __STARTUP_COPY_MULTIPLE
\r
216 /* Multiple sections scheme.
\r
218 * Between symbol address __copy_table_start__ and __copy_table_end__,
\r
219 * there are array of triplets, each of which specify:
\r
220 * offset 0: LMA of start of a section to copy from
\r
221 * offset 4: VMA of start of a section to copy to
\r
222 * offset 8: size of the section to copy. Must be multiply of 4
\r
224 * All addresses must be aligned to 4 bytes boundary.
\r
226 pTable = &__copy_table_start__;
\r
228 for (; pTable < &__copy_table_end__; pTable = pTable + 3)
\r
230 pSrc = (uint32_t*)*(pTable + 0);
\r
231 pDest = (uint32_t*)*(pTable + 1);
\r
232 for (; pDest < (uint32_t*)(*(pTable + 1) + *(pTable + 2)) ; )
\r
234 *pDest++ = *pSrc++;
\r
238 /* Single section scheme.
\r
240 * The ranges of copy from/to are specified by following symbols
\r
241 * __etext: LMA of start of the section to copy from. Usually end of text
\r
242 * __data_start__: VMA of start of the section to copy to
\r
243 * __data_end__: VMA of end of the section to copy to
\r
245 * All addresses must be aligned to 4 bytes boundary.
\r
248 pDest = &__data_start__;
\r
250 for ( ; pDest < &__data_end__ ; )
\r
252 *pDest++ = *pSrc++;
\r
254 #endif /*__STARTUP_COPY_MULTIPLE */
\r
256 /* This part of work usually is done in C library startup code. Otherwise,
\r
257 * define this macro to enable it in this startup.
\r
259 * There are two schemes too. One can clear multiple BSS sections. Another
\r
260 * can only clear one section. The former is more size expensive than the
\r
263 * Define macro __STARTUP_CLEAR_BSS_MULTIPLE to choose the former.
\r
264 * Otherwise efine macro __STARTUP_CLEAR_BSS to choose the later.
\r
266 #ifdef __STARTUP_CLEAR_BSS_MULTIPLE
\r
267 /* Multiple sections scheme.
\r
269 * Between symbol address __copy_table_start__ and __copy_table_end__,
\r
270 * there are array of tuples specifying:
\r
271 * offset 0: Start of a BSS section
\r
272 * offset 4: Size of this BSS section. Must be multiply of 4
\r
274 pTable = &__zero_table_start__;
\r
276 for (; pTable < &__zero_table_end__; pTable = pTable + 2)
\r
278 pDest = (uint32_t*)*(pTable + 0);
\r
279 for (; pDest < (uint32_t*)(*(pTable + 0) + *(pTable + 1)) ; )
\r
284 #elif defined (__STARTUP_CLEAR_BSS)
\r
285 /* Single BSS section scheme.
\r
287 * The BSS section is specified by following symbols
\r
288 * __bss_start__: start of the BSS section.
\r
289 * __bss_end__: end of the BSS section.
\r
291 * Both addresses must be aligned to 4 bytes boundary.
\r
293 pDest = &__bss_start__;
\r
295 for ( ; pDest < &__bss_end__ ; )
\r
299 #endif /* __STARTUP_CLEAR_BSS_MULTIPLE || __STARTUP_CLEAR_BSS */
\r
302 #define __START _start
\r
308 /*----------------------------------------------------------------------------
\r
309 Default Handler for Exceptions / Interrupts
\r
310 *----------------------------------------------------------------------------*/
\r
311 void Default_Handler(void)
\r