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