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