aboutsummaryrefslogtreecommitdiff
path: root/lib/chibios-contrib/ext/mcux-sdk/devices/LPC51U68/mcuxpresso/startup_lpc51u68.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/chibios-contrib/ext/mcux-sdk/devices/LPC51U68/mcuxpresso/startup_lpc51u68.cpp')
-rw-r--r--lib/chibios-contrib/ext/mcux-sdk/devices/LPC51U68/mcuxpresso/startup_lpc51u68.cpp520
1 files changed, 520 insertions, 0 deletions
diff --git a/lib/chibios-contrib/ext/mcux-sdk/devices/LPC51U68/mcuxpresso/startup_lpc51u68.cpp b/lib/chibios-contrib/ext/mcux-sdk/devices/LPC51U68/mcuxpresso/startup_lpc51u68.cpp
new file mode 100644
index 000000000..35b26b62a
--- /dev/null
+++ b/lib/chibios-contrib/ext/mcux-sdk/devices/LPC51U68/mcuxpresso/startup_lpc51u68.cpp
@@ -0,0 +1,520 @@
1//*****************************************************************************
2// LPC51U68 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// 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#include <NXP/crp.h>
48__CRP const unsigned int CRP_WORD = CRP_NO_CRP ;
49
50//*****************************************************************************
51// Declaration of external SystemInit function
52//*****************************************************************************
53#if defined (__USE_CMSIS)
54extern void SystemInit(void);
55#endif // (__USE_CMSIS)
56
57//*****************************************************************************
58// Forward declaration of the core exception handlers.
59// When the application defines a handler (with the same name), this will
60// automatically take precedence over these weak definitions.
61// If your application is a C++ one, then any interrupt handlers defined
62// in C++ files within in your main application will need to have C linkage
63// rather than C++ linkage. To do this, make sure that you are using extern "C"
64// { .... } around the interrupt handler within your main application code.
65//*****************************************************************************
66 void ResetISR(void);
67WEAK void NMI_Handler(void);
68WEAK void HardFault_Handler(void);
69WEAK void SVC_Handler(void);
70WEAK void PendSV_Handler(void);
71WEAK void SysTick_Handler(void);
72WEAK void IntDefaultHandler(void);
73
74//*****************************************************************************
75// Forward declaration of the application IRQ handlers. When the application
76// defines a handler (with the same name), this will automatically take
77// precedence over weak definitions below
78//*****************************************************************************
79WEAK void WDT_BOD_IRQHandler(void);
80WEAK void DMA0_IRQHandler(void);
81WEAK void GINT0_IRQHandler(void);
82WEAK void GINT1_IRQHandler(void);
83WEAK void PIN_INT0_IRQHandler(void);
84WEAK void PIN_INT1_IRQHandler(void);
85WEAK void PIN_INT2_IRQHandler(void);
86WEAK void PIN_INT3_IRQHandler(void);
87WEAK void UTICK0_IRQHandler(void);
88WEAK void MRT0_IRQHandler(void);
89WEAK void CTIMER0_IRQHandler(void);
90WEAK void CTIMER1_IRQHandler(void);
91WEAK void SCT0_IRQHandler(void);
92WEAK void CTIMER3_IRQHandler(void);
93WEAK void FLEXCOMM0_IRQHandler(void);
94WEAK void FLEXCOMM1_IRQHandler(void);
95WEAK void FLEXCOMM2_IRQHandler(void);
96WEAK void FLEXCOMM3_IRQHandler(void);
97WEAK void FLEXCOMM4_IRQHandler(void);
98WEAK void FLEXCOMM5_IRQHandler(void);
99WEAK void FLEXCOMM6_IRQHandler(void);
100WEAK void FLEXCOMM7_IRQHandler(void);
101WEAK void ADC0_SEQA_IRQHandler(void);
102WEAK void ADC0_SEQB_IRQHandler(void);
103WEAK void ADC0_THCMP_IRQHandler(void);
104WEAK void Reserved41_IRQHandler(void);
105WEAK void Reserved42_IRQHandler(void);
106WEAK void USB0_NEEDCLK_IRQHandler(void);
107WEAK void USB0_IRQHandler(void);
108WEAK void RTC_IRQHandler(void);
109
110//*****************************************************************************
111// Forward declaration of the driver IRQ handlers. These are aliased
112// to the IntDefaultHandler, which is a 'forever' loop. When the driver
113// defines a handler (with the same name), this will automatically take
114// precedence over these weak definitions
115//*****************************************************************************
116void WDT_BOD_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
117void DMA0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
118void GINT0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
119void GINT1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
120void PIN_INT0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
121void PIN_INT1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
122void PIN_INT2_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
123void PIN_INT3_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
124void UTICK0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
125void MRT0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
126void CTIMER0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
127void CTIMER1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
128void SCT0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
129void CTIMER3_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
130void FLEXCOMM0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
131void FLEXCOMM1_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
132void FLEXCOMM2_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
133void FLEXCOMM3_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
134void FLEXCOMM4_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
135void FLEXCOMM5_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
136void FLEXCOMM6_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
137void FLEXCOMM7_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
138void ADC0_SEQA_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
139void ADC0_SEQB_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
140void ADC0_THCMP_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
141void Reserved41_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
142void Reserved42_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
143void USB0_NEEDCLK_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
144void USB0_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
145void RTC_DriverIRQHandler(void) ALIAS(IntDefaultHandler);
146
147//*****************************************************************************
148// The entry point for the application.
149// __main() is the entry point for Redlib based applications
150// main() is the entry point for Newlib based applications
151//*****************************************************************************
152#if defined (__REDLIB__)
153extern void __main(void);
154#endif
155extern int main(void);
156
157//*****************************************************************************
158// External declaration for the pointer to the stack top from the Linker Script
159//*****************************************************************************
160extern void _vStackTop(void);
161//*****************************************************************************
162// External declaration for LPC MCU vector table checksum from Linker Script
163//*****************************************************************************
164WEAK extern void __valid_user_code_checksum();
165
166//*****************************************************************************
167//*****************************************************************************
168#if defined (__cplusplus)
169} // extern "C"
170#endif
171//*****************************************************************************
172// The vector table.
173// This relies on the linker script to place at correct location in memory.
174//*****************************************************************************
175
176
177
178extern void (* const g_pfnVectors[])(void);
179extern void * __Vectors __attribute__ ((alias ("g_pfnVectors")));
180
181__attribute__ ((used, section(".isr_vector")))
182void (* const g_pfnVectors[])(void) = {
183 // Core Level - CM0P
184 &_vStackTop, // The initial stack pointer
185 ResetISR, // The reset handler
186 NMI_Handler, // The NMI handler
187 HardFault_Handler, // The hard fault handler
188 0, // Reserved
189 0, // Reserved
190 0, // Reserved
191 __valid_user_code_checksum, // LPC MCU checksum
192 0, // ECRP
193 0, // Reserved
194 0, // Reserved
195 SVC_Handler, // SVCall handler
196 0, // Reserved
197 0, // Reserved
198 PendSV_Handler, // The PendSV handler
199 SysTick_Handler, // The SysTick handler
200
201 // Chip Level - LPC51U68
202 WDT_BOD_IRQHandler, // 16: Windowed watchdog timer, Brownout detect
203 DMA0_IRQHandler, // 17: DMA controller
204 GINT0_IRQHandler, // 18: GPIO group 0
205 GINT1_IRQHandler, // 19: GPIO group 1
206 PIN_INT0_IRQHandler, // 20: Pin interrupt 0 or pattern match engine slice 0
207 PIN_INT1_IRQHandler, // 21: Pin interrupt 1or pattern match engine slice 1
208 PIN_INT2_IRQHandler, // 22: Pin interrupt 2 or pattern match engine slice 2
209 PIN_INT3_IRQHandler, // 23: Pin interrupt 3 or pattern match engine slice 3
210 UTICK0_IRQHandler, // 24: Micro-tick Timer
211 MRT0_IRQHandler, // 25: Multi-rate timer
212 CTIMER0_IRQHandler, // 26: Standard counter/timer CTIMER0
213 CTIMER1_IRQHandler, // 27: Standard counter/timer CTIMER1
214 SCT0_IRQHandler, // 28: SCTimer/PWM
215 CTIMER3_IRQHandler, // 29: Standard counter/timer CTIMER3
216 FLEXCOMM0_IRQHandler, // 30: Flexcomm Interface 0 (USART, SPI, I2C)
217 FLEXCOMM1_IRQHandler, // 31: Flexcomm Interface 1 (USART, SPI, I2C)
218 FLEXCOMM2_IRQHandler, // 32: Flexcomm Interface 2 (USART, SPI, I2C)
219 FLEXCOMM3_IRQHandler, // 33: Flexcomm Interface 3 (USART, SPI, I2C)
220 FLEXCOMM4_IRQHandler, // 34: Flexcomm Interface 4 (USART, SPI, I2C)
221 FLEXCOMM5_IRQHandler, // 35: Flexcomm Interface 5 (USART, SPI, I2C)
222 FLEXCOMM6_IRQHandler, // 36: Flexcomm Interface 6 (USART, SPI, I2C, I2S)
223 FLEXCOMM7_IRQHandler, // 37: Flexcomm Interface 7 (USART, SPI, I2C, I2S)
224 ADC0_SEQA_IRQHandler, // 38: ADC0 sequence A completion.
225 ADC0_SEQB_IRQHandler, // 39: ADC0 sequence B completion.
226 ADC0_THCMP_IRQHandler, // 40: ADC0 threshold compare and error.
227 Reserved41_IRQHandler, // 41: Reserved interrupt
228 Reserved42_IRQHandler, // 42: Reserved interrupt
229 USB0_NEEDCLK_IRQHandler, // 43: USB Activity Wake-up Interrupt
230 USB0_IRQHandler, // 44: USB device
231 RTC_IRQHandler, // 45: RTC alarm and wake-up interrupts
232
233
234}; /* End of g_pfnVectors */
235
236//*****************************************************************************
237// Functions to carry out the initialization of RW and BSS data sections. These
238// are written as separate functions rather than being inlined within the
239// ResetISR() function in order to cope with MCUs with multiple banks of
240// memory.
241//*****************************************************************************
242__attribute__ ((section(".after_vectors.init_data")))
243void data_init(unsigned int romstart, unsigned int start, unsigned int len) {
244 unsigned int *pulDest = (unsigned int*) start;
245 unsigned int *pulSrc = (unsigned int*) romstart;
246 unsigned int loop;
247 for (loop = 0; loop < len; loop = loop + 4)
248 *pulDest++ = *pulSrc++;
249}
250
251__attribute__ ((section(".after_vectors.init_bss")))
252void bss_init(unsigned int start, unsigned int len) {
253 unsigned int *pulDest = (unsigned int*) start;
254 unsigned int loop;
255 for (loop = 0; loop < len; loop = loop + 4)
256 *pulDest++ = 0;
257}
258
259//*****************************************************************************
260// The following symbols are constructs generated by the linker, indicating
261// the location of various points in the "Global Section Table". This table is
262// created by the linker via the Code Red managed linker script mechanism. It
263// contains the load address, execution address and length of each RW data
264// section and the execution and length of each BSS (zero initialized) section.
265//*****************************************************************************
266extern unsigned int __data_section_table;
267extern unsigned int __data_section_table_end;
268extern unsigned int __bss_section_table;
269extern unsigned int __bss_section_table_end;
270
271//*****************************************************************************
272// Reset entry point for your code.
273// Sets up a simple runtime environment and initializes the C/C++
274// library.
275//*****************************************************************************
276__attribute__ ((section(".after_vectors.reset")))
277void ResetISR(void) {
278
279 // Disable interrupts
280 __asm volatile ("cpsid i");
281
282
283 // Enable SRAM clock used by Stack
284 __asm volatile ("LDR R0, =0x40000220\n\t"
285 "MOV R1, #56\n\t"
286 "STR R1, [R0]");
287
288#if defined (__USE_CMSIS)
289// If __USE_CMSIS defined, then call CMSIS SystemInit code
290 SystemInit();
291
292#endif // (__USE_CMSIS)
293
294 //
295 // Copy the data sections from flash to SRAM.
296 //
297 unsigned int LoadAddr, ExeAddr, SectionLen;
298 unsigned int *SectionTableAddr;
299
300 // Load base address of Global Section Table
301 SectionTableAddr = &__data_section_table;
302
303 // Copy the data sections from flash to SRAM.
304 while (SectionTableAddr < &__data_section_table_end) {
305 LoadAddr = *SectionTableAddr++;
306 ExeAddr = *SectionTableAddr++;
307 SectionLen = *SectionTableAddr++;
308 data_init(LoadAddr, ExeAddr, SectionLen);
309 }
310
311 // At this point, SectionTableAddr = &__bss_section_table;
312 // Zero fill the bss segment
313 while (SectionTableAddr < &__bss_section_table_end) {
314 ExeAddr = *SectionTableAddr++;
315 SectionLen = *SectionTableAddr++;
316 bss_init(ExeAddr, SectionLen);
317 }
318
319
320#if !defined (__USE_CMSIS)
321// Assume that if __USE_CMSIS defined, then CMSIS SystemInit code
322// will setup the VTOR register
323
324 // Check to see if we are running the code from a non-zero
325 // address (eg RAM, external flash), in which case we need
326 // to modify the VTOR register to tell the CPU that the
327 // vector table is located at a non-0x0 address.
328 unsigned int * pSCB_VTOR = (unsigned int *) 0xE000ED08;
329 if ((unsigned int *)g_pfnVectors!=(unsigned int *) 0x00000000) {
330 *pSCB_VTOR = (unsigned int)g_pfnVectors;
331 }
332#endif // (__USE_CMSIS)
333#if defined (__cplusplus)
334 //
335 // Call C++ library initialisation
336 //
337 __libc_init_array();
338#endif
339
340 // Reenable interrupts
341 __asm volatile ("cpsie i");
342
343#if defined (__REDLIB__)
344 // Call the Redlib library, which in turn calls main()
345 __main();
346#else
347 main();
348#endif
349
350 //
351 // main() shouldn't return, but if it does, we'll just enter an infinite loop
352 //
353 while (1) {
354 ;
355 }
356}
357
358//*****************************************************************************
359// Default core exception handlers. Override the ones here by defining your own
360// handler routines in your application code.
361//*****************************************************************************
362WEAK_AV void NMI_Handler(void)
363{ while(1) {}
364}
365
366WEAK_AV void HardFault_Handler(void)
367{ while(1) {}
368}
369
370WEAK_AV void SVC_Handler(void)
371{ while(1) {}
372}
373
374WEAK_AV void PendSV_Handler(void)
375{ while(1) {}
376}
377
378WEAK_AV void SysTick_Handler(void)
379{ while(1) {}
380}
381
382//*****************************************************************************
383// Processor ends up here if an unexpected interrupt occurs or a specific
384// handler is not present in the application code.
385//*****************************************************************************
386WEAK_AV void IntDefaultHandler(void)
387{ while(1) {}
388}
389
390//*****************************************************************************
391// Default application exception handlers. Override the ones here by defining
392// your own handler routines in your application code. These routines call
393// driver exception handlers or IntDefaultHandler() if no driver exception
394// handler is included.
395//*****************************************************************************
396WEAK_AV void WDT_BOD_IRQHandler(void)
397{ WDT_BOD_DriverIRQHandler();
398}
399
400WEAK_AV void DMA0_IRQHandler(void)
401{ DMA0_DriverIRQHandler();
402}
403
404WEAK_AV void GINT0_IRQHandler(void)
405{ GINT0_DriverIRQHandler();
406}
407
408WEAK_AV void GINT1_IRQHandler(void)
409{ GINT1_DriverIRQHandler();
410}
411
412WEAK_AV void PIN_INT0_IRQHandler(void)
413{ PIN_INT0_DriverIRQHandler();
414}
415
416WEAK_AV void PIN_INT1_IRQHandler(void)
417{ PIN_INT1_DriverIRQHandler();
418}
419
420WEAK_AV void PIN_INT2_IRQHandler(void)
421{ PIN_INT2_DriverIRQHandler();
422}
423
424WEAK_AV void PIN_INT3_IRQHandler(void)
425{ PIN_INT3_DriverIRQHandler();
426}
427
428WEAK_AV void UTICK0_IRQHandler(void)
429{ UTICK0_DriverIRQHandler();
430}
431
432WEAK_AV void MRT0_IRQHandler(void)
433{ MRT0_DriverIRQHandler();
434}
435
436WEAK_AV void CTIMER0_IRQHandler(void)
437{ CTIMER0_DriverIRQHandler();
438}
439
440WEAK_AV void CTIMER1_IRQHandler(void)
441{ CTIMER1_DriverIRQHandler();
442}
443
444WEAK_AV void SCT0_IRQHandler(void)
445{ SCT0_DriverIRQHandler();
446}
447
448WEAK_AV void CTIMER3_IRQHandler(void)
449{ CTIMER3_DriverIRQHandler();
450}
451
452WEAK_AV void FLEXCOMM0_IRQHandler(void)
453{ FLEXCOMM0_DriverIRQHandler();
454}
455
456WEAK_AV void FLEXCOMM1_IRQHandler(void)
457{ FLEXCOMM1_DriverIRQHandler();
458}
459
460WEAK_AV void FLEXCOMM2_IRQHandler(void)
461{ FLEXCOMM2_DriverIRQHandler();
462}
463
464WEAK_AV void FLEXCOMM3_IRQHandler(void)
465{ FLEXCOMM3_DriverIRQHandler();
466}
467
468WEAK_AV void FLEXCOMM4_IRQHandler(void)
469{ FLEXCOMM4_DriverIRQHandler();
470}
471
472WEAK_AV void FLEXCOMM5_IRQHandler(void)
473{ FLEXCOMM5_DriverIRQHandler();
474}
475
476WEAK_AV void FLEXCOMM6_IRQHandler(void)
477{ FLEXCOMM6_DriverIRQHandler();
478}
479
480WEAK_AV void FLEXCOMM7_IRQHandler(void)
481{ FLEXCOMM7_DriverIRQHandler();
482}
483
484WEAK_AV void ADC0_SEQA_IRQHandler(void)
485{ ADC0_SEQA_DriverIRQHandler();
486}
487
488WEAK_AV void ADC0_SEQB_IRQHandler(void)
489{ ADC0_SEQB_DriverIRQHandler();
490}
491
492WEAK_AV void ADC0_THCMP_IRQHandler(void)
493{ ADC0_THCMP_DriverIRQHandler();
494}
495
496WEAK_AV void Reserved41_IRQHandler(void)
497{ Reserved41_DriverIRQHandler();
498}
499
500WEAK_AV void Reserved42_IRQHandler(void)
501{ Reserved42_DriverIRQHandler();
502}
503
504WEAK_AV void USB0_NEEDCLK_IRQHandler(void)
505{ USB0_NEEDCLK_DriverIRQHandler();
506}
507
508WEAK_AV void USB0_IRQHandler(void)
509{ USB0_DriverIRQHandler();
510}
511
512WEAK_AV void RTC_IRQHandler(void)
513{ RTC_DriverIRQHandler();
514}
515
516//*****************************************************************************
517
518#if defined (DEBUG)
519#pragma GCC pop_options
520#endif // (DEBUG)