1 //*****************************************************************************
2 // MKE14F16 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, 0xFFFF7DFE};
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 DMA4_IRQHandler(void);
92 WEAK void DMA5_IRQHandler(void);
93 WEAK void DMA6_IRQHandler(void);
94 WEAK void DMA7_IRQHandler(void);
95 WEAK void DMA8_IRQHandler(void);
96 WEAK void DMA9_IRQHandler(void);
97 WEAK void DMA10_IRQHandler(void);
98 WEAK void DMA11_IRQHandler(void);
99 WEAK void DMA12_IRQHandler(void);
100 WEAK void DMA13_IRQHandler(void);
101 WEAK void DMA14_IRQHandler(void);
102 WEAK void DMA15_IRQHandler(void);
103 WEAK void DMA_Error_IRQHandler(void);
104 WEAK void MCM_IRQHandler(void);
105 WEAK void FTFE_IRQHandler(void);
106 WEAK void Read_Collision_IRQHandler(void);
107 WEAK void LVD_LVW_IRQHandler(void);
108 WEAK void Doublebit_Fault_IRQHandler(void);
109 WEAK void WDOG_EWM_IRQHandler(void);
110 WEAK void Reserved39_IRQHandler(void);
111 WEAK void LPI2C0_IRQHandler(void);
112 WEAK void LPI2C1_IRQHandler(void);
113 WEAK void LPSPI0_IRQHandler(void);
114 WEAK void LPSPI1_IRQHandler(void);
115 WEAK void Reserved44_IRQHandler(void);
116 WEAK void PWT_IRQHandler(void);
117 WEAK void Reserved46_IRQHandler(void);
118 WEAK void LPUART0_TX_IRQHandler(void);
119 WEAK void LPUART0_RX_IRQHandler(void);
120 WEAK void LPUART1_TX_IRQHandler(void);
121 WEAK void LPUART1_RX_IRQHandler(void);
122 WEAK void LPUART2_TX_IRQHandler(void);
123 WEAK void LPUART2_RX_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 LPIT0_Ch0_IRQHandler(void);
136 WEAK void LPIT0_Ch1_IRQHandler(void);
137 WEAK void LPIT0_Ch2_IRQHandler(void);
138 WEAK void LPIT0_Ch3_IRQHandler(void);
139 WEAK void PDB0_IRQHandler(void);
140 WEAK void Reserved69_IRQHandler(void);
141 WEAK void Reserved70_IRQHandler(void);
142 WEAK void Reserved71_IRQHandler(void);
143 WEAK void DAC0_IRQHandler(void);
144 WEAK void SCG_RCM_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 PDB1_IRQHandler(void);
156 WEAK void FLEXIO_IRQHandler(void);
157 WEAK void CMP2_IRQHandler(void);
158 WEAK void FTM3_IRQHandler(void);
159 WEAK void Reserved88_IRQHandler(void);
160 WEAK void ADC1_IRQHandler(void);
161 WEAK void ADC2_IRQHandler(void);
162 WEAK void Reserved91_IRQHandler(void);
163 WEAK void Reserved92_IRQHandler(void);
164 WEAK void PDB2_IRQHandler(void);
165 
166 //*****************************************************************************
167 // Forward declaration of the driver IRQ handlers. These are aliased
168 // to the IntDefaultHandler, which is a 'forever' loop. When the driver
169 // defines a handler (with the same name), this will automatically take
170 // precedence over these weak definitions
171 //*****************************************************************************
172 void DMA0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
173 void DMA1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
174 void DMA2_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
175 void DMA3_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
176 void DMA4_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
177 void DMA5_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
178 void DMA6_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
179 void DMA7_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
180 void DMA8_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
181 void DMA9_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
182 void DMA10_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
183 void DMA11_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
184 void DMA12_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
185 void DMA13_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
186 void DMA14_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
187 void DMA15_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
188 void DMA_Error_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
189 void MCM_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
190 void FTFE_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
191 void Read_Collision_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
192 void LVD_LVW_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
193 void Doublebit_Fault_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
194 void WDOG_EWM_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
195 void Reserved39_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
196 void LPI2C0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
197 void LPI2C1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
198 void LPSPI0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
199 void LPSPI1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
200 void Reserved44_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
201 void PWT_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
202 void Reserved46_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
203 void LPUART0_TX_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
204 void LPUART0_RX_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
205 void LPUART1_TX_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
206 void LPUART1_RX_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
207 void LPUART2_TX_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
208 void LPUART2_RX_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
209 void Reserved53_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
210 void Reserved54_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
211 void ADC0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
212 void CMP0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
213 void CMP1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
214 void FTM0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
215 void FTM1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
216 void FTM2_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
217 void Reserved61_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
218 void RTC_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
219 void RTC_Seconds_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
220 void LPIT0_Ch0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
221 void LPIT0_Ch1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
222 void LPIT0_Ch2_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
223 void LPIT0_Ch3_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
224 void PDB0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
225 void Reserved69_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
226 void Reserved70_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
227 void Reserved71_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
228 void DAC0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
229 void SCG_RCM_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
230 void LPTMR0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
231 void PORTA_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
232 void PORTB_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
233 void PORTC_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
234 void PORTD_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
235 void PORTE_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
236 void SWI_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
237 void Reserved81_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
238 void Reserved82_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
239 void Reserved83_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
240 void PDB1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
241 void FLEXIO_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
242 void CMP2_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
243 void FTM3_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
244 void Reserved88_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
245 void ADC1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
246 void ADC2_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
247 void Reserved91_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
248 void Reserved92_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
249 void PDB2_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
250 
251 //*****************************************************************************
252 // The entry point for the application.
253 // __main() is the entry point for Redlib based applications
254 // main() is the entry point for Newlib based applications
255 //*****************************************************************************
256 #if defined (__REDLIB__)
257 extern void __main(void);
258 #endif
259 extern int main(void);
260 
261 //*****************************************************************************
262 // External declaration for the pointer to the stack top from the Linker Script
263 //*****************************************************************************
264 extern void _vStackTop(void);
265 //*****************************************************************************
266 #if defined (__cplusplus)
267 } // extern "C"
268 #endif
269 //*****************************************************************************
270 // The vector table.
271 // This relies on the linker script to place at correct location in memory.
272 //*****************************************************************************
273 
274 
275 
276 extern void (* const g_pfnVectors[])(void);
277 extern void * __Vectors __attribute__ ((alias ("g_pfnVectors")));
278 
279 __attribute__ ((used, section(".isr_vector")))
280 void (* const g_pfnVectors[])(void) = {
281     // Core Level - CM4
282     &_vStackTop,                       // The initial stack pointer
283     ResetISR,                          // The reset handler
284     NMI_Handler,                       // The NMI handler
285     HardFault_Handler,                 // The hard fault handler
286     MemManage_Handler,                 // The MPU fault handler
287     BusFault_Handler,                  // The bus fault handler
288     UsageFault_Handler,                // The usage fault handler
289     0,                                 // Reserved
290     0,                                 // Reserved
291     0,                                 // Reserved
292     0,                                 // Reserved
293     SVC_Handler,                       // SVCall handler
294     DebugMon_Handler,                  // Debug monitor handler
295     0,                                 // Reserved
296     PendSV_Handler,                    // The PendSV handler
297     SysTick_Handler,                   // The SysTick handler
298 
299     // Chip Level - MKE14F16
300     DMA0_IRQHandler,             // 16: DMA channel 0 transfer complete
301     DMA1_IRQHandler,             // 17: DMA channel 1 transfer complete
302     DMA2_IRQHandler,             // 18: DMA channel 2 transfer complete
303     DMA3_IRQHandler,             // 19: DMA channel 3 transfer complete
304     DMA4_IRQHandler,             // 20: DMA channel 4 transfer complete
305     DMA5_IRQHandler,             // 21: DMA channel 5 transfer complete
306     DMA6_IRQHandler,             // 22: DMA channel 6 transfer complete
307     DMA7_IRQHandler,             // 23: DMA channel 7 transfer complete
308     DMA8_IRQHandler,             // 24: DMA channel 8 transfer complete
309     DMA9_IRQHandler,             // 25: DMA channel 9 transfer complete
310     DMA10_IRQHandler,            // 26: DMA channel 10 transfer complete
311     DMA11_IRQHandler,            // 27: DMA channel 11 transfer complete
312     DMA12_IRQHandler,            // 28: DMA channel 12 transfer complete
313     DMA13_IRQHandler,            // 29: DMA channel 13 transfer complete
314     DMA14_IRQHandler,            // 30: DMA channel 14 transfer complete
315     DMA15_IRQHandler,            // 31: DMA channel 15 transfer complete
316     DMA_Error_IRQHandler,        // 32: DMA error interrupt channels 0-15
317     MCM_IRQHandler,              // 33: FPU sources
318     FTFE_IRQHandler,             // 34: FTFE command complete
319     Read_Collision_IRQHandler,   // 35: FTFE read collision
320     LVD_LVW_IRQHandler,          // 36: PMC controller low-voltage detect, low-voltage warning
321     Doublebit_Fault_IRQHandler,  // 37: FTFE double bit fault detect
322     WDOG_EWM_IRQHandler,         // 38: Single interrupt vector for WDOG and EWM
323     Reserved39_IRQHandler,       // 39: Reserved interrupt
324     LPI2C0_IRQHandler,           // 40: Inter-integrated circuit 0 interrupt
325     LPI2C1_IRQHandler,           // 41: Inter-integrated circuit 1 interrupt
326     LPSPI0_IRQHandler,           // 42: Serial peripheral Interface 0 interrupt
327     LPSPI1_IRQHandler,           // 43: Serial peripheral Interface 1 interrupt
328     Reserved44_IRQHandler,       // 44: Reserved interrupt
329     PWT_IRQHandler,              // 45: PWT interrupt
330     Reserved46_IRQHandler,       // 46: Reserved interrupt
331     LPUART0_TX_IRQHandler,       // 47: LPUART0 transmit interrupt
332     LPUART0_RX_IRQHandler,       // 48: LPUART0 receive interrupt
333     LPUART1_TX_IRQHandler,       // 49: LPUART1 transmit interrupt
334     LPUART1_RX_IRQHandler,       // 50: LPUART1 receive interrupt
335     LPUART2_TX_IRQHandler,       // 51: LPUART2 transmit interrupt
336     LPUART2_RX_IRQHandler,       // 52: LPUART2 receive interrupt
337     Reserved53_IRQHandler,       // 53: Reserved interrupt
338     Reserved54_IRQHandler,       // 54: Reserved interrupt
339     ADC0_IRQHandler,             // 55: ADC conversion complete interrupt
340     CMP0_IRQHandler,             // 56: CMP0 interrupt
341     CMP1_IRQHandler,             // 57: CMP1 interrupt
342     FTM0_IRQHandler,             // 58: FTM0 single interrupt vector for all sources
343     FTM1_IRQHandler,             // 59: FTM1 single interrupt vector for all sources
344     FTM2_IRQHandler,             // 60: FTM2 single interrupt vector for all sources
345     Reserved61_IRQHandler,       // 61: Reserved interrupt
346     RTC_IRQHandler,              // 62: RTC alarm interrupt
347     RTC_Seconds_IRQHandler,      // 63: RTC seconds interrupt
348     LPIT0_Ch0_IRQHandler,        // 64: LPIT channel 0 overflow interrupt
349     LPIT0_Ch1_IRQHandler,        // 65: LPIT channel 1 overflow interrupt
350     LPIT0_Ch2_IRQHandler,        // 66: LPIT channel 2 overflow interrupt
351     LPIT0_Ch3_IRQHandler,        // 67: LPIT channel 3 overflow interrupt
352     PDB0_IRQHandler,             // 68: Programmable delay block 0 interrupt
353     Reserved69_IRQHandler,       // 69: Reserved interrupt
354     Reserved70_IRQHandler,       // 70: Reserved interrupt
355     Reserved71_IRQHandler,       // 71: Reserved interrupt
356     DAC0_IRQHandler,             // 72: Digital-to-analog converter 0 interrupt
357     SCG_RCM_IRQHandler,          // 73: SCG_RCM interrupt
358     LPTMR0_IRQHandler,           // 74: Single interrupt vector for  Low Power Timer 0 interrupt
359     PORTA_IRQHandler,            // 75: Port A pin detect interrupt
360     PORTB_IRQHandler,            // 76: Port B pin detect interrupt
361     PORTC_IRQHandler,            // 77: Port C pin detect interrupt
362     PORTD_IRQHandler,            // 78: Port D pin detect interrupt
363     PORTE_IRQHandler,            // 79: Port E pin detect interrupt
364     SWI_IRQHandler,              // 80: Software interrupt
365     Reserved81_IRQHandler,       // 81: Reserved interrupt
366     Reserved82_IRQHandler,       // 82: Reserved interrupt
367     Reserved83_IRQHandler,       // 83: Reserved interrupt
368     PDB1_IRQHandler,             // 84: Programmable delay block 1 interrupt
369     FLEXIO_IRQHandler,           // 85: FLEXIO interrupt
370     CMP2_IRQHandler,             // 86: CMP2 interrupt
371     FTM3_IRQHandler,             // 87: FlexTimer module 3 fault, overflow and channels interrupt
372     Reserved88_IRQHandler,       // 88: Reserved interrupt
373     ADC1_IRQHandler,             // 89: ADC conversion complete interrupt
374     ADC2_IRQHandler,             // 90: ADC conversion complete interrupt
375     Reserved91_IRQHandler,       // 91: Reserved interrupt
376     Reserved92_IRQHandler,       // 92: Reserved interrupt
377     PDB2_IRQHandler,             // 93: Programmable delay block 2 interrupt
378 
379 
380 }; /* End of g_pfnVectors */
381 
382 //*****************************************************************************
383 // Functions to carry out the initialization of RW and BSS data sections. These
384 // are written as separate functions rather than being inlined within the
385 // ResetISR() function in order to cope with MCUs with multiple banks of
386 // memory.
387 //*****************************************************************************
388 __attribute__ ((section(".after_vectors.init_data")))
data_init(unsigned int romstart,unsigned int start,unsigned int len)389 void data_init(unsigned int romstart, unsigned int start, unsigned int len) {
390     unsigned int *pulDest = (unsigned int*) start;
391     unsigned int *pulSrc = (unsigned int*) romstart;
392     unsigned int loop;
393     for (loop = 0; loop < len; loop = loop + 4)
394         *pulDest++ = *pulSrc++;
395 }
396 
397 __attribute__ ((section(".after_vectors.init_bss")))
bss_init(unsigned int start,unsigned int len)398 void bss_init(unsigned int start, unsigned int len) {
399     unsigned int *pulDest = (unsigned int*) start;
400     unsigned int loop;
401     for (loop = 0; loop < len; loop = loop + 4)
402         *pulDest++ = 0;
403 }
404 
405 //*****************************************************************************
406 // The following symbols are constructs generated by the linker, indicating
407 // the location of various points in the "Global Section Table". This table is
408 // created by the linker via the Code Red managed linker script mechanism. It
409 // contains the load address, execution address and length of each RW data
410 // section and the execution and length of each BSS (zero initialized) section.
411 //*****************************************************************************
412 extern unsigned int __data_section_table;
413 extern unsigned int __data_section_table_end;
414 extern unsigned int __bss_section_table;
415 extern unsigned int __bss_section_table_end;
416 
417 //*****************************************************************************
418 // Reset entry point for your code.
419 // Sets up a simple runtime environment and initializes the C/C++
420 // library.
421 //*****************************************************************************
422 __attribute__ ((naked, section(".after_vectors.reset")))
ResetISR(void)423 void ResetISR(void) {
424 
425     // Disable interrupts
426     __asm volatile ("cpsid i");
427 
428 
429 #if defined (__USE_CMSIS)
430 // If __USE_CMSIS defined, then call CMSIS SystemInit code
431     SystemInit();
432 
433 #else
434     // Disable Watchdog
435     // Write watchdog update key to unlock
436     *((volatile unsigned int *)0x40052004) = 0xD928C520;
437     // Set timeout value
438     *((volatile unsigned int *)0x40052008) = 0xFFFF;
439     // Now disable watchdog via control register
440     volatile unsigned int *WDOG_CS = (unsigned int *) 0x40052000;
441     *WDOG_CS = (*WDOG_CS & ~(1 << 7)) | (1 << 5);
442 #endif // (__USE_CMSIS)
443 
444     //
445     // Copy the data sections from flash to SRAM.
446     //
447     unsigned int LoadAddr, ExeAddr, SectionLen;
448     unsigned int *SectionTableAddr;
449 
450     // Load base address of Global Section Table
451     SectionTableAddr = &__data_section_table;
452 
453     // Copy the data sections from flash to SRAM.
454     while (SectionTableAddr < &__data_section_table_end) {
455         LoadAddr = *SectionTableAddr++;
456         ExeAddr = *SectionTableAddr++;
457         SectionLen = *SectionTableAddr++;
458         data_init(LoadAddr, ExeAddr, SectionLen);
459     }
460 
461     // At this point, SectionTableAddr = &__bss_section_table;
462     // Zero fill the bss segment
463     while (SectionTableAddr < &__bss_section_table_end) {
464         ExeAddr = *SectionTableAddr++;
465         SectionLen = *SectionTableAddr++;
466         bss_init(ExeAddr, SectionLen);
467     }
468 
469 #if !defined (__USE_CMSIS)
470 // Assume that if __USE_CMSIS defined, then CMSIS SystemInit code
471 // will enable the FPU
472 #if defined (__VFP_FP__) && !defined (__SOFTFP__)
473     //
474     // Code to enable the Cortex-M4 FPU only included
475     // if appropriate build options have been selected.
476     // Code taken from Section 7.1, Cortex-M4 TRM (DDI0439C)
477     //
478     // Read CPACR (located at address 0xE000ED88)
479     // Set bits 20-23 to enable CP10 and CP11 coprocessors
480     // Write back the modified value to the CPACR
481     asm volatile ("LDR.W R0, =0xE000ED88\n\t"
482                   "LDR R1, [R0]\n\t"
483                   "ORR R1, R1, #(0xF << 20)\n\t"
484                   "STR R1, [R0]");
485 #endif // (__VFP_FP__) && !(__SOFTFP__)
486 #endif // (__USE_CMSIS)
487 
488 
489 #if !defined (__USE_CMSIS)
490 // Assume that if __USE_CMSIS defined, then CMSIS SystemInit code
491 // will setup the VTOR register
492 
493     // Check to see if we are running the code from a non-zero
494     // address (eg RAM, external flash), in which case we need
495     // to modify the VTOR register to tell the CPU that the
496     // vector table is located at a non-0x0 address.
497     unsigned int * pSCB_VTOR = (unsigned int *) 0xE000ED08;
498     if ((unsigned int *)g_pfnVectors!=(unsigned int *) 0x00000000) {
499         *pSCB_VTOR = (unsigned int)g_pfnVectors;
500     }
501 #endif // (__USE_CMSIS)
502 #if defined (__cplusplus)
503     //
504     // Call C++ library initialisation
505     //
506     __libc_init_array();
507 #endif
508 
509     // Reenable interrupts
510     __asm volatile ("cpsie i");
511 
512 #if defined (__REDLIB__)
513     // Call the Redlib library, which in turn calls main()
514     __main();
515 #else
516     main();
517 #endif
518 
519     //
520     // main() shouldn't return, but if it does, we'll just enter an infinite loop
521     //
522     while (1) {
523         ;
524     }
525 }
526 
527 //*****************************************************************************
528 // Default core exception handlers. Override the ones here by defining your own
529 // handler routines in your application code.
530 //*****************************************************************************
NMI_Handler(void)531 WEAK_AV void NMI_Handler(void)
532 { while(1) {}
533 }
534 
HardFault_Handler(void)535 WEAK_AV void HardFault_Handler(void)
536 { while(1) {}
537 }
538 
MemManage_Handler(void)539 WEAK_AV void MemManage_Handler(void)
540 { while(1) {}
541 }
542 
BusFault_Handler(void)543 WEAK_AV void BusFault_Handler(void)
544 { while(1) {}
545 }
546 
UsageFault_Handler(void)547 WEAK_AV void UsageFault_Handler(void)
548 { while(1) {}
549 }
550 
SVC_Handler(void)551 WEAK_AV void SVC_Handler(void)
552 { while(1) {}
553 }
554 
DebugMon_Handler(void)555 WEAK_AV void DebugMon_Handler(void)
556 { while(1) {}
557 }
558 
PendSV_Handler(void)559 WEAK_AV void PendSV_Handler(void)
560 { while(1) {}
561 }
562 
SysTick_Handler(void)563 WEAK_AV void SysTick_Handler(void)
564 { while(1) {}
565 }
566 
567 //*****************************************************************************
568 // Processor ends up here if an unexpected interrupt occurs or a specific
569 // handler is not present in the application code.
570 //*****************************************************************************
IntDefaultHandler(void)571 WEAK_AV void IntDefaultHandler(void)
572 { while(1) {}
573 }
574 
575 //*****************************************************************************
576 // Default application exception handlers. Override the ones here by defining
577 // your own handler routines in your application code. These routines call
578 // driver exception handlers or IntDefaultHandler() if no driver exception
579 // handler is included.
580 //*****************************************************************************
DMA0_IRQHandler(void)581 WEAK void DMA0_IRQHandler(void)
582 {   DMA0_DriverIRQHandler();
583 }
584 
DMA1_IRQHandler(void)585 WEAK void DMA1_IRQHandler(void)
586 {   DMA1_DriverIRQHandler();
587 }
588 
DMA2_IRQHandler(void)589 WEAK void DMA2_IRQHandler(void)
590 {   DMA2_DriverIRQHandler();
591 }
592 
DMA3_IRQHandler(void)593 WEAK void DMA3_IRQHandler(void)
594 {   DMA3_DriverIRQHandler();
595 }
596 
DMA4_IRQHandler(void)597 WEAK void DMA4_IRQHandler(void)
598 {   DMA4_DriverIRQHandler();
599 }
600 
DMA5_IRQHandler(void)601 WEAK void DMA5_IRQHandler(void)
602 {   DMA5_DriverIRQHandler();
603 }
604 
DMA6_IRQHandler(void)605 WEAK void DMA6_IRQHandler(void)
606 {   DMA6_DriverIRQHandler();
607 }
608 
DMA7_IRQHandler(void)609 WEAK void DMA7_IRQHandler(void)
610 {   DMA7_DriverIRQHandler();
611 }
612 
DMA8_IRQHandler(void)613 WEAK void DMA8_IRQHandler(void)
614 {   DMA8_DriverIRQHandler();
615 }
616 
DMA9_IRQHandler(void)617 WEAK void DMA9_IRQHandler(void)
618 {   DMA9_DriverIRQHandler();
619 }
620 
DMA10_IRQHandler(void)621 WEAK void DMA10_IRQHandler(void)
622 {   DMA10_DriverIRQHandler();
623 }
624 
DMA11_IRQHandler(void)625 WEAK void DMA11_IRQHandler(void)
626 {   DMA11_DriverIRQHandler();
627 }
628 
DMA12_IRQHandler(void)629 WEAK void DMA12_IRQHandler(void)
630 {   DMA12_DriverIRQHandler();
631 }
632 
DMA13_IRQHandler(void)633 WEAK void DMA13_IRQHandler(void)
634 {   DMA13_DriverIRQHandler();
635 }
636 
DMA14_IRQHandler(void)637 WEAK void DMA14_IRQHandler(void)
638 {   DMA14_DriverIRQHandler();
639 }
640 
DMA15_IRQHandler(void)641 WEAK void DMA15_IRQHandler(void)
642 {   DMA15_DriverIRQHandler();
643 }
644 
DMA_Error_IRQHandler(void)645 WEAK void DMA_Error_IRQHandler(void)
646 {   DMA_Error_DriverIRQHandler();
647 }
648 
MCM_IRQHandler(void)649 WEAK void MCM_IRQHandler(void)
650 {   MCM_DriverIRQHandler();
651 }
652 
FTFE_IRQHandler(void)653 WEAK void FTFE_IRQHandler(void)
654 {   FTFE_DriverIRQHandler();
655 }
656 
Read_Collision_IRQHandler(void)657 WEAK void Read_Collision_IRQHandler(void)
658 {   Read_Collision_DriverIRQHandler();
659 }
660 
LVD_LVW_IRQHandler(void)661 WEAK void LVD_LVW_IRQHandler(void)
662 {   LVD_LVW_DriverIRQHandler();
663 }
664 
Doublebit_Fault_IRQHandler(void)665 WEAK void Doublebit_Fault_IRQHandler(void)
666 {   Doublebit_Fault_DriverIRQHandler();
667 }
668 
WDOG_EWM_IRQHandler(void)669 WEAK void WDOG_EWM_IRQHandler(void)
670 {   WDOG_EWM_DriverIRQHandler();
671 }
672 
Reserved39_IRQHandler(void)673 WEAK void Reserved39_IRQHandler(void)
674 {   Reserved39_DriverIRQHandler();
675 }
676 
LPI2C0_IRQHandler(void)677 WEAK void LPI2C0_IRQHandler(void)
678 {   LPI2C0_DriverIRQHandler();
679 }
680 
LPI2C1_IRQHandler(void)681 WEAK void LPI2C1_IRQHandler(void)
682 {   LPI2C1_DriverIRQHandler();
683 }
684 
LPSPI0_IRQHandler(void)685 WEAK void LPSPI0_IRQHandler(void)
686 {   LPSPI0_DriverIRQHandler();
687 }
688 
LPSPI1_IRQHandler(void)689 WEAK void LPSPI1_IRQHandler(void)
690 {   LPSPI1_DriverIRQHandler();
691 }
692 
Reserved44_IRQHandler(void)693 WEAK void Reserved44_IRQHandler(void)
694 {   Reserved44_DriverIRQHandler();
695 }
696 
PWT_IRQHandler(void)697 WEAK void PWT_IRQHandler(void)
698 {   PWT_DriverIRQHandler();
699 }
700 
Reserved46_IRQHandler(void)701 WEAK void Reserved46_IRQHandler(void)
702 {   Reserved46_DriverIRQHandler();
703 }
704 
LPUART0_TX_IRQHandler(void)705 WEAK void LPUART0_TX_IRQHandler(void)
706 {   LPUART0_TX_DriverIRQHandler();
707 }
708 
LPUART0_RX_IRQHandler(void)709 WEAK void LPUART0_RX_IRQHandler(void)
710 {   LPUART0_RX_DriverIRQHandler();
711 }
712 
LPUART1_TX_IRQHandler(void)713 WEAK void LPUART1_TX_IRQHandler(void)
714 {   LPUART1_TX_DriverIRQHandler();
715 }
716 
LPUART1_RX_IRQHandler(void)717 WEAK void LPUART1_RX_IRQHandler(void)
718 {   LPUART1_RX_DriverIRQHandler();
719 }
720 
LPUART2_TX_IRQHandler(void)721 WEAK void LPUART2_TX_IRQHandler(void)
722 {   LPUART2_TX_DriverIRQHandler();
723 }
724 
LPUART2_RX_IRQHandler(void)725 WEAK void LPUART2_RX_IRQHandler(void)
726 {   LPUART2_RX_DriverIRQHandler();
727 }
728 
Reserved53_IRQHandler(void)729 WEAK void Reserved53_IRQHandler(void)
730 {   Reserved53_DriverIRQHandler();
731 }
732 
Reserved54_IRQHandler(void)733 WEAK void Reserved54_IRQHandler(void)
734 {   Reserved54_DriverIRQHandler();
735 }
736 
ADC0_IRQHandler(void)737 WEAK void ADC0_IRQHandler(void)
738 {   ADC0_DriverIRQHandler();
739 }
740 
CMP0_IRQHandler(void)741 WEAK void CMP0_IRQHandler(void)
742 {   CMP0_DriverIRQHandler();
743 }
744 
CMP1_IRQHandler(void)745 WEAK void CMP1_IRQHandler(void)
746 {   CMP1_DriverIRQHandler();
747 }
748 
FTM0_IRQHandler(void)749 WEAK void FTM0_IRQHandler(void)
750 {   FTM0_DriverIRQHandler();
751 }
752 
FTM1_IRQHandler(void)753 WEAK void FTM1_IRQHandler(void)
754 {   FTM1_DriverIRQHandler();
755 }
756 
FTM2_IRQHandler(void)757 WEAK void FTM2_IRQHandler(void)
758 {   FTM2_DriverIRQHandler();
759 }
760 
Reserved61_IRQHandler(void)761 WEAK void Reserved61_IRQHandler(void)
762 {   Reserved61_DriverIRQHandler();
763 }
764 
RTC_IRQHandler(void)765 WEAK void RTC_IRQHandler(void)
766 {   RTC_DriverIRQHandler();
767 }
768 
RTC_Seconds_IRQHandler(void)769 WEAK void RTC_Seconds_IRQHandler(void)
770 {   RTC_Seconds_DriverIRQHandler();
771 }
772 
LPIT0_Ch0_IRQHandler(void)773 WEAK void LPIT0_Ch0_IRQHandler(void)
774 {   LPIT0_Ch0_DriverIRQHandler();
775 }
776 
LPIT0_Ch1_IRQHandler(void)777 WEAK void LPIT0_Ch1_IRQHandler(void)
778 {   LPIT0_Ch1_DriverIRQHandler();
779 }
780 
LPIT0_Ch2_IRQHandler(void)781 WEAK void LPIT0_Ch2_IRQHandler(void)
782 {   LPIT0_Ch2_DriverIRQHandler();
783 }
784 
LPIT0_Ch3_IRQHandler(void)785 WEAK void LPIT0_Ch3_IRQHandler(void)
786 {   LPIT0_Ch3_DriverIRQHandler();
787 }
788 
PDB0_IRQHandler(void)789 WEAK void PDB0_IRQHandler(void)
790 {   PDB0_DriverIRQHandler();
791 }
792 
Reserved69_IRQHandler(void)793 WEAK void Reserved69_IRQHandler(void)
794 {   Reserved69_DriverIRQHandler();
795 }
796 
Reserved70_IRQHandler(void)797 WEAK void Reserved70_IRQHandler(void)
798 {   Reserved70_DriverIRQHandler();
799 }
800 
Reserved71_IRQHandler(void)801 WEAK void Reserved71_IRQHandler(void)
802 {   Reserved71_DriverIRQHandler();
803 }
804 
DAC0_IRQHandler(void)805 WEAK void DAC0_IRQHandler(void)
806 {   DAC0_DriverIRQHandler();
807 }
808 
SCG_RCM_IRQHandler(void)809 WEAK void SCG_RCM_IRQHandler(void)
810 {   SCG_RCM_DriverIRQHandler();
811 }
812 
LPTMR0_IRQHandler(void)813 WEAK void LPTMR0_IRQHandler(void)
814 {   LPTMR0_DriverIRQHandler();
815 }
816 
PORTA_IRQHandler(void)817 WEAK void PORTA_IRQHandler(void)
818 {   PORTA_DriverIRQHandler();
819 }
820 
PORTB_IRQHandler(void)821 WEAK void PORTB_IRQHandler(void)
822 {   PORTB_DriverIRQHandler();
823 }
824 
PORTC_IRQHandler(void)825 WEAK void PORTC_IRQHandler(void)
826 {   PORTC_DriverIRQHandler();
827 }
828 
PORTD_IRQHandler(void)829 WEAK void PORTD_IRQHandler(void)
830 {   PORTD_DriverIRQHandler();
831 }
832 
PORTE_IRQHandler(void)833 WEAK void PORTE_IRQHandler(void)
834 {   PORTE_DriverIRQHandler();
835 }
836 
SWI_IRQHandler(void)837 WEAK void SWI_IRQHandler(void)
838 {   SWI_DriverIRQHandler();
839 }
840 
Reserved81_IRQHandler(void)841 WEAK void Reserved81_IRQHandler(void)
842 {   Reserved81_DriverIRQHandler();
843 }
844 
Reserved82_IRQHandler(void)845 WEAK void Reserved82_IRQHandler(void)
846 {   Reserved82_DriverIRQHandler();
847 }
848 
Reserved83_IRQHandler(void)849 WEAK void Reserved83_IRQHandler(void)
850 {   Reserved83_DriverIRQHandler();
851 }
852 
PDB1_IRQHandler(void)853 WEAK void PDB1_IRQHandler(void)
854 {   PDB1_DriverIRQHandler();
855 }
856 
FLEXIO_IRQHandler(void)857 WEAK void FLEXIO_IRQHandler(void)
858 {   FLEXIO_DriverIRQHandler();
859 }
860 
CMP2_IRQHandler(void)861 WEAK void CMP2_IRQHandler(void)
862 {   CMP2_DriverIRQHandler();
863 }
864 
FTM3_IRQHandler(void)865 WEAK void FTM3_IRQHandler(void)
866 {   FTM3_DriverIRQHandler();
867 }
868 
Reserved88_IRQHandler(void)869 WEAK void Reserved88_IRQHandler(void)
870 {   Reserved88_DriverIRQHandler();
871 }
872 
ADC1_IRQHandler(void)873 WEAK void ADC1_IRQHandler(void)
874 {   ADC1_DriverIRQHandler();
875 }
876 
ADC2_IRQHandler(void)877 WEAK void ADC2_IRQHandler(void)
878 {   ADC2_DriverIRQHandler();
879 }
880 
Reserved91_IRQHandler(void)881 WEAK void Reserved91_IRQHandler(void)
882 {   Reserved91_DriverIRQHandler();
883 }
884 
Reserved92_IRQHandler(void)885 WEAK void Reserved92_IRQHandler(void)
886 {   Reserved92_DriverIRQHandler();
887 }
888 
PDB2_IRQHandler(void)889 WEAK void PDB2_IRQHandler(void)
890 {   PDB2_DriverIRQHandler();
891 }
892 
893 //*****************************************************************************
894 
895 #if defined (DEBUG)
896 #pragma GCC pop_options
897 #endif // (DEBUG)
898