1 //*****************************************************************************
2 // MK22F12810 startup code for use with MCUXpresso IDE
3 //
4 // Version : 160420
5 //*****************************************************************************
6 //
7 // Copyright 2016-2020 NXP
8 // All rights reserved.
9 //
10 // SPDX-License-Identifier: BSD-3-Clause
11 //*****************************************************************************
12 
13 #if defined (DEBUG)
14 #pragma GCC push_options
15 #pragma GCC optimize ("Og")
16 #endif // (DEBUG)
17 
18 #if defined (__cplusplus)
19 #ifdef __REDLIB__
20 #error Redlib does not support C++
21 #else
22 //*****************************************************************************
23 //
24 // The entry point for the C++ library startup
25 //
26 //*****************************************************************************
27 extern "C" {
28     extern void __libc_init_array(void);
29 }
30 #endif
31 #endif
32 
33 #define WEAK __attribute__ ((weak))
34 #define WEAK_AV __attribute__ ((weak, section(".after_vectors")))
35 #define ALIAS(f) __attribute__ ((weak, alias (#f)))
36 
37 //*****************************************************************************
38 #if defined (__cplusplus)
39 extern "C" {
40 #endif
41 
42 //*****************************************************************************
43 // Flash Configuration block : 16-byte flash configuration field that stores
44 // default protection settings (loaded on reset) and security information that
45 // allows the MCU to restrict access to the Flash Memory module.
46 // Placed at address 0x400 by the linker script.
47 //*****************************************************************************
48 __attribute__ ((used,section(".FlashConfig"))) const struct {
49     unsigned int word1;
50     unsigned int word2;
51     unsigned int word3;
52     unsigned int word4;
53 } Flash_Config = {0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFE};
54 //*****************************************************************************
55 // Declaration of external SystemInit function
56 //*****************************************************************************
57 #if defined (__USE_CMSIS)
58 extern void SystemInit(void);
59 #endif // (__USE_CMSIS)
60 
61 //*****************************************************************************
62 // Forward declaration of the core exception handlers.
63 // When the application defines a handler (with the same name), this will
64 // automatically take precedence over these weak definitions.
65 // If your application is a C++ one, then any interrupt handlers defined
66 // in C++ files within in your main application will need to have C linkage
67 // rather than C++ linkage. To do this, make sure that you are using extern "C"
68 // { .... } around the interrupt handler within your main application code.
69 //*****************************************************************************
70      void ResetISR(void);
71 WEAK void NMI_Handler(void);
72 WEAK void HardFault_Handler(void);
73 WEAK void MemManage_Handler(void);
74 WEAK void BusFault_Handler(void);
75 WEAK void UsageFault_Handler(void);
76 WEAK void SVC_Handler(void);
77 WEAK void DebugMon_Handler(void);
78 WEAK void PendSV_Handler(void);
79 WEAK void SysTick_Handler(void);
80 WEAK void IntDefaultHandler(void);
81 
82 //*****************************************************************************
83 // Forward declaration of the application IRQ handlers. When the application
84 // defines a handler (with the same name), this will automatically take
85 // precedence over weak definitions below
86 //*****************************************************************************
87 WEAK void DMA0_IRQHandler(void);
88 WEAK void DMA1_IRQHandler(void);
89 WEAK void DMA2_IRQHandler(void);
90 WEAK void DMA3_IRQHandler(void);
91 WEAK void Reserved20_IRQHandler(void);
92 WEAK void Reserved21_IRQHandler(void);
93 WEAK void Reserved22_IRQHandler(void);
94 WEAK void Reserved23_IRQHandler(void);
95 WEAK void Reserved24_IRQHandler(void);
96 WEAK void Reserved25_IRQHandler(void);
97 WEAK void Reserved26_IRQHandler(void);
98 WEAK void Reserved27_IRQHandler(void);
99 WEAK void Reserved28_IRQHandler(void);
100 WEAK void Reserved29_IRQHandler(void);
101 WEAK void Reserved30_IRQHandler(void);
102 WEAK void Reserved31_IRQHandler(void);
103 WEAK void DMA_Error_IRQHandler(void);
104 WEAK void MCM_IRQHandler(void);
105 WEAK void FTF_IRQHandler(void);
106 WEAK void Read_Collision_IRQHandler(void);
107 WEAK void LVD_LVW_IRQHandler(void);
108 WEAK void LLWU_IRQHandler(void);
109 WEAK void WDOG_EWM_IRQHandler(void);
110 WEAK void Reserved39_IRQHandler(void);
111 WEAK void I2C0_IRQHandler(void);
112 WEAK void I2C1_IRQHandler(void);
113 WEAK void SPI0_IRQHandler(void);
114 WEAK void SPI1_IRQHandler(void);
115 WEAK void I2S0_Tx_IRQHandler(void);
116 WEAK void I2S0_Rx_IRQHandler(void);
117 WEAK void LPUART0_IRQHandler(void);
118 WEAK void UART0_RX_TX_IRQHandler(void);
119 WEAK void UART0_ERR_IRQHandler(void);
120 WEAK void UART1_RX_TX_IRQHandler(void);
121 WEAK void UART1_ERR_IRQHandler(void);
122 WEAK void UART2_RX_TX_IRQHandler(void);
123 WEAK void UART2_ERR_IRQHandler(void);
124 WEAK void Reserved53_IRQHandler(void);
125 WEAK void Reserved54_IRQHandler(void);
126 WEAK void ADC0_IRQHandler(void);
127 WEAK void CMP0_IRQHandler(void);
128 WEAK void CMP1_IRQHandler(void);
129 WEAK void FTM0_IRQHandler(void);
130 WEAK void FTM1_IRQHandler(void);
131 WEAK void FTM2_IRQHandler(void);
132 WEAK void Reserved61_IRQHandler(void);
133 WEAK void RTC_IRQHandler(void);
134 WEAK void RTC_Seconds_IRQHandler(void);
135 WEAK void PIT0_IRQHandler(void);
136 WEAK void PIT1_IRQHandler(void);
137 WEAK void PIT2_IRQHandler(void);
138 WEAK void PIT3_IRQHandler(void);
139 WEAK void PDB0_IRQHandler(void);
140 WEAK void USB0_IRQHandler(void);
141 WEAK void Reserved70_IRQHandler(void);
142 WEAK void Reserved71_IRQHandler(void);
143 WEAK void DAC0_IRQHandler(void);
144 WEAK void MCG_IRQHandler(void);
145 WEAK void LPTMR0_IRQHandler(void);
146 WEAK void PORTA_IRQHandler(void);
147 WEAK void PORTB_IRQHandler(void);
148 WEAK void PORTC_IRQHandler(void);
149 WEAK void PORTD_IRQHandler(void);
150 WEAK void PORTE_IRQHandler(void);
151 WEAK void SWI_IRQHandler(void);
152 WEAK void Reserved81_IRQHandler(void);
153 WEAK void Reserved82_IRQHandler(void);
154 WEAK void Reserved83_IRQHandler(void);
155 WEAK void Reserved84_IRQHandler(void);
156 WEAK void Reserved85_IRQHandler(void);
157 WEAK void Reserved86_IRQHandler(void);
158 WEAK void Reserved87_IRQHandler(void);
159 WEAK void Reserved88_IRQHandler(void);
160 WEAK void ADC1_IRQHandler(void);
161 
162 //*****************************************************************************
163 // Forward declaration of the driver IRQ handlers. These are aliased
164 // to the IntDefaultHandler, which is a 'forever' loop. When the driver
165 // defines a handler (with the same name), this will automatically take
166 // precedence over these weak definitions
167 //*****************************************************************************
168 void DMA0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
169 void DMA1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
170 void DMA2_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
171 void DMA3_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
172 void Reserved20_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
173 void Reserved21_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
174 void Reserved22_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
175 void Reserved23_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
176 void Reserved24_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
177 void Reserved25_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
178 void Reserved26_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
179 void Reserved27_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
180 void Reserved28_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
181 void Reserved29_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
182 void Reserved30_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
183 void Reserved31_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
184 void DMA_Error_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
185 void MCM_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
186 void FTF_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
187 void Read_Collision_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
188 void LVD_LVW_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
189 void LLWU_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
190 void WDOG_EWM_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
191 void Reserved39_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
192 void I2C0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
193 void I2C1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
194 void SPI0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
195 void SPI1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
196 void I2S0_Tx_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
197 void I2S0_Rx_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
198 void LPUART0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
199 void UART0_RX_TX_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
200 void UART0_ERR_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
201 void UART1_RX_TX_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
202 void UART1_ERR_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
203 void UART2_RX_TX_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
204 void UART2_ERR_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
205 void Reserved53_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
206 void Reserved54_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
207 void ADC0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
208 void CMP0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
209 void CMP1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
210 void FTM0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
211 void FTM1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
212 void FTM2_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
213 void Reserved61_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
214 void RTC_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
215 void RTC_Seconds_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
216 void PIT0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
217 void PIT1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
218 void PIT2_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
219 void PIT3_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
220 void PDB0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
221 void USB0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
222 void Reserved70_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
223 void Reserved71_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
224 void DAC0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
225 void MCG_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
226 void LPTMR0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
227 void PORTA_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
228 void PORTB_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
229 void PORTC_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
230 void PORTD_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
231 void PORTE_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
232 void SWI_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
233 void Reserved81_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
234 void Reserved82_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
235 void Reserved83_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
236 void Reserved84_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
237 void Reserved85_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
238 void Reserved86_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
239 void Reserved87_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
240 void Reserved88_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
241 void ADC1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
242 
243 //*****************************************************************************
244 // The entry point for the application.
245 // __main() is the entry point for Redlib based applications
246 // main() is the entry point for Newlib based applications
247 //*****************************************************************************
248 #if defined (__REDLIB__)
249 extern void __main(void);
250 #endif
251 extern int main(void);
252 
253 //*****************************************************************************
254 // External declaration for the pointer to the stack top from the Linker Script
255 //*****************************************************************************
256 extern void _vStackTop(void);
257 //*****************************************************************************
258 #if defined (__cplusplus)
259 } // extern "C"
260 #endif
261 //*****************************************************************************
262 // The vector table.
263 // This relies on the linker script to place at correct location in memory.
264 //*****************************************************************************
265 
266 
267 
268 extern void (* const g_pfnVectors[])(void);
269 extern void * __Vectors __attribute__ ((alias ("g_pfnVectors")));
270 
271 __attribute__ ((used, section(".isr_vector")))
272 void (* const g_pfnVectors[])(void) = {
273     // Core Level - CM4
274     &_vStackTop,                       // The initial stack pointer
275     ResetISR,                          // The reset handler
276     NMI_Handler,                       // The NMI handler
277     HardFault_Handler,                 // The hard fault handler
278     MemManage_Handler,                 // The MPU fault handler
279     BusFault_Handler,                  // The bus fault handler
280     UsageFault_Handler,                // The usage fault handler
281     0,                                 // Reserved
282     0,                                 // Reserved
283     0,                                 // Reserved
284     0,                                 // Reserved
285     SVC_Handler,                       // SVCall handler
286     DebugMon_Handler,                  // Debug monitor handler
287     0,                                 // Reserved
288     PendSV_Handler,                    // The PendSV handler
289     SysTick_Handler,                   // The SysTick handler
290 
291     // Chip Level - MK22F12810
292     DMA0_IRQHandler,            // 16: DMA Channel 0 Transfer Complete
293     DMA1_IRQHandler,            // 17: DMA Channel 1 Transfer Complete
294     DMA2_IRQHandler,            // 18: DMA Channel 2 Transfer Complete
295     DMA3_IRQHandler,            // 19: DMA Channel 3 Transfer Complete
296     Reserved20_IRQHandler,      // 20: Reserved interrupt
297     Reserved21_IRQHandler,      // 21: Reserved interrupt
298     Reserved22_IRQHandler,      // 22: Reserved interrupt
299     Reserved23_IRQHandler,      // 23: Reserved interrupt
300     Reserved24_IRQHandler,      // 24: Reserved interrupt
301     Reserved25_IRQHandler,      // 25: Reserved interrupt
302     Reserved26_IRQHandler,      // 26: Reserved interrupt
303     Reserved27_IRQHandler,      // 27: Reserved interrupt
304     Reserved28_IRQHandler,      // 28: Reserved interrupt
305     Reserved29_IRQHandler,      // 29: Reserved interrupt
306     Reserved30_IRQHandler,      // 30: Reserved interrupt
307     Reserved31_IRQHandler,      // 31: Reserved interrupt
308     DMA_Error_IRQHandler,       // 32: DMA Error Interrupt
309     MCM_IRQHandler,             // 33: Normal Interrupt
310     FTF_IRQHandler,             // 34: FTFA Command complete interrupt
311     Read_Collision_IRQHandler,  // 35: Read Collision Interrupt
312     LVD_LVW_IRQHandler,         // 36: Low Voltage Detect, Low Voltage Warning
313     LLWU_IRQHandler,            // 37: Low Leakage Wakeup Unit
314     WDOG_EWM_IRQHandler,        // 38: WDOG Interrupt
315     Reserved39_IRQHandler,      // 39: Reserved interrupt
316     I2C0_IRQHandler,            // 40: I2C0 interrupt
317     I2C1_IRQHandler,            // 41: I2C1 interrupt
318     SPI0_IRQHandler,            // 42: SPI0 Interrupt
319     SPI1_IRQHandler,            // 43: SPI1 Interrupt
320     I2S0_Tx_IRQHandler,         // 44: I2S0 transmit interrupt
321     I2S0_Rx_IRQHandler,         // 45: I2S0 receive interrupt
322     LPUART0_IRQHandler,         // 46: LPUART0 status/error interrupt
323     UART0_RX_TX_IRQHandler,     // 47: UART0 Receive/Transmit interrupt
324     UART0_ERR_IRQHandler,       // 48: UART0 Error interrupt
325     UART1_RX_TX_IRQHandler,     // 49: UART1 Receive/Transmit interrupt
326     UART1_ERR_IRQHandler,       // 50: UART1 Error interrupt
327     UART2_RX_TX_IRQHandler,     // 51: UART2 Receive/Transmit interrupt
328     UART2_ERR_IRQHandler,       // 52: UART2 Error interrupt
329     Reserved53_IRQHandler,      // 53: Reserved interrupt
330     Reserved54_IRQHandler,      // 54: Reserved interrupt
331     ADC0_IRQHandler,            // 55: ADC0 interrupt
332     CMP0_IRQHandler,            // 56: CMP0 interrupt
333     CMP1_IRQHandler,            // 57: CMP1 interrupt
334     FTM0_IRQHandler,            // 58: FTM0 fault, overflow and channels interrupt
335     FTM1_IRQHandler,            // 59: FTM1 fault, overflow and channels interrupt
336     FTM2_IRQHandler,            // 60: FTM2 fault, overflow and channels interrupt
337     Reserved61_IRQHandler,      // 61: Reserved interrupt
338     RTC_IRQHandler,             // 62: RTC interrupt
339     RTC_Seconds_IRQHandler,     // 63: RTC seconds interrupt
340     PIT0_IRQHandler,            // 64: PIT timer channel 0 interrupt
341     PIT1_IRQHandler,            // 65: PIT timer channel 1 interrupt
342     PIT2_IRQHandler,            // 66: PIT timer channel 2 interrupt
343     PIT3_IRQHandler,            // 67: PIT timer channel 3 interrupt
344     PDB0_IRQHandler,            // 68: PDB0 Interrupt
345     USB0_IRQHandler,            // 69: USB0 interrupt
346     Reserved70_IRQHandler,      // 70: Reserved interrupt
347     Reserved71_IRQHandler,      // 71: Reserved interrupt
348     DAC0_IRQHandler,            // 72: DAC0 interrupt
349     MCG_IRQHandler,             // 73: MCG Interrupt
350     LPTMR0_IRQHandler,          // 74: LPTimer interrupt
351     PORTA_IRQHandler,           // 75: Port A interrupt
352     PORTB_IRQHandler,           // 76: Port B interrupt
353     PORTC_IRQHandler,           // 77: Port C interrupt
354     PORTD_IRQHandler,           // 78: Port D interrupt
355     PORTE_IRQHandler,           // 79: Port E interrupt
356     SWI_IRQHandler,             // 80: Software interrupt
357     Reserved81_IRQHandler,      // 81: Reserved interrupt
358     Reserved82_IRQHandler,      // 82: Reserved interrupt
359     Reserved83_IRQHandler,      // 83: Reserved interrupt
360     Reserved84_IRQHandler,      // 84: Reserved interrupt
361     Reserved85_IRQHandler,      // 85: Reserved interrupt
362     Reserved86_IRQHandler,      // 86: Reserved interrupt
363     Reserved87_IRQHandler,      // 87: Reserved interrupt
364     Reserved88_IRQHandler,      // 88: Reserved interrupt
365     ADC1_IRQHandler,            // 89: ADC1 interrupt
366 
367 
368 }; /* End of g_pfnVectors */
369 
370 //*****************************************************************************
371 // Functions to carry out the initialization of RW and BSS data sections. These
372 // are written as separate functions rather than being inlined within the
373 // ResetISR() function in order to cope with MCUs with multiple banks of
374 // memory.
375 //*****************************************************************************
376 __attribute__ ((section(".after_vectors.init_data")))
data_init(unsigned int romstart,unsigned int start,unsigned int len)377 void data_init(unsigned int romstart, unsigned int start, unsigned int len) {
378     unsigned int *pulDest = (unsigned int*) start;
379     unsigned int *pulSrc = (unsigned int*) romstart;
380     unsigned int loop;
381     for (loop = 0; loop < len; loop = loop + 4)
382         *pulDest++ = *pulSrc++;
383 }
384 
385 __attribute__ ((section(".after_vectors.init_bss")))
bss_init(unsigned int start,unsigned int len)386 void bss_init(unsigned int start, unsigned int len) {
387     unsigned int *pulDest = (unsigned int*) start;
388     unsigned int loop;
389     for (loop = 0; loop < len; loop = loop + 4)
390         *pulDest++ = 0;
391 }
392 
393 //*****************************************************************************
394 // The following symbols are constructs generated by the linker, indicating
395 // the location of various points in the "Global Section Table". This table is
396 // created by the linker via the Code Red managed linker script mechanism. It
397 // contains the load address, execution address and length of each RW data
398 // section and the execution and length of each BSS (zero initialized) section.
399 //*****************************************************************************
400 extern unsigned int __data_section_table;
401 extern unsigned int __data_section_table_end;
402 extern unsigned int __bss_section_table;
403 extern unsigned int __bss_section_table_end;
404 
405 //*****************************************************************************
406 // Reset entry point for your code.
407 // Sets up a simple runtime environment and initializes the C/C++
408 // library.
409 //*****************************************************************************
410 __attribute__ ((naked, section(".after_vectors.reset")))
ResetISR(void)411 void ResetISR(void) {
412 
413     // Disable interrupts
414     __asm volatile ("cpsid i");
415 
416 
417 #if defined (__USE_CMSIS)
418 // If __USE_CMSIS defined, then call CMSIS SystemInit code
419     SystemInit();
420 
421 #else
422     // Disable Watchdog
423     //  Write 0xC520 to watchdog unlock register
424     *((volatile unsigned short *)0x4005200E) = 0xC520;
425     //  Followed by 0xD928 to complete the unlock
426     *((volatile unsigned short *)0x4005200E) = 0xD928;
427     // Now disable watchdog via STCTRLH register
428     *((volatile unsigned short *)0x40052000) = 0x01D2u;
429 #endif // (__USE_CMSIS)
430 
431     //
432     // Copy the data sections from flash to SRAM.
433     //
434     unsigned int LoadAddr, ExeAddr, SectionLen;
435     unsigned int *SectionTableAddr;
436 
437     // Load base address of Global Section Table
438     SectionTableAddr = &__data_section_table;
439 
440     // Copy the data sections from flash to SRAM.
441     while (SectionTableAddr < &__data_section_table_end) {
442         LoadAddr = *SectionTableAddr++;
443         ExeAddr = *SectionTableAddr++;
444         SectionLen = *SectionTableAddr++;
445         data_init(LoadAddr, ExeAddr, SectionLen);
446     }
447 
448     // At this point, SectionTableAddr = &__bss_section_table;
449     // Zero fill the bss segment
450     while (SectionTableAddr < &__bss_section_table_end) {
451         ExeAddr = *SectionTableAddr++;
452         SectionLen = *SectionTableAddr++;
453         bss_init(ExeAddr, SectionLen);
454     }
455 
456 #if !defined (__USE_CMSIS)
457 // Assume that if __USE_CMSIS defined, then CMSIS SystemInit code
458 // will enable the FPU
459 #if defined (__VFP_FP__) && !defined (__SOFTFP__)
460     //
461     // Code to enable the Cortex-M4 FPU only included
462     // if appropriate build options have been selected.
463     // Code taken from Section 7.1, Cortex-M4 TRM (DDI0439C)
464     //
465     // Read CPACR (located at address 0xE000ED88)
466     // Set bits 20-23 to enable CP10 and CP11 coprocessors
467     // Write back the modified value to the CPACR
468     asm volatile ("LDR.W R0, =0xE000ED88\n\t"
469                   "LDR R1, [R0]\n\t"
470                   "ORR R1, R1, #(0xF << 20)\n\t"
471                   "STR R1, [R0]");
472 #endif // (__VFP_FP__) && !(__SOFTFP__)
473 #endif // (__USE_CMSIS)
474 
475 
476 #if !defined (__USE_CMSIS)
477 // Assume that if __USE_CMSIS defined, then CMSIS SystemInit code
478 // will setup the VTOR register
479 
480     // Check to see if we are running the code from a non-zero
481     // address (eg RAM, external flash), in which case we need
482     // to modify the VTOR register to tell the CPU that the
483     // vector table is located at a non-0x0 address.
484     unsigned int * pSCB_VTOR = (unsigned int *) 0xE000ED08;
485     if ((unsigned int *)g_pfnVectors!=(unsigned int *) 0x00000000) {
486         *pSCB_VTOR = (unsigned int)g_pfnVectors;
487     }
488 #endif // (__USE_CMSIS)
489 #if defined (__cplusplus)
490     //
491     // Call C++ library initialisation
492     //
493     __libc_init_array();
494 #endif
495 
496     // Reenable interrupts
497     __asm volatile ("cpsie i");
498 
499 #if defined (__REDLIB__)
500     // Call the Redlib library, which in turn calls main()
501     __main();
502 #else
503     main();
504 #endif
505 
506     //
507     // main() shouldn't return, but if it does, we'll just enter an infinite loop
508     //
509     while (1) {
510         ;
511     }
512 }
513 
514 //*****************************************************************************
515 // Default core exception handlers. Override the ones here by defining your own
516 // handler routines in your application code.
517 //*****************************************************************************
NMI_Handler(void)518 WEAK_AV void NMI_Handler(void)
519 { while(1) {}
520 }
521 
HardFault_Handler(void)522 WEAK_AV void HardFault_Handler(void)
523 { while(1) {}
524 }
525 
MemManage_Handler(void)526 WEAK_AV void MemManage_Handler(void)
527 { while(1) {}
528 }
529 
BusFault_Handler(void)530 WEAK_AV void BusFault_Handler(void)
531 { while(1) {}
532 }
533 
UsageFault_Handler(void)534 WEAK_AV void UsageFault_Handler(void)
535 { while(1) {}
536 }
537 
SVC_Handler(void)538 WEAK_AV void SVC_Handler(void)
539 { while(1) {}
540 }
541 
DebugMon_Handler(void)542 WEAK_AV void DebugMon_Handler(void)
543 { while(1) {}
544 }
545 
PendSV_Handler(void)546 WEAK_AV void PendSV_Handler(void)
547 { while(1) {}
548 }
549 
SysTick_Handler(void)550 WEAK_AV void SysTick_Handler(void)
551 { while(1) {}
552 }
553 
554 //*****************************************************************************
555 // Processor ends up here if an unexpected interrupt occurs or a specific
556 // handler is not present in the application code.
557 //*****************************************************************************
IntDefaultHandler(void)558 WEAK_AV void IntDefaultHandler(void)
559 { while(1) {}
560 }
561 
562 //*****************************************************************************
563 // Default application exception handlers. Override the ones here by defining
564 // your own handler routines in your application code. These routines call
565 // driver exception handlers or IntDefaultHandler() if no driver exception
566 // handler is included.
567 //*****************************************************************************
DMA0_IRQHandler(void)568 WEAK void DMA0_IRQHandler(void)
569 {   DMA0_DriverIRQHandler();
570 }
571 
DMA1_IRQHandler(void)572 WEAK void DMA1_IRQHandler(void)
573 {   DMA1_DriverIRQHandler();
574 }
575 
DMA2_IRQHandler(void)576 WEAK void DMA2_IRQHandler(void)
577 {   DMA2_DriverIRQHandler();
578 }
579 
DMA3_IRQHandler(void)580 WEAK void DMA3_IRQHandler(void)
581 {   DMA3_DriverIRQHandler();
582 }
583 
Reserved20_IRQHandler(void)584 WEAK void Reserved20_IRQHandler(void)
585 {   Reserved20_DriverIRQHandler();
586 }
587 
Reserved21_IRQHandler(void)588 WEAK void Reserved21_IRQHandler(void)
589 {   Reserved21_DriverIRQHandler();
590 }
591 
Reserved22_IRQHandler(void)592 WEAK void Reserved22_IRQHandler(void)
593 {   Reserved22_DriverIRQHandler();
594 }
595 
Reserved23_IRQHandler(void)596 WEAK void Reserved23_IRQHandler(void)
597 {   Reserved23_DriverIRQHandler();
598 }
599 
Reserved24_IRQHandler(void)600 WEAK void Reserved24_IRQHandler(void)
601 {   Reserved24_DriverIRQHandler();
602 }
603 
Reserved25_IRQHandler(void)604 WEAK void Reserved25_IRQHandler(void)
605 {   Reserved25_DriverIRQHandler();
606 }
607 
Reserved26_IRQHandler(void)608 WEAK void Reserved26_IRQHandler(void)
609 {   Reserved26_DriverIRQHandler();
610 }
611 
Reserved27_IRQHandler(void)612 WEAK void Reserved27_IRQHandler(void)
613 {   Reserved27_DriverIRQHandler();
614 }
615 
Reserved28_IRQHandler(void)616 WEAK void Reserved28_IRQHandler(void)
617 {   Reserved28_DriverIRQHandler();
618 }
619 
Reserved29_IRQHandler(void)620 WEAK void Reserved29_IRQHandler(void)
621 {   Reserved29_DriverIRQHandler();
622 }
623 
Reserved30_IRQHandler(void)624 WEAK void Reserved30_IRQHandler(void)
625 {   Reserved30_DriverIRQHandler();
626 }
627 
Reserved31_IRQHandler(void)628 WEAK void Reserved31_IRQHandler(void)
629 {   Reserved31_DriverIRQHandler();
630 }
631 
DMA_Error_IRQHandler(void)632 WEAK void DMA_Error_IRQHandler(void)
633 {   DMA_Error_DriverIRQHandler();
634 }
635 
MCM_IRQHandler(void)636 WEAK void MCM_IRQHandler(void)
637 {   MCM_DriverIRQHandler();
638 }
639 
FTF_IRQHandler(void)640 WEAK void FTF_IRQHandler(void)
641 {   FTF_DriverIRQHandler();
642 }
643 
Read_Collision_IRQHandler(void)644 WEAK void Read_Collision_IRQHandler(void)
645 {   Read_Collision_DriverIRQHandler();
646 }
647 
LVD_LVW_IRQHandler(void)648 WEAK void LVD_LVW_IRQHandler(void)
649 {   LVD_LVW_DriverIRQHandler();
650 }
651 
LLWU_IRQHandler(void)652 WEAK void LLWU_IRQHandler(void)
653 {   LLWU_DriverIRQHandler();
654 }
655 
WDOG_EWM_IRQHandler(void)656 WEAK void WDOG_EWM_IRQHandler(void)
657 {   WDOG_EWM_DriverIRQHandler();
658 }
659 
Reserved39_IRQHandler(void)660 WEAK void Reserved39_IRQHandler(void)
661 {   Reserved39_DriverIRQHandler();
662 }
663 
I2C0_IRQHandler(void)664 WEAK void I2C0_IRQHandler(void)
665 {   I2C0_DriverIRQHandler();
666 }
667 
I2C1_IRQHandler(void)668 WEAK void I2C1_IRQHandler(void)
669 {   I2C1_DriverIRQHandler();
670 }
671 
SPI0_IRQHandler(void)672 WEAK void SPI0_IRQHandler(void)
673 {   SPI0_DriverIRQHandler();
674 }
675 
SPI1_IRQHandler(void)676 WEAK void SPI1_IRQHandler(void)
677 {   SPI1_DriverIRQHandler();
678 }
679 
I2S0_Tx_IRQHandler(void)680 WEAK void I2S0_Tx_IRQHandler(void)
681 {   I2S0_Tx_DriverIRQHandler();
682 }
683 
I2S0_Rx_IRQHandler(void)684 WEAK void I2S0_Rx_IRQHandler(void)
685 {   I2S0_Rx_DriverIRQHandler();
686 }
687 
LPUART0_IRQHandler(void)688 WEAK void LPUART0_IRQHandler(void)
689 {   LPUART0_DriverIRQHandler();
690 }
691 
UART0_RX_TX_IRQHandler(void)692 WEAK void UART0_RX_TX_IRQHandler(void)
693 {   UART0_RX_TX_DriverIRQHandler();
694 }
695 
UART0_ERR_IRQHandler(void)696 WEAK void UART0_ERR_IRQHandler(void)
697 {   UART0_ERR_DriverIRQHandler();
698 }
699 
UART1_RX_TX_IRQHandler(void)700 WEAK void UART1_RX_TX_IRQHandler(void)
701 {   UART1_RX_TX_DriverIRQHandler();
702 }
703 
UART1_ERR_IRQHandler(void)704 WEAK void UART1_ERR_IRQHandler(void)
705 {   UART1_ERR_DriverIRQHandler();
706 }
707 
UART2_RX_TX_IRQHandler(void)708 WEAK void UART2_RX_TX_IRQHandler(void)
709 {   UART2_RX_TX_DriverIRQHandler();
710 }
711 
UART2_ERR_IRQHandler(void)712 WEAK void UART2_ERR_IRQHandler(void)
713 {   UART2_ERR_DriverIRQHandler();
714 }
715 
Reserved53_IRQHandler(void)716 WEAK void Reserved53_IRQHandler(void)
717 {   Reserved53_DriverIRQHandler();
718 }
719 
Reserved54_IRQHandler(void)720 WEAK void Reserved54_IRQHandler(void)
721 {   Reserved54_DriverIRQHandler();
722 }
723 
ADC0_IRQHandler(void)724 WEAK void ADC0_IRQHandler(void)
725 {   ADC0_DriverIRQHandler();
726 }
727 
CMP0_IRQHandler(void)728 WEAK void CMP0_IRQHandler(void)
729 {   CMP0_DriverIRQHandler();
730 }
731 
CMP1_IRQHandler(void)732 WEAK void CMP1_IRQHandler(void)
733 {   CMP1_DriverIRQHandler();
734 }
735 
FTM0_IRQHandler(void)736 WEAK void FTM0_IRQHandler(void)
737 {   FTM0_DriverIRQHandler();
738 }
739 
FTM1_IRQHandler(void)740 WEAK void FTM1_IRQHandler(void)
741 {   FTM1_DriverIRQHandler();
742 }
743 
FTM2_IRQHandler(void)744 WEAK void FTM2_IRQHandler(void)
745 {   FTM2_DriverIRQHandler();
746 }
747 
Reserved61_IRQHandler(void)748 WEAK void Reserved61_IRQHandler(void)
749 {   Reserved61_DriverIRQHandler();
750 }
751 
RTC_IRQHandler(void)752 WEAK void RTC_IRQHandler(void)
753 {   RTC_DriverIRQHandler();
754 }
755 
RTC_Seconds_IRQHandler(void)756 WEAK void RTC_Seconds_IRQHandler(void)
757 {   RTC_Seconds_DriverIRQHandler();
758 }
759 
PIT0_IRQHandler(void)760 WEAK void PIT0_IRQHandler(void)
761 {   PIT0_DriverIRQHandler();
762 }
763 
PIT1_IRQHandler(void)764 WEAK void PIT1_IRQHandler(void)
765 {   PIT1_DriverIRQHandler();
766 }
767 
PIT2_IRQHandler(void)768 WEAK void PIT2_IRQHandler(void)
769 {   PIT2_DriverIRQHandler();
770 }
771 
PIT3_IRQHandler(void)772 WEAK void PIT3_IRQHandler(void)
773 {   PIT3_DriverIRQHandler();
774 }
775 
PDB0_IRQHandler(void)776 WEAK void PDB0_IRQHandler(void)
777 {   PDB0_DriverIRQHandler();
778 }
779 
USB0_IRQHandler(void)780 WEAK void USB0_IRQHandler(void)
781 {   USB0_DriverIRQHandler();
782 }
783 
Reserved70_IRQHandler(void)784 WEAK void Reserved70_IRQHandler(void)
785 {   Reserved70_DriverIRQHandler();
786 }
787 
Reserved71_IRQHandler(void)788 WEAK void Reserved71_IRQHandler(void)
789 {   Reserved71_DriverIRQHandler();
790 }
791 
DAC0_IRQHandler(void)792 WEAK void DAC0_IRQHandler(void)
793 {   DAC0_DriverIRQHandler();
794 }
795 
MCG_IRQHandler(void)796 WEAK void MCG_IRQHandler(void)
797 {   MCG_DriverIRQHandler();
798 }
799 
LPTMR0_IRQHandler(void)800 WEAK void LPTMR0_IRQHandler(void)
801 {   LPTMR0_DriverIRQHandler();
802 }
803 
PORTA_IRQHandler(void)804 WEAK void PORTA_IRQHandler(void)
805 {   PORTA_DriverIRQHandler();
806 }
807 
PORTB_IRQHandler(void)808 WEAK void PORTB_IRQHandler(void)
809 {   PORTB_DriverIRQHandler();
810 }
811 
PORTC_IRQHandler(void)812 WEAK void PORTC_IRQHandler(void)
813 {   PORTC_DriverIRQHandler();
814 }
815 
PORTD_IRQHandler(void)816 WEAK void PORTD_IRQHandler(void)
817 {   PORTD_DriverIRQHandler();
818 }
819 
PORTE_IRQHandler(void)820 WEAK void PORTE_IRQHandler(void)
821 {   PORTE_DriverIRQHandler();
822 }
823 
SWI_IRQHandler(void)824 WEAK void SWI_IRQHandler(void)
825 {   SWI_DriverIRQHandler();
826 }
827 
Reserved81_IRQHandler(void)828 WEAK void Reserved81_IRQHandler(void)
829 {   Reserved81_DriverIRQHandler();
830 }
831 
Reserved82_IRQHandler(void)832 WEAK void Reserved82_IRQHandler(void)
833 {   Reserved82_DriverIRQHandler();
834 }
835 
Reserved83_IRQHandler(void)836 WEAK void Reserved83_IRQHandler(void)
837 {   Reserved83_DriverIRQHandler();
838 }
839 
Reserved84_IRQHandler(void)840 WEAK void Reserved84_IRQHandler(void)
841 {   Reserved84_DriverIRQHandler();
842 }
843 
Reserved85_IRQHandler(void)844 WEAK void Reserved85_IRQHandler(void)
845 {   Reserved85_DriverIRQHandler();
846 }
847 
Reserved86_IRQHandler(void)848 WEAK void Reserved86_IRQHandler(void)
849 {   Reserved86_DriverIRQHandler();
850 }
851 
Reserved87_IRQHandler(void)852 WEAK void Reserved87_IRQHandler(void)
853 {   Reserved87_DriverIRQHandler();
854 }
855 
Reserved88_IRQHandler(void)856 WEAK void Reserved88_IRQHandler(void)
857 {   Reserved88_DriverIRQHandler();
858 }
859 
ADC1_IRQHandler(void)860 WEAK void ADC1_IRQHandler(void)
861 {   ADC1_DriverIRQHandler();
862 }
863 
864 //*****************************************************************************
865 
866 #if defined (DEBUG)
867 #pragma GCC pop_options
868 #endif // (DEBUG)
869