aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios-contrib/ext/mcux-sdk/devices/K32L2B11A/mcuxpresso/startup_k32l2b11a.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios-contrib/ext/mcux-sdk/devices/K32L2B11A/mcuxpresso/startup_k32l2b11a.cpp')
-rw-r--r--lib/chibios-contrib/ext/mcux-sdk/devices/K32L2B11A/mcuxpresso/startup_k32l2b11a.cpp531
1 files changed, 531 insertions, 0 deletions
diff --git a/lib/chibios-contrib/ext/mcux-sdk/devices/K32L2B11A/mcuxpresso/startup_k32l2b11a.cpp b/lib/chibios-contrib/ext/mcux-sdk/devices/K32L2B11A/mcuxpresso/startup_k32l2b11a.cpp
new file mode 100644
index 000000000..0753b5189
--- /dev/null
+++ b/lib/chibios-contrib/ext/mcux-sdk/devices/K32L2B11A/mcuxpresso/startup_k32l2b11a.cpp
@@ -0,0 +1,531 @@
1//*****************************************************************************
2// K32L2B11A 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//*****************************************************************************
27extern "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)
39extern "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, 0xFFFF3FFE};
54//*****************************************************************************
55// Declaration of external SystemInit function
56//*****************************************************************************
57#if defined (__USE_CMSIS)
58extern 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);
71WEAK void NMI_Handler(void);
72WEAK void HardFault_Handler(void);
73WEAK void SVC_Handler(void);
74WEAK void PendSV_Handler(void);
75WEAK void SysTick_Handler(void);
76WEAK void IntDefaultHandler(void);
77
78//*****************************************************************************
79// Forward declaration of the application IRQ handlers. When the application
80// defines a handler (with the same name), this will automatically take
81// precedence over weak definitions below
82//*****************************************************************************
83WEAK void DMA0_IRQHandler(void);
84WEAK void DMA1_IRQHandler(void);
85WEAK void DMA2_IRQHandler(void);
86WEAK void DMA3_IRQHandler(void);
87WEAK void Reserved20_IRQHandler(void);
88WEAK void FTFA_IRQHandler(void);
89WEAK void PMC_IRQHandler(void);
90WEAK void LLWU_IRQHandler(void);
91WEAK void I2C0_IRQHandler(void);
92WEAK void I2C1_IRQHandler(void);
93WEAK void SPI0_IRQHandler(void);
94WEAK void SPI1_IRQHandler(void);
95WEAK void LPUART0_IRQHandler(void);
96WEAK void LPUART1_IRQHandler(void);
97WEAK void UART2_FLEXIO_IRQHandler(void);
98WEAK void ADC0_IRQHandler(void);
99WEAK void CMP0_IRQHandler(void);
100WEAK void TPM0_IRQHandler(void);
101WEAK void TPM1_IRQHandler(void);
102WEAK void TPM2_IRQHandler(void);
103WEAK void RTC_IRQHandler(void);
104WEAK void RTC_Seconds_IRQHandler(void);
105WEAK void PIT_IRQHandler(void);
106WEAK void Reserved39_IRQHandler(void);
107WEAK void USB0_IRQHandler(void);
108WEAK void DAC0_IRQHandler(void);
109WEAK void Reserved42_IRQHandler(void);
110WEAK void Reserved43_IRQHandler(void);
111WEAK void LPTMR0_IRQHandler(void);
112WEAK void LCD_IRQHandler(void);
113WEAK void PORTA_IRQHandler(void);
114WEAK void PORTC_PORTD_IRQHandler(void);
115
116//*****************************************************************************
117// Forward declaration of the driver IRQ handlers. These are aliased
118// to the IntDefaultHandler, which is a 'forever' loop. When the driver
119// defines a handler (with the same name), this will automatically take
120// precedence over these weak definitions
121//*****************************************************************************
122void DMA0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
123void DMA1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
124void DMA2_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
125void DMA3_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
126void Reserved20_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
127void FTFA_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
128void PMC_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
129void LLWU_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
130void I2C0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
131void I2C1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
132void SPI0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
133void SPI1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
134void LPUART0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
135void LPUART1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
136void UART2_FLEXIO_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
137void ADC0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
138void CMP0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
139void TPM0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
140void TPM1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
141void TPM2_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
142void RTC_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
143void RTC_Seconds_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
144void PIT_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
145void Reserved39_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
146void USB0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
147void DAC0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
148void Reserved42_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
149void Reserved43_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
150void LPTMR0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
151void LCD_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
152void PORTA_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
153void PORTC_PORTD_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
154
155//*****************************************************************************
156// The entry point for the application.
157// __main() is the entry point for Redlib based applications
158// main() is the entry point for Newlib based applications
159//*****************************************************************************
160#if defined (__REDLIB__)
161extern void __main(void);
162#endif
163extern int main(void);
164
165//*****************************************************************************
166// External declaration for the pointer to the stack top from the Linker Script
167//*****************************************************************************
168extern void _vStackTop(void);
169//*****************************************************************************
170#if defined (__cplusplus)
171} // extern "C"
172#endif
173//*****************************************************************************
174// The vector table.
175// This relies on the linker script to place at correct location in memory.
176//*****************************************************************************
177
178
179
180extern void (* const g_pfnVectors[])(void);
181extern void * __Vectors __attribute__ ((alias ("g_pfnVectors")));
182
183__attribute__ ((used, section(".isr_vector")))
184void (* const g_pfnVectors[])(void) = {
185 // Core Level - CM0P
186 &_vStackTop, // The initial stack pointer
187 ResetISR, // The reset handler
188 NMI_Handler, // The NMI handler
189 HardFault_Handler, // The hard fault handler
190 0, // Reserved
191 0, // Reserved
192 0, // Reserved
193 0, // Reserved
194 0, // Reserved
195 0, // Reserved
196 0, // Reserved
197 SVC_Handler, // SVCall handler
198 0, // Reserved
199 0, // Reserved
200 PendSV_Handler, // The PendSV handler
201 SysTick_Handler, // The SysTick handler
202
203 // Chip Level - K32L2B11A
204 DMA0_IRQHandler, // 16: DMA channel 0 transfer complete
205 DMA1_IRQHandler, // 17: DMA channel 1 transfer complete
206 DMA2_IRQHandler, // 18: DMA channel 2 transfer complete
207 DMA3_IRQHandler, // 19: DMA channel 3 transfer complete
208 Reserved20_IRQHandler, // 20: Reserved interrupt
209 FTFA_IRQHandler, // 21: Command complete and read collision
210 PMC_IRQHandler, // 22: Low-voltage detect, low-voltage warning
211 LLWU_IRQHandler, // 23: Low leakage wakeup
212 I2C0_IRQHandler, // 24: I2C0 interrupt
213 I2C1_IRQHandler, // 25: I2C1 interrupt
214 SPI0_IRQHandler, // 26: SPI0 single interrupt vector for all sources
215 SPI1_IRQHandler, // 27: SPI1 single interrupt vector for all sources
216 LPUART0_IRQHandler, // 28: LPUART0 status and error
217 LPUART1_IRQHandler, // 29: LPUART1 status and error
218 UART2_FLEXIO_IRQHandler, // 30: UART2 or FLEXIO
219 ADC0_IRQHandler, // 31: ADC0 interrupt
220 CMP0_IRQHandler, // 32: CMP0 interrupt
221 TPM0_IRQHandler, // 33: TPM0 single interrupt vector for all sources
222 TPM1_IRQHandler, // 34: TPM1 single interrupt vector for all sources
223 TPM2_IRQHandler, // 35: TPM2 single interrupt vector for all sources
224 RTC_IRQHandler, // 36: RTC alarm
225 RTC_Seconds_IRQHandler, // 37: RTC seconds
226 PIT_IRQHandler, // 38: PIT interrupt
227 Reserved39_IRQHandler, // 39: Reserved interrupt
228 USB0_IRQHandler, // 40: USB0 interrupt
229 DAC0_IRQHandler, // 41: DAC0 interrupt
230 Reserved42_IRQHandler, // 42: Reserved interrupt
231 Reserved43_IRQHandler, // 43: Reserved interrupt
232 LPTMR0_IRQHandler, // 44: LPTMR0 interrupt
233 LCD_IRQHandler, // 45: LCD interrupt
234 PORTA_IRQHandler, // 46: PORTA Pin detect
235 PORTC_PORTD_IRQHandler, // 47: Single interrupt vector for PORTC; PORTD Pin detect
236
237
238}; /* End of g_pfnVectors */
239
240//*****************************************************************************
241// Functions to carry out the initialization of RW and BSS data sections. These
242// are written as separate functions rather than being inlined within the
243// ResetISR() function in order to cope with MCUs with multiple banks of
244// memory.
245//*****************************************************************************
246__attribute__ ((section(".after_vectors.init_data")))
247void data_init(unsigned int romstart, unsigned int start, unsigned int len) {
248 unsigned int *pulDest = (unsigned int*) start;
249 unsigned int *pulSrc = (unsigned int*) romstart;
250 unsigned int loop;
251 for (loop = 0; loop < len; loop = loop + 4)
252 *pulDest++ = *pulSrc++;
253}
254
255__attribute__ ((section(".after_vectors.init_bss")))
256void bss_init(unsigned int start, unsigned int len) {
257 unsigned int *pulDest = (unsigned int*) start;
258 unsigned int loop;
259 for (loop = 0; loop < len; loop = loop + 4)
260 *pulDest++ = 0;
261}
262
263//*****************************************************************************
264// The following symbols are constructs generated by the linker, indicating
265// the location of various points in the "Global Section Table". This table is
266// created by the linker via the Code Red managed linker script mechanism. It
267// contains the load address, execution address and length of each RW data
268// section and the execution and length of each BSS (zero initialized) section.
269//*****************************************************************************
270extern unsigned int __data_section_table;
271extern unsigned int __data_section_table_end;
272extern unsigned int __bss_section_table;
273extern unsigned int __bss_section_table_end;
274
275//*****************************************************************************
276// Reset entry point for your code.
277// Sets up a simple runtime environment and initializes the C/C++
278// library.
279//*****************************************************************************
280__attribute__ ((section(".after_vectors.reset")))
281void ResetISR(void) {
282
283 // Disable interrupts
284 __asm volatile ("cpsid i");
285
286
287#if defined (__USE_CMSIS)
288// If __USE_CMSIS defined, then call CMSIS SystemInit code
289 SystemInit();
290
291#else
292 // Disable Watchdog
293 // SIM->COPC register: COPT=0,COPCLKS=0,COPW=0
294 *((volatile unsigned int *)0x40048100) = 0x00u;
295#endif // (__USE_CMSIS)
296
297 //
298 // Copy the data sections from flash to SRAM.
299 //
300 unsigned int LoadAddr, ExeAddr, SectionLen;
301 unsigned int *SectionTableAddr;
302
303 // Load base address of Global Section Table
304 SectionTableAddr = &__data_section_table;
305
306 // Copy the data sections from flash to SRAM.
307 while (SectionTableAddr < &__data_section_table_end) {
308 LoadAddr = *SectionTableAddr++;
309 ExeAddr = *SectionTableAddr++;
310 SectionLen = *SectionTableAddr++;
311 data_init(LoadAddr, ExeAddr, SectionLen);
312 }
313
314 // At this point, SectionTableAddr = &__bss_section_table;
315 // Zero fill the bss segment
316 while (SectionTableAddr < &__bss_section_table_end) {
317 ExeAddr = *SectionTableAddr++;
318 SectionLen = *SectionTableAddr++;
319 bss_init(ExeAddr, SectionLen);
320 }
321
322
323#if !defined (__USE_CMSIS)
324// Assume that if __USE_CMSIS defined, then CMSIS SystemInit code
325// will setup the VTOR register
326
327 // Check to see if we are running the code from a non-zero
328 // address (eg RAM, external flash), in which case we need
329 // to modify the VTOR register to tell the CPU that the
330 // vector table is located at a non-0x0 address.
331 unsigned int * pSCB_VTOR = (unsigned int *) 0xE000ED08;
332 if ((unsigned int *)g_pfnVectors!=(unsigned int *) 0x00000000) {
333 *pSCB_VTOR = (unsigned int)g_pfnVectors;
334 }
335#endif // (__USE_CMSIS)
336#if defined (__cplusplus)
337 //
338 // Call C++ library initialisation
339 //
340 __libc_init_array();
341#endif
342
343 // Reenable interrupts
344 __asm volatile ("cpsie i");
345
346#if defined (__REDLIB__)
347 // Call the Redlib library, which in turn calls main()
348 __main();
349#else
350 main();
351#endif
352
353 //
354 // main() shouldn't return, but if it does, we'll just enter an infinite loop
355 //
356 while (1) {
357 ;
358 }
359}
360
361//*****************************************************************************
362// Default core exception handlers. Override the ones here by defining your own
363// handler routines in your application code.
364//*****************************************************************************
365WEAK_AV void NMI_Handler(void)
366{ while(1) {}
367}
368
369WEAK_AV void HardFault_Handler(void)
370{ while(1) {}
371}
372
373WEAK_AV void SVC_Handler(void)
374{ while(1) {}
375}
376
377WEAK_AV void PendSV_Handler(void)
378{ while(1) {}
379}
380
381WEAK_AV void SysTick_Handler(void)
382{ while(1) {}
383}
384
385//*****************************************************************************
386// Processor ends up here if an unexpected interrupt occurs or a specific
387// handler is not present in the application code.
388//*****************************************************************************
389WEAK_AV void IntDefaultHandler(void)
390{ while(1) {}
391}
392
393//*****************************************************************************
394// Default application exception handlers. Override the ones here by defining
395// your own handler routines in your application code. These routines call
396// driver exception handlers or IntDefaultHandler() if no driver exception
397// handler is included.
398//*****************************************************************************
399WEAK_AV void DMA0_IRQHandler(void)
400{ DMA0_DriverIRQHandler();
401}
402
403WEAK_AV void DMA1_IRQHandler(void)
404{ DMA1_DriverIRQHandler();
405}
406
407WEAK_AV void DMA2_IRQHandler(void)
408{ DMA2_DriverIRQHandler();
409}
410
411WEAK_AV void DMA3_IRQHandler(void)
412{ DMA3_DriverIRQHandler();
413}
414
415WEAK_AV void Reserved20_IRQHandler(void)
416{ Reserved20_DriverIRQHandler();
417}
418
419WEAK_AV void FTFA_IRQHandler(void)
420{ FTFA_DriverIRQHandler();
421}
422
423WEAK_AV void PMC_IRQHandler(void)
424{ PMC_DriverIRQHandler();
425}
426
427WEAK_AV void LLWU_IRQHandler(void)
428{ LLWU_DriverIRQHandler();
429}
430
431WEAK_AV void I2C0_IRQHandler(void)
432{ I2C0_DriverIRQHandler();
433}
434
435WEAK_AV void I2C1_IRQHandler(void)
436{ I2C1_DriverIRQHandler();
437}
438
439WEAK_AV void SPI0_IRQHandler(void)
440{ SPI0_DriverIRQHandler();
441}
442
443WEAK_AV void SPI1_IRQHandler(void)
444{ SPI1_DriverIRQHandler();
445}
446
447WEAK_AV void LPUART0_IRQHandler(void)
448{ LPUART0_DriverIRQHandler();
449}
450
451WEAK_AV void LPUART1_IRQHandler(void)
452{ LPUART1_DriverIRQHandler();
453}
454
455WEAK_AV void UART2_FLEXIO_IRQHandler(void)
456{ UART2_FLEXIO_DriverIRQHandler();
457}
458
459WEAK_AV void ADC0_IRQHandler(void)
460{ ADC0_DriverIRQHandler();
461}
462
463WEAK_AV void CMP0_IRQHandler(void)
464{ CMP0_DriverIRQHandler();
465}
466
467WEAK_AV void TPM0_IRQHandler(void)
468{ TPM0_DriverIRQHandler();
469}
470
471WEAK_AV void TPM1_IRQHandler(void)
472{ TPM1_DriverIRQHandler();
473}
474
475WEAK_AV void TPM2_IRQHandler(void)
476{ TPM2_DriverIRQHandler();
477}
478
479WEAK_AV void RTC_IRQHandler(void)
480{ RTC_DriverIRQHandler();
481}
482
483WEAK_AV void RTC_Seconds_IRQHandler(void)
484{ RTC_Seconds_DriverIRQHandler();
485}
486
487WEAK_AV void PIT_IRQHandler(void)
488{ PIT_DriverIRQHandler();
489}
490
491WEAK_AV void Reserved39_IRQHandler(void)
492{ Reserved39_DriverIRQHandler();
493}
494
495WEAK_AV void USB0_IRQHandler(void)
496{ USB0_DriverIRQHandler();
497}
498
499WEAK_AV void DAC0_IRQHandler(void)
500{ DAC0_DriverIRQHandler();
501}
502
503WEAK_AV void Reserved42_IRQHandler(void)
504{ Reserved42_DriverIRQHandler();
505}
506
507WEAK_AV void Reserved43_IRQHandler(void)
508{ Reserved43_DriverIRQHandler();
509}
510
511WEAK_AV void LPTMR0_IRQHandler(void)
512{ LPTMR0_DriverIRQHandler();
513}
514
515WEAK_AV void LCD_IRQHandler(void)
516{ LCD_DriverIRQHandler();
517}
518
519WEAK_AV void PORTA_IRQHandler(void)
520{ PORTA_DriverIRQHandler();
521}
522
523WEAK_AV void PORTC_PORTD_IRQHandler(void)
524{ PORTC_PORTD_DriverIRQHandler();
525}
526
527//*****************************************************************************
528
529#if defined (DEBUG)
530#pragma GCC pop_options
531#endif // (DEBUG)