1 //*****************************************************************************
2 // MIMXRT595S_cm33 startup code for use with MCUXpresso IDE
3 //
4 // Version : 101121
5 //*****************************************************************************
6 //
7 // Copyright 2016-2021 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 // Variable to store CRP value in. Will be placed automatically
44 // by the linker when "Enable Code Read Protect" selected.
45 // See crp.h header for more information
46 //*****************************************************************************
47 //*****************************************************************************
48 // Declaration of external SystemInit function
49 //*****************************************************************************
50 #if defined (__USE_CMSIS)
51 extern void SystemInit(void);
52 #endif // (__USE_CMSIS)
53 
54 //*****************************************************************************
55 // Forward declaration of the core exception handlers.
56 // When the application defines a handler (with the same name), this will
57 // automatically take precedence over these weak definitions.
58 // If your application is a C++ one, then any interrupt handlers defined
59 // in C++ files within in your main application will need to have C linkage
60 // rather than C++ linkage. To do this, make sure that you are using extern "C"
61 // { .... } around the interrupt handler within your main application code.
62 //*****************************************************************************
63      void ResetISR(void);
64 WEAK void NMI_Handler(void);
65 WEAK void HardFault_Handler(void);
66 WEAK void MemManage_Handler(void);
67 WEAK void BusFault_Handler(void);
68 WEAK void UsageFault_Handler(void);
69 WEAK void SecureFault_Handler(void);
70 WEAK void SVC_Handler(void);
71 WEAK void DebugMon_Handler(void);
72 WEAK void PendSV_Handler(void);
73 WEAK void SysTick_Handler(void);
74 WEAK void IntDefaultHandler(void);
75 
76 //*****************************************************************************
77 // Forward declaration of the application IRQ handlers. When the application
78 // defines a handler (with the same name), this will automatically take
79 // precedence over weak definitions below
80 //*****************************************************************************
81 WEAK void WDT0_IRQHandler(void);
82 WEAK void DMA0_IRQHandler(void);
83 WEAK void GPIO_INTA_IRQHandler(void);
84 WEAK void GPIO_INTB_IRQHandler(void);
85 WEAK void PIN_INT0_IRQHandler(void);
86 WEAK void PIN_INT1_IRQHandler(void);
87 WEAK void PIN_INT2_IRQHandler(void);
88 WEAK void PIN_INT3_IRQHandler(void);
89 WEAK void UTICK0_IRQHandler(void);
90 WEAK void MRT0_IRQHandler(void);
91 WEAK void CTIMER0_IRQHandler(void);
92 WEAK void CTIMER1_IRQHandler(void);
93 WEAK void SCT0_IRQHandler(void);
94 WEAK void CTIMER3_IRQHandler(void);
95 WEAK void FLEXCOMM0_IRQHandler(void);
96 WEAK void FLEXCOMM1_IRQHandler(void);
97 WEAK void FLEXCOMM2_IRQHandler(void);
98 WEAK void FLEXCOMM3_IRQHandler(void);
99 WEAK void FLEXCOMM4_IRQHandler(void);
100 WEAK void FLEXCOMM5_IRQHandler(void);
101 WEAK void FLEXCOMM14_IRQHandler(void);
102 WEAK void FLEXCOMM15_IRQHandler(void);
103 WEAK void ADC0_IRQHandler(void);
104 WEAK void Reserved39_IRQHandler(void);
105 WEAK void ACMP_IRQHandler(void);
106 WEAK void DMIC0_IRQHandler(void);
107 WEAK void Reserved42_IRQHandler(void);
108 WEAK void HYPERVISOR_IRQHandler(void);
109 WEAK void SECURE_VIOLATION_IRQHandler(void);
110 WEAK void HWVAD0_IRQHandler(void);
111 WEAK void Reserved46_IRQHandler(void);
112 WEAK void RNG_IRQHandler(void);
113 WEAK void RTC_IRQHandler(void);
114 WEAK void DSP_TIE_EXPSTATE1_IRQHandler(void);
115 WEAK void MU_A_IRQHandler(void);
116 WEAK void PIN_INT4_IRQHandler(void);
117 WEAK void PIN_INT5_IRQHandler(void);
118 WEAK void PIN_INT6_IRQHandler(void);
119 WEAK void PIN_INT7_IRQHandler(void);
120 WEAK void CTIMER2_IRQHandler(void);
121 WEAK void CTIMER4_IRQHandler(void);
122 WEAK void OS_EVENT_IRQHandler(void);
123 WEAK void FLEXSPI0_FLEXSPI1_IRQHandler(void);
124 WEAK void FLEXCOMM6_IRQHandler(void);
125 WEAK void FLEXCOMM7_IRQHandler(void);
126 WEAK void USDHC0_IRQHandler(void);
127 WEAK void USDHC1_IRQHandler(void);
128 WEAK void SGPIO_INTA_IRQHandler(void);
129 WEAK void SGPIO_INTB_IRQHandler(void);
130 WEAK void I3C0_IRQHandler(void);
131 WEAK void USB0_IRQHandler(void);
132 WEAK void USB0_NEEDCLK_IRQHandler(void);
133 WEAK void WDT1_IRQHandler(void);
134 WEAK void USB_PHYDCD_IRQHandler(void);
135 WEAK void DMA1_IRQHandler(void);
136 WEAK void PUF_IRQHandler(void);
137 WEAK void POWERQUAD_IRQHandler(void);
138 WEAK void CASPER_IRQHandler(void);
139 WEAK void PMU_PMIC_IRQHandler(void);
140 WEAK void HASHCRYPT_IRQHandler(void);
141 WEAK void FLEXCOMM8_IRQHandler(void);
142 WEAK void FLEXCOMM9_IRQHandler(void);
143 WEAK void FLEXCOMM10_IRQHandler(void);
144 WEAK void FLEXCOMM11_IRQHandler(void);
145 WEAK void FLEXCOMM12_IRQHandler(void);
146 WEAK void FLEXCOMM13_IRQHandler(void);
147 WEAK void FLEXCOMM16_IRQHandler(void);
148 WEAK void I3C1_IRQHandler(void);
149 WEAK void FLEXIO_IRQHandler(void);
150 WEAK void LCDIF_IRQHandler(void);
151 WEAK void GPU_IRQHandler(void);
152 WEAK void MIPI_IRQHandler(void);
153 WEAK void Reserved88_IRQHandler(void);
154 WEAK void SDMA_IRQHandler(void);
155 
156 //*****************************************************************************
157 // Forward declaration of the driver IRQ handlers. These are aliased
158 // to the IntDefaultHandler, which is a 'forever' loop. When the driver
159 // defines a handler (with the same name), this will automatically take
160 // precedence over these weak definitions
161 //*****************************************************************************
162 void WDT0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
163 void DMA0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
164 void GPIO_INTA_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
165 void GPIO_INTB_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
166 void PIN_INT0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
167 void PIN_INT1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
168 void PIN_INT2_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
169 void PIN_INT3_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
170 void UTICK0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
171 void MRT0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
172 void CTIMER0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
173 void CTIMER1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
174 void SCT0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
175 void CTIMER3_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
176 void FLEXCOMM0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
177 void FLEXCOMM1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
178 void FLEXCOMM2_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
179 void FLEXCOMM3_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
180 void FLEXCOMM4_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
181 void FLEXCOMM5_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
182 void FLEXCOMM14_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
183 void FLEXCOMM15_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
184 void ADC0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
185 void Reserved39_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
186 void ACMP_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
187 void DMIC0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
188 void Reserved42_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
189 void HYPERVISOR_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
190 void SECURE_VIOLATION_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
191 void HWVAD0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
192 void Reserved46_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
193 void RNG_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
194 void RTC_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
195 void DSP_TIE_EXPSTATE1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
196 void MU_A_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
197 void PIN_INT4_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
198 void PIN_INT5_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
199 void PIN_INT6_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
200 void PIN_INT7_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
201 void CTIMER2_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
202 void CTIMER4_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
203 void OS_EVENT_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
204 void FLEXSPI0_FLEXSPI1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
205 void FLEXCOMM6_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
206 void FLEXCOMM7_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
207 void USDHC0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
208 void USDHC1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
209 void SGPIO_INTA_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
210 void SGPIO_INTB_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
211 void I3C0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
212 void USB0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
213 void USB0_NEEDCLK_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
214 void WDT1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
215 void USB_PHYDCD_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
216 void DMA1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
217 void PUF_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
218 void POWERQUAD_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
219 void CASPER_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
220 void PMU_PMIC_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
221 void HASHCRYPT_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
222 void FLEXCOMM8_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
223 void FLEXCOMM9_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
224 void FLEXCOMM10_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
225 void FLEXCOMM11_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
226 void FLEXCOMM12_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
227 void FLEXCOMM13_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
228 void FLEXCOMM16_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
229 void I3C1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
230 void FLEXIO_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
231 void LCDIF_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
232 void GPU_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
233 void MIPI_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
234 void Reserved88_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
235 void SDMA_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
236 
237 //*****************************************************************************
238 // The entry point for the application.
239 // __main() is the entry point for Redlib based applications
240 // main() is the entry point for Newlib based applications
241 //*****************************************************************************
242 #if defined (__REDLIB__)
243 extern void __main(void);
244 #endif
245 extern int main(void);
246 
247 //*****************************************************************************
248 // External declaration for the pointer to the stack top from the Linker Script
249 //*****************************************************************************
250 extern void _vStackTop(void);
251 extern void _image_size(void);
252 //*****************************************************************************
253 // External declaration for the pointer to the stack base from the Linker Script
254 //*****************************************************************************
255 extern void _vStackBase(void);
256 //*****************************************************************************
257 // External declaration for image type and load address from  Linker Script
258 //*****************************************************************************
259 WEAK extern void __imghdr_loadaddress();
260 WEAK extern void __imghdr_imagetype();
261 
262 //*****************************************************************************
263 #if defined (__cplusplus)
264 } // extern "C"
265 #endif
266 //*****************************************************************************
267 // The vector table.
268 // This relies on the linker script to place at correct location in memory.
269 //*****************************************************************************
270 
271 extern void (* const g_pfnVectors[])(void);
272 extern void * __Vectors __attribute__ ((alias ("g_pfnVectors")));
273 
274 __attribute__ ((used, section(".isr_vector")))
275 void (* const g_pfnVectors[])(void) = {
276     // Core Level - CM33
277     &_vStackTop,                       // The initial stack pointer
278     ResetISR,                          // The reset handler
279     NMI_Handler,                       // The NMI handler
280     HardFault_Handler,                 // The hard fault handler
281     MemManage_Handler,                 // The MPU fault handler
282     BusFault_Handler,                  // The bus fault handler
283     UsageFault_Handler,                // The usage fault handler
284     SecureFault_Handler,               // The secure fault handler
285 #if (defined(__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE & 0x2))
286     (void (*)())0x280000,                // Image length
287 #else
288     (void (*)())((unsigned)_image_size), // Image length
289 #endif
290     __imghdr_imagetype,                // Image type
291     0,                                 // Reserved
292     SVC_Handler,                       // SVCall handler
293     DebugMon_Handler,                  // Debug monitor handler
294     (void (*)())g_pfnVectors,              // Image load address
295     PendSV_Handler,                    // The PendSV handler
296     SysTick_Handler,                   // The SysTick handler
297 
298     // Chip Level - MIMXRT595S_cm33
299     WDT0_IRQHandler,               // 16: Watchdog timer interrupt
300     DMA0_IRQHandler,               // 17: DMA interrupt
301     GPIO_INTA_IRQHandler,          // 18: GPIO Interrupt A
302     GPIO_INTB_IRQHandler,          // 19: GPIO Interrupt B
303     PIN_INT0_IRQHandler,           // 20: General Purpose Input/Output interrupt 0
304     PIN_INT1_IRQHandler,           // 21: General Purpose Input/Output interrupt 1
305     PIN_INT2_IRQHandler,           // 22: General Purpose Input/Output interrupt 2
306     PIN_INT3_IRQHandler,           // 23: General Purpose Input/Output interrupt 3
307     UTICK0_IRQHandler,             // 24: Micro-tick Timer
308     MRT0_IRQHandler,               // 25: Multi-Rate Timer
309     CTIMER0_IRQHandler,            // 26: Standard counter/timer CTIMER0
310     CTIMER1_IRQHandler,            // 27: Standard counter/timer CTIMER1
311     SCT0_IRQHandler,               // 28: SCTimer/PWM
312     CTIMER3_IRQHandler,            // 29: Standard counter/timer CTIMER3
313     FLEXCOMM0_IRQHandler,          // 30: FlexComm interrupt
314     FLEXCOMM1_IRQHandler,          // 31: FlexComm interrupt
315     FLEXCOMM2_IRQHandler,          // 32: FlexComm interrupt
316     FLEXCOMM3_IRQHandler,          // 33: FlexComm interrupt
317     FLEXCOMM4_IRQHandler,          // 34: FlexComm interrupt
318     FLEXCOMM5_IRQHandler,          // 35: FlexComm interrupt
319     FLEXCOMM14_IRQHandler,         // 36: FlexComm interrupt. Standalone SPI
320     FLEXCOMM15_IRQHandler,         // 37: FlexComm interrupt. Standalone I2C
321     ADC0_IRQHandler,               // 38: Analog-to-Digital Converter interrupt
322     Reserved39_IRQHandler,         // 39: Reserved interrupt
323     ACMP_IRQHandler,               // 40: Analog comparator Interrupts
324     DMIC0_IRQHandler,              // 41: Digital Microphone Interface interrupt
325     Reserved42_IRQHandler,         // 42: Reserved interrupt
326     HYPERVISOR_IRQHandler,         // 43: Hypervisor interrupt
327     SECURE_VIOLATION_IRQHandler,   // 44: Secure violation interrupt
328     HWVAD0_IRQHandler,             // 45: Hardware Voice Activity Detector interrupt
329     Reserved46_IRQHandler,         // 46: Reserved interrupt
330     RNG_IRQHandler,                // 47: Random Number Generator interrupt
331     RTC_IRQHandler,                // 48: Real Time Clock Alarm interrupt OR Wakeup timer interrupt
332     DSP_TIE_EXPSTATE1_IRQHandler,  // 49: DSP interrupt
333     MU_A_IRQHandler,               // 50: Messaging Unit - Side A
334     PIN_INT4_IRQHandler,           // 51: General Purpose Input/Output interrupt 4
335     PIN_INT5_IRQHandler,           // 52: General Purpose Input/Output interrupt 5
336     PIN_INT6_IRQHandler,           // 53: General Purpose Input/Output interrupt 6
337     PIN_INT7_IRQHandler,           // 54: General Purpose Input/Output interrupt 7
338     CTIMER2_IRQHandler,            // 55: Standard counter/timer CTIMER2
339     CTIMER4_IRQHandler,            // 56: Standard counter/timer CTIMER4
340     OS_EVENT_IRQHandler,           // 57: Event timer M33 Wakeup/interrupt
341     FLEXSPI0_FLEXSPI1_IRQHandler,  // 58: FlexSPI0_IRQ OR FlexSPI1_IRQ
342     FLEXCOMM6_IRQHandler,          // 59: FlexComm interrupt
343     FLEXCOMM7_IRQHandler,          // 60: FlexComm interrupt
344     USDHC0_IRQHandler,             // 61: USDHC interrupt
345     USDHC1_IRQHandler,             // 62: USDHC interrupt
346     SGPIO_INTA_IRQHandler,         // 63: Secure GPIO HS interrupt 0
347     SGPIO_INTB_IRQHandler,         // 64: Secure GPIO HS interrupt 1
348     I3C0_IRQHandler,               // 65: Improved Inter Integrated Circuit 0 interrupt
349     USB0_IRQHandler,               // 66: USB device
350     USB0_NEEDCLK_IRQHandler,       // 67: USB Activity Wake-up Interrupt
351     WDT1_IRQHandler,               // 68: Watchdog timer 1 interrupt
352     USB_PHYDCD_IRQHandler,         // 69: USBPHY DCD interrupt
353     DMA1_IRQHandler,               // 70: DMA interrupt
354     PUF_IRQHandler,                // 71: QuidKey interrupt
355     POWERQUAD_IRQHandler,          // 72: Powerquad interrupt
356     CASPER_IRQHandler,             // 73: Caspar interrupt
357     PMU_PMIC_IRQHandler,           // 74: Power Management Control interrupt
358     HASHCRYPT_IRQHandler,          // 75: SHA interrupt
359     FLEXCOMM8_IRQHandler,          // 76: FlexComm interrupt
360     FLEXCOMM9_IRQHandler,          // 77: FlexComm interrupt
361     FLEXCOMM10_IRQHandler,         // 78: FlexComm interrupt
362     FLEXCOMM11_IRQHandler,         // 79: FlexComm interrupt
363     FLEXCOMM12_IRQHandler,         // 80: FlexComm interrupt
364     FLEXCOMM13_IRQHandler,         // 81: FlexComm interrupt
365     FLEXCOMM16_IRQHandler,         // 82: FlexComm interrupt
366     I3C1_IRQHandler,               // 83: Improved Inter Integrated Circuit 1 interrupt
367     FLEXIO_IRQHandler,             // 84: Flexible I/O interrupt
368     LCDIF_IRQHandler,              // 85: Liquid Crystal Display interface interrupt
369     GPU_IRQHandler,                // 86: Graphics Processor Unit interrupt
370     MIPI_IRQHandler,               // 87: MIPI interrupt
371     Reserved88_IRQHandler,         // 88: Reserved interrupt
372     SDMA_IRQHandler,               // 89: Smart DMA Engine Controller interrupt
373 }; /* End of g_pfnVectors */
374 
375 #if defined(ENABLE_RAM_VECTOR_TABLE)
376 extern void * __VECTOR_TABLE __attribute__ ((alias ("g_pfnVectors")));
377 void (* __VECTOR_RAM[sizeof(g_pfnVectors) / 4])(void) __attribute__((aligned(128)));
378 unsigned int __RAM_VECTOR_TABLE_SIZE_BYTES = sizeof(g_pfnVectors);
379 #endif
380 
381 //*****************************************************************************
382 // Functions to carry out the initialization of RW and BSS data sections. These
383 // are written as separate functions rather than being inlined within the
384 // ResetISR() function in order to cope with MCUs with multiple banks of
385 // memory.
386 //*****************************************************************************
387 __attribute__ ((section(".after_vectors.init_data")))
data_init(unsigned int romstart,unsigned int start,unsigned int len)388 void data_init(unsigned int romstart, unsigned int start, unsigned int len) {
389     unsigned int *pulDest = (unsigned int*) start;
390     unsigned int *pulSrc = (unsigned int*) romstart;
391     unsigned int loop;
392     for (loop = 0; loop < len; loop = loop + 4)
393         *pulDest++ = *pulSrc++;
394 }
395 
396 __attribute__ ((section(".after_vectors.init_bss")))
bss_init(unsigned int start,unsigned int len)397 void bss_init(unsigned int start, unsigned int len) {
398     unsigned int *pulDest = (unsigned int*) start;
399     unsigned int loop;
400     for (loop = 0; loop < len; loop = loop + 4)
401         *pulDest++ = 0;
402 }
403 
404 //*****************************************************************************
405 // The following symbols are constructs generated by the linker, indicating
406 // the location of various points in the "Global Section Table". This table is
407 // created by the linker via the Code Red managed linker script mechanism. It
408 // contains the load address, execution address and length of each RW data
409 // section and the execution and length of each BSS (zero initialized) section.
410 //*****************************************************************************
411 extern unsigned int __data_section_table;
412 extern unsigned int __data_section_table_end;
413 extern unsigned int __bss_section_table;
414 extern unsigned int __bss_section_table_end;
415 
416 //*****************************************************************************
417 // Reset entry point for your code.
418 // Sets up a simple runtime environment and initializes the C/C++
419 // library.
420 //*****************************************************************************
421 __attribute__ ((naked, section(".after_vectors.reset")))
ResetISR(void)422 void ResetISR(void) {
423     // Disable interrupts
424     __asm volatile ("cpsid i");
425     // Config VTOR & MSPLIM register
426     __asm volatile ("LDR R0, =0xE000ED08  \n"
427                     "STR %0, [R0]         \n"
428                     "LDR R1, [%0]         \n"
429                     "MSR MSP, R1          \n"
430                     "MSR MSPLIM, %1       \n"
431                     :
432                     : "r"(g_pfnVectors), "r"(_vStackBase)
433                     : "r0", "r1");
434 
435 #if defined (__USE_CMSIS)
436 // If __USE_CMSIS defined, then call CMSIS SystemInit code
437     SystemInit();
438 
439 #endif // (__USE_CMSIS)
440 
441     //
442     // Copy the data sections from flash to SRAM.
443     //
444     unsigned int LoadAddr, ExeAddr, SectionLen;
445     unsigned int *SectionTableAddr;
446 
447     // Load base address of Global Section Table
448     SectionTableAddr = &__data_section_table;
449 
450     // Copy the data sections from flash to SRAM.
451     while (SectionTableAddr < &__data_section_table_end) {
452         LoadAddr = *SectionTableAddr++;
453         ExeAddr = *SectionTableAddr++;
454         SectionLen = *SectionTableAddr++;
455         data_init(LoadAddr, ExeAddr, SectionLen);
456     }
457 
458     // At this point, SectionTableAddr = &__bss_section_table;
459     // Zero fill the bss segment
460     while (SectionTableAddr < &__bss_section_table_end) {
461         ExeAddr = *SectionTableAddr++;
462         SectionLen = *SectionTableAddr++;
463         bss_init(ExeAddr, SectionLen);
464     }
465 
466 #if defined (__cplusplus)
467     //
468     // Call C++ library initialisation
469     //
470     __libc_init_array();
471 #endif
472 
473     // Reenable interrupts
474     __asm volatile ("cpsie i");
475 
476 #if defined (__REDLIB__)
477     // Call the Redlib library, which in turn calls main()
478     __main();
479 #else
480     main();
481 #endif
482 
483     //
484     // main() shouldn't return, but if it does, we'll just enter an infinite loop
485     //
486     while (1) {
487         ;
488     }
489 }
490 
491 //*****************************************************************************
492 // Default core exception handlers. Override the ones here by defining your own
493 // handler routines in your application code.
494 //*****************************************************************************
NMI_Handler(void)495 WEAK_AV void NMI_Handler(void)
496 { while(1) {}
497 }
498 
HardFault_Handler(void)499 WEAK_AV void HardFault_Handler(void)
500 { while(1) {}
501 }
502 
MemManage_Handler(void)503 WEAK_AV void MemManage_Handler(void)
504 { while(1) {}
505 }
506 
BusFault_Handler(void)507 WEAK_AV void BusFault_Handler(void)
508 { while(1) {}
509 }
510 
UsageFault_Handler(void)511 WEAK_AV void UsageFault_Handler(void)
512 { while(1) {}
513 }
514 
SecureFault_Handler(void)515 WEAK_AV void SecureFault_Handler(void)
516 { while(1) {}
517 }
518 
SVC_Handler(void)519 WEAK_AV void SVC_Handler(void)
520 { while(1) {}
521 }
522 
DebugMon_Handler(void)523 WEAK_AV void DebugMon_Handler(void)
524 { while(1) {}
525 }
526 
PendSV_Handler(void)527 WEAK_AV void PendSV_Handler(void)
528 { while(1) {}
529 }
530 
SysTick_Handler(void)531 WEAK_AV void SysTick_Handler(void)
532 { while(1) {}
533 }
534 
535 //*****************************************************************************
536 // Processor ends up here if an unexpected interrupt occurs or a specific
537 // handler is not present in the application code.
538 //*****************************************************************************
IntDefaultHandler(void)539 WEAK_AV void IntDefaultHandler(void)
540 { while(1) {}
541 }
542 
543 //*****************************************************************************
544 // Default application exception handlers. Override the ones here by defining
545 // your own handler routines in your application code. These routines call
546 // driver exception handlers or IntDefaultHandler() if no driver exception
547 // handler is included.
548 //*****************************************************************************
WDT0_IRQHandler(void)549 WEAK void WDT0_IRQHandler(void)
550 {   WDT0_DriverIRQHandler();
551 }
552 
DMA0_IRQHandler(void)553 WEAK void DMA0_IRQHandler(void)
554 {   DMA0_DriverIRQHandler();
555 }
556 
GPIO_INTA_IRQHandler(void)557 WEAK void GPIO_INTA_IRQHandler(void)
558 {   GPIO_INTA_DriverIRQHandler();
559 }
560 
GPIO_INTB_IRQHandler(void)561 WEAK void GPIO_INTB_IRQHandler(void)
562 {   GPIO_INTB_DriverIRQHandler();
563 }
564 
PIN_INT0_IRQHandler(void)565 WEAK void PIN_INT0_IRQHandler(void)
566 {   PIN_INT0_DriverIRQHandler();
567 }
568 
PIN_INT1_IRQHandler(void)569 WEAK void PIN_INT1_IRQHandler(void)
570 {   PIN_INT1_DriverIRQHandler();
571 }
572 
PIN_INT2_IRQHandler(void)573 WEAK void PIN_INT2_IRQHandler(void)
574 {   PIN_INT2_DriverIRQHandler();
575 }
576 
PIN_INT3_IRQHandler(void)577 WEAK void PIN_INT3_IRQHandler(void)
578 {   PIN_INT3_DriverIRQHandler();
579 }
580 
UTICK0_IRQHandler(void)581 WEAK void UTICK0_IRQHandler(void)
582 {   UTICK0_DriverIRQHandler();
583 }
584 
MRT0_IRQHandler(void)585 WEAK void MRT0_IRQHandler(void)
586 {   MRT0_DriverIRQHandler();
587 }
588 
CTIMER0_IRQHandler(void)589 WEAK void CTIMER0_IRQHandler(void)
590 {   CTIMER0_DriverIRQHandler();
591 }
592 
CTIMER1_IRQHandler(void)593 WEAK void CTIMER1_IRQHandler(void)
594 {   CTIMER1_DriverIRQHandler();
595 }
596 
SCT0_IRQHandler(void)597 WEAK void SCT0_IRQHandler(void)
598 {   SCT0_DriverIRQHandler();
599 }
600 
CTIMER3_IRQHandler(void)601 WEAK void CTIMER3_IRQHandler(void)
602 {   CTIMER3_DriverIRQHandler();
603 }
604 
FLEXCOMM0_IRQHandler(void)605 WEAK void FLEXCOMM0_IRQHandler(void)
606 {   FLEXCOMM0_DriverIRQHandler();
607 }
608 
FLEXCOMM1_IRQHandler(void)609 WEAK void FLEXCOMM1_IRQHandler(void)
610 {   FLEXCOMM1_DriverIRQHandler();
611 }
612 
FLEXCOMM2_IRQHandler(void)613 WEAK void FLEXCOMM2_IRQHandler(void)
614 {   FLEXCOMM2_DriverIRQHandler();
615 }
616 
FLEXCOMM3_IRQHandler(void)617 WEAK void FLEXCOMM3_IRQHandler(void)
618 {   FLEXCOMM3_DriverIRQHandler();
619 }
620 
FLEXCOMM4_IRQHandler(void)621 WEAK void FLEXCOMM4_IRQHandler(void)
622 {   FLEXCOMM4_DriverIRQHandler();
623 }
624 
FLEXCOMM5_IRQHandler(void)625 WEAK void FLEXCOMM5_IRQHandler(void)
626 {   FLEXCOMM5_DriverIRQHandler();
627 }
628 
FLEXCOMM14_IRQHandler(void)629 WEAK void FLEXCOMM14_IRQHandler(void)
630 {   FLEXCOMM14_DriverIRQHandler();
631 }
632 
FLEXCOMM15_IRQHandler(void)633 WEAK void FLEXCOMM15_IRQHandler(void)
634 {   FLEXCOMM15_DriverIRQHandler();
635 }
636 
ADC0_IRQHandler(void)637 WEAK void ADC0_IRQHandler(void)
638 {   ADC0_DriverIRQHandler();
639 }
640 
Reserved39_IRQHandler(void)641 WEAK void Reserved39_IRQHandler(void)
642 {   Reserved39_DriverIRQHandler();
643 }
644 
ACMP_IRQHandler(void)645 WEAK void ACMP_IRQHandler(void)
646 {   ACMP_DriverIRQHandler();
647 }
648 
DMIC0_IRQHandler(void)649 WEAK void DMIC0_IRQHandler(void)
650 {   DMIC0_DriverIRQHandler();
651 }
652 
Reserved42_IRQHandler(void)653 WEAK void Reserved42_IRQHandler(void)
654 {   Reserved42_DriverIRQHandler();
655 }
656 
HYPERVISOR_IRQHandler(void)657 WEAK void HYPERVISOR_IRQHandler(void)
658 {   HYPERVISOR_DriverIRQHandler();
659 }
660 
SECURE_VIOLATION_IRQHandler(void)661 WEAK void SECURE_VIOLATION_IRQHandler(void)
662 {   SECURE_VIOLATION_DriverIRQHandler();
663 }
664 
HWVAD0_IRQHandler(void)665 WEAK void HWVAD0_IRQHandler(void)
666 {   HWVAD0_DriverIRQHandler();
667 }
668 
Reserved46_IRQHandler(void)669 WEAK void Reserved46_IRQHandler(void)
670 {   Reserved46_DriverIRQHandler();
671 }
672 
RNG_IRQHandler(void)673 WEAK void RNG_IRQHandler(void)
674 {   RNG_DriverIRQHandler();
675 }
676 
RTC_IRQHandler(void)677 WEAK void RTC_IRQHandler(void)
678 {   RTC_DriverIRQHandler();
679 }
680 
DSP_TIE_EXPSTATE1_IRQHandler(void)681 WEAK void DSP_TIE_EXPSTATE1_IRQHandler(void)
682 {   DSP_TIE_EXPSTATE1_DriverIRQHandler();
683 }
684 
MU_A_IRQHandler(void)685 WEAK void MU_A_IRQHandler(void)
686 {   MU_A_DriverIRQHandler();
687 }
688 
PIN_INT4_IRQHandler(void)689 WEAK void PIN_INT4_IRQHandler(void)
690 {   PIN_INT4_DriverIRQHandler();
691 }
692 
PIN_INT5_IRQHandler(void)693 WEAK void PIN_INT5_IRQHandler(void)
694 {   PIN_INT5_DriverIRQHandler();
695 }
696 
PIN_INT6_IRQHandler(void)697 WEAK void PIN_INT6_IRQHandler(void)
698 {   PIN_INT6_DriverIRQHandler();
699 }
700 
PIN_INT7_IRQHandler(void)701 WEAK void PIN_INT7_IRQHandler(void)
702 {   PIN_INT7_DriverIRQHandler();
703 }
704 
CTIMER2_IRQHandler(void)705 WEAK void CTIMER2_IRQHandler(void)
706 {   CTIMER2_DriverIRQHandler();
707 }
708 
CTIMER4_IRQHandler(void)709 WEAK void CTIMER4_IRQHandler(void)
710 {   CTIMER4_DriverIRQHandler();
711 }
712 
OS_EVENT_IRQHandler(void)713 WEAK void OS_EVENT_IRQHandler(void)
714 {   OS_EVENT_DriverIRQHandler();
715 }
716 
FLEXSPI0_FLEXSPI1_IRQHandler(void)717 WEAK void FLEXSPI0_FLEXSPI1_IRQHandler(void)
718 {   FLEXSPI0_FLEXSPI1_DriverIRQHandler();
719 }
720 
FLEXCOMM6_IRQHandler(void)721 WEAK void FLEXCOMM6_IRQHandler(void)
722 {   FLEXCOMM6_DriverIRQHandler();
723 }
724 
FLEXCOMM7_IRQHandler(void)725 WEAK void FLEXCOMM7_IRQHandler(void)
726 {   FLEXCOMM7_DriverIRQHandler();
727 }
728 
USDHC0_IRQHandler(void)729 WEAK void USDHC0_IRQHandler(void)
730 {   USDHC0_DriverIRQHandler();
731 }
732 
USDHC1_IRQHandler(void)733 WEAK void USDHC1_IRQHandler(void)
734 {   USDHC1_DriverIRQHandler();
735 }
736 
SGPIO_INTA_IRQHandler(void)737 WEAK void SGPIO_INTA_IRQHandler(void)
738 {   SGPIO_INTA_DriverIRQHandler();
739 }
740 
SGPIO_INTB_IRQHandler(void)741 WEAK void SGPIO_INTB_IRQHandler(void)
742 {   SGPIO_INTB_DriverIRQHandler();
743 }
744 
I3C0_IRQHandler(void)745 WEAK void I3C0_IRQHandler(void)
746 {   I3C0_DriverIRQHandler();
747 }
748 
USB0_IRQHandler(void)749 WEAK void USB0_IRQHandler(void)
750 {   USB0_DriverIRQHandler();
751 }
752 
USB0_NEEDCLK_IRQHandler(void)753 WEAK void USB0_NEEDCLK_IRQHandler(void)
754 {   USB0_NEEDCLK_DriverIRQHandler();
755 }
756 
WDT1_IRQHandler(void)757 WEAK void WDT1_IRQHandler(void)
758 {   WDT1_DriverIRQHandler();
759 }
760 
USB_PHYDCD_IRQHandler(void)761 WEAK void USB_PHYDCD_IRQHandler(void)
762 {   USB_PHYDCD_DriverIRQHandler();
763 }
764 
DMA1_IRQHandler(void)765 WEAK void DMA1_IRQHandler(void)
766 {   DMA1_DriverIRQHandler();
767 }
768 
PUF_IRQHandler(void)769 WEAK void PUF_IRQHandler(void)
770 {   PUF_DriverIRQHandler();
771 }
772 
POWERQUAD_IRQHandler(void)773 WEAK void POWERQUAD_IRQHandler(void)
774 {   POWERQUAD_DriverIRQHandler();
775 }
776 
CASPER_IRQHandler(void)777 WEAK void CASPER_IRQHandler(void)
778 {   CASPER_DriverIRQHandler();
779 }
780 
PMU_PMIC_IRQHandler(void)781 WEAK void PMU_PMIC_IRQHandler(void)
782 {   PMU_PMIC_DriverIRQHandler();
783 }
784 
HASHCRYPT_IRQHandler(void)785 WEAK void HASHCRYPT_IRQHandler(void)
786 {   HASHCRYPT_DriverIRQHandler();
787 }
788 
FLEXCOMM8_IRQHandler(void)789 WEAK void FLEXCOMM8_IRQHandler(void)
790 {   FLEXCOMM8_DriverIRQHandler();
791 }
792 
FLEXCOMM9_IRQHandler(void)793 WEAK void FLEXCOMM9_IRQHandler(void)
794 {   FLEXCOMM9_DriverIRQHandler();
795 }
796 
FLEXCOMM10_IRQHandler(void)797 WEAK void FLEXCOMM10_IRQHandler(void)
798 {   FLEXCOMM10_DriverIRQHandler();
799 }
800 
FLEXCOMM11_IRQHandler(void)801 WEAK void FLEXCOMM11_IRQHandler(void)
802 {   FLEXCOMM11_DriverIRQHandler();
803 }
804 
FLEXCOMM12_IRQHandler(void)805 WEAK void FLEXCOMM12_IRQHandler(void)
806 {   FLEXCOMM12_DriverIRQHandler();
807 }
808 
FLEXCOMM13_IRQHandler(void)809 WEAK void FLEXCOMM13_IRQHandler(void)
810 {   FLEXCOMM13_DriverIRQHandler();
811 }
812 
FLEXCOMM16_IRQHandler(void)813 WEAK void FLEXCOMM16_IRQHandler(void)
814 {   FLEXCOMM16_DriverIRQHandler();
815 }
816 
I3C1_IRQHandler(void)817 WEAK void I3C1_IRQHandler(void)
818 {   I3C1_DriverIRQHandler();
819 }
820 
FLEXIO_IRQHandler(void)821 WEAK void FLEXIO_IRQHandler(void)
822 {   FLEXIO_DriverIRQHandler();
823 }
824 
LCDIF_IRQHandler(void)825 WEAK void LCDIF_IRQHandler(void)
826 {   LCDIF_DriverIRQHandler();
827 }
828 
GPU_IRQHandler(void)829 WEAK void GPU_IRQHandler(void)
830 {   GPU_DriverIRQHandler();
831 }
832 
MIPI_IRQHandler(void)833 WEAK void MIPI_IRQHandler(void)
834 {   MIPI_DriverIRQHandler();
835 }
836 
Reserved88_IRQHandler(void)837 WEAK void Reserved88_IRQHandler(void)
838 {   Reserved88_DriverIRQHandler();
839 }
840 
SDMA_IRQHandler(void)841 WEAK void SDMA_IRQHandler(void)
842 {   SDMA_DriverIRQHandler();
843 }
844 
845 //*****************************************************************************
846 
847 #if defined (DEBUG)
848 #pragma GCC pop_options
849 #endif // (DEBUG)
850