1/* ------------------------------------------------------------------------- */
2/*  @file:    startup_LPC51U68.s                                             */
3/*  @purpose: CMSIS Cortex-M0P Core Device Startup File                      */
4/*            LPC51U68                                                       */
5/*  @version: 1.0                                                            */
6/*  @date:    2017-12-15                                                     */
7/*  @build:   b230529                                                        */
8/* ------------------------------------------------------------------------- */
9/*                                                                           */
10/* Copyright 1997-2016 Freescale Semiconductor, Inc.                         */
11/* Copyright 2016-2023 NXP                                                   */
12/* SPDX-License-Identifier: BSD-3-Clause                                     */
13/*****************************************************************************/
14/* Version: GCC for ARM Embedded Processors                                  */
15/*****************************************************************************/
16    .syntax unified
17    .arch armv6-m
18
19    .section .isr_vector, "a"
20    .align 2
21    .globl __Vectors
22__Vectors:
23    .long   __StackTop                                      /* Top of Stack */
24    .long   Reset_Handler                                   /* Reset Handler */
25    .long   NMI_Handler                                     /* NMI Handler*/
26    .long   HardFault_Handler                               /* Hard Fault Handler*/
27    .long   0                                               /* Reserved*/
28    .long   0                                               /* Reserved*/
29    .long   0                                               /* Reserved*/
30    .long   0                                               /* Reserved*/
31    .long   0                                               /* Reserved*/
32    .long   0                                               /* Reserved*/
33    .long   0                                               /* Reserved*/
34    .long   SVC_Handler                                     /* SVCall Handler*/
35    .long   0                                               /* Reserved*/
36    .long   0                                               /* Reserved*/
37    .long   PendSV_Handler                                  /* PendSV Handler*/
38    .long   SysTick_Handler                                 /* SysTick Handler*/
39
40                                                            /* External Interrupts*/
41    .long   WDT_BOD_IRQHandler                              /* Windowed watchdog timer, Brownout detect*/
42    .long   DMA0_IRQHandler                                 /* DMA controller*/
43    .long   GINT0_IRQHandler                                /* GPIO group 0*/
44    .long   GINT1_IRQHandler                                /* GPIO group 1*/
45    .long   PIN_INT0_IRQHandler                             /* Pin interrupt 0 or pattern match engine slice 0*/
46    .long   PIN_INT1_IRQHandler                             /* Pin interrupt 1or pattern match engine slice 1*/
47    .long   PIN_INT2_IRQHandler                             /* Pin interrupt 2 or pattern match engine slice 2*/
48    .long   PIN_INT3_IRQHandler                             /* Pin interrupt 3 or pattern match engine slice 3*/
49    .long   UTICK0_IRQHandler                               /* Micro-tick Timer*/
50    .long   MRT0_IRQHandler                                 /* Multi-rate timer*/
51    .long   CTIMER0_IRQHandler                              /* Standard counter/timer CTIMER0*/
52    .long   CTIMER1_IRQHandler                              /* Standard counter/timer CTIMER1*/
53    .long   SCT0_IRQHandler                                 /* SCTimer/PWM*/
54    .long   CTIMER3_IRQHandler                              /* Standard counter/timer CTIMER3*/
55    .long   FLEXCOMM0_IRQHandler                            /* Flexcomm Interface 0 (USART, SPI, I2C)*/
56    .long   FLEXCOMM1_IRQHandler                            /* Flexcomm Interface 1 (USART, SPI, I2C)*/
57    .long   FLEXCOMM2_IRQHandler                            /* Flexcomm Interface 2 (USART, SPI, I2C)*/
58    .long   FLEXCOMM3_IRQHandler                            /* Flexcomm Interface 3 (USART, SPI, I2C)*/
59    .long   FLEXCOMM4_IRQHandler                            /* Flexcomm Interface 4 (USART, SPI, I2C)*/
60    .long   FLEXCOMM5_IRQHandler                            /* Flexcomm Interface 5 (USART, SPI, I2C)*/
61    .long   FLEXCOMM6_IRQHandler                            /* Flexcomm Interface 6 (USART, SPI, I2C, I2S)*/
62    .long   FLEXCOMM7_IRQHandler                            /* Flexcomm Interface 7 (USART, SPI, I2C, I2S)*/
63    .long   ADC0_SEQA_IRQHandler                            /* ADC0 sequence A completion.*/
64    .long   ADC0_SEQB_IRQHandler                            /* ADC0 sequence B completion.*/
65    .long   ADC0_THCMP_IRQHandler                           /* ADC0 threshold compare and error.*/
66    .long   Reserved41_IRQHandler                           /* Reserved interrupt*/
67    .long   Reserved42_IRQHandler                           /* Reserved interrupt*/
68    .long   USB0_NEEDCLK_IRQHandler                         /* USB Activity Wake-up Interrupt*/
69    .long   USB0_IRQHandler                                 /* USB device*/
70    .long   RTC_IRQHandler                                  /* RTC alarm and wake-up interrupts*/
71    .long   Reserved46_IRQHandler                           /* Reserved interrupt*/
72    .long   Reserved47_IRQHandler                           /* Reserved interrupt*/
73
74    .size   __Vectors, . - __Vectors
75
76/*  Variable to store CRP value in. No code read protection enabled by default
77 *  Code Read Protection level (CRP)
78 *    CRP_Level:
79 *      <0xFFFFFFFF=> Disabled
80 *      <0x4E697370=> NO_ISP
81 *      <0x12345678=> CRP1
82 *      <0x87654321=> CRP2
83 *      <0x43218765=> CRP3
84 */
85    #ifndef NO_CRP
86      .section .crp, "a"
87      .long 0xFFFFFFFF
88    #endif
89
90    .text
91    .thumb
92
93/* Reset Handler */
94
95    .thumb_func
96    .align 2
97    .globl   Reset_Handler
98    .weak    Reset_Handler
99    .type    Reset_Handler, %function
100Reset_Handler:
101    cpsid   i               /* Mask interrupts */
102#ifndef __NO_SYSTEM_INIT
103    ldr   r0,=SystemInit
104    blx   r0
105#endif
106/*     Loop to copy data from read only memory to RAM. The ranges
107 *      of copy from/to are specified by following symbols evaluated in
108 *      linker script.
109 *      __etext: End of code section, i.e., begin of data sections to copy from.
110 *      __data_start__/__data_end__: RAM address range that data should be
111 *      copied to. Both must be aligned to 4 bytes boundary.  */
112
113    ldr    r1, =__etext
114    ldr    r2, =__data_start__
115    ldr    r3, =__data_end__
116
117    subs    r3, r2
118    ble     .LC0
119
120.LC1:
121    subs    r3, 4
122    ldr    r0, [r1,r3]
123    str    r0, [r2,r3]
124    bgt    .LC1
125.LC0:
126
127#ifdef __STARTUP_CLEAR_BSS
128/*     This part of work usually is done in C library startup code. Otherwise,
129 *     define this macro to enable it in this startup.
130 *
131 *     Loop to zero out BSS section, which uses following symbols
132 *     in linker script:
133 *      __bss_start__: start of BSS section. Must align to 4
134 *      __bss_end__: end of BSS section. Must align to 4
135 */
136    ldr r1, =__bss_start__
137    ldr r2, =__bss_end__
138
139    subs    r2, r1
140    ble .LC3
141
142    movs    r0, 0
143.LC2:
144    subs    r2, 4
145    str r0, [r1, r2]
146    bgt .LC2
147.LC3:
148#endif
149    cpsie   i               /* Unmask interrupts */
150#ifndef __START
151#define __START _start
152#endif
153#ifndef __ATOLLIC__
154    ldr   r0,=__START
155    blx   r0
156#else
157    ldr   r0,=__libc_init_array
158    blx   r0
159    ldr   r0,=main
160    bx    r0
161#endif
162    .pool
163    .size Reset_Handler, . - Reset_Handler
164
165    .align  1
166    .thumb_func
167    .weak DefaultISR
168    .type DefaultISR, %function
169DefaultISR:
170    ldr r0, =DefaultISR
171    bx r0
172    .size DefaultISR, . - DefaultISR
173
174    .align 1
175    .thumb_func
176    .weak NMI_Handler
177    .type NMI_Handler, %function
178NMI_Handler:
179    ldr   r0,=NMI_Handler
180    bx    r0
181    .size NMI_Handler, . - NMI_Handler
182
183    .align 1
184    .thumb_func
185    .weak HardFault_Handler
186    .type HardFault_Handler, %function
187HardFault_Handler:
188    ldr   r0,=HardFault_Handler
189    bx    r0
190    .size HardFault_Handler, . - HardFault_Handler
191
192    .align 1
193    .thumb_func
194    .weak SVC_Handler
195    .type SVC_Handler, %function
196SVC_Handler:
197    ldr   r0,=SVC_Handler
198    bx    r0
199    .size SVC_Handler, . - SVC_Handler
200
201    .align 1
202    .thumb_func
203    .weak PendSV_Handler
204    .type PendSV_Handler, %function
205PendSV_Handler:
206    ldr   r0,=PendSV_Handler
207    bx    r0
208    .size PendSV_Handler, . - PendSV_Handler
209
210    .align 1
211    .thumb_func
212    .weak SysTick_Handler
213    .type SysTick_Handler, %function
214SysTick_Handler:
215    ldr   r0,=SysTick_Handler
216    bx    r0
217    .size SysTick_Handler, . - SysTick_Handler
218
219    .align 1
220    .thumb_func
221    .weak WDT_BOD_IRQHandler
222    .type WDT_BOD_IRQHandler, %function
223WDT_BOD_IRQHandler:
224    ldr   r0,=WDT_BOD_DriverIRQHandler
225    bx    r0
226    .size WDT_BOD_IRQHandler, . - WDT_BOD_IRQHandler
227
228    .align 1
229    .thumb_func
230    .weak DMA0_IRQHandler
231    .type DMA0_IRQHandler, %function
232DMA0_IRQHandler:
233    ldr   r0,=DMA0_DriverIRQHandler
234    bx    r0
235    .size DMA0_IRQHandler, . - DMA0_IRQHandler
236
237    .align 1
238    .thumb_func
239    .weak GINT0_IRQHandler
240    .type GINT0_IRQHandler, %function
241GINT0_IRQHandler:
242    ldr   r0,=GINT0_DriverIRQHandler
243    bx    r0
244    .size GINT0_IRQHandler, . - GINT0_IRQHandler
245
246    .align 1
247    .thumb_func
248    .weak GINT1_IRQHandler
249    .type GINT1_IRQHandler, %function
250GINT1_IRQHandler:
251    ldr   r0,=GINT1_DriverIRQHandler
252    bx    r0
253    .size GINT1_IRQHandler, . - GINT1_IRQHandler
254
255    .align 1
256    .thumb_func
257    .weak PIN_INT0_IRQHandler
258    .type PIN_INT0_IRQHandler, %function
259PIN_INT0_IRQHandler:
260    ldr   r0,=PIN_INT0_DriverIRQHandler
261    bx    r0
262    .size PIN_INT0_IRQHandler, . - PIN_INT0_IRQHandler
263
264    .align 1
265    .thumb_func
266    .weak PIN_INT1_IRQHandler
267    .type PIN_INT1_IRQHandler, %function
268PIN_INT1_IRQHandler:
269    ldr   r0,=PIN_INT1_DriverIRQHandler
270    bx    r0
271    .size PIN_INT1_IRQHandler, . - PIN_INT1_IRQHandler
272
273    .align 1
274    .thumb_func
275    .weak PIN_INT2_IRQHandler
276    .type PIN_INT2_IRQHandler, %function
277PIN_INT2_IRQHandler:
278    ldr   r0,=PIN_INT2_DriverIRQHandler
279    bx    r0
280    .size PIN_INT2_IRQHandler, . - PIN_INT2_IRQHandler
281
282    .align 1
283    .thumb_func
284    .weak PIN_INT3_IRQHandler
285    .type PIN_INT3_IRQHandler, %function
286PIN_INT3_IRQHandler:
287    ldr   r0,=PIN_INT3_DriverIRQHandler
288    bx    r0
289    .size PIN_INT3_IRQHandler, . - PIN_INT3_IRQHandler
290
291    .align 1
292    .thumb_func
293    .weak UTICK0_IRQHandler
294    .type UTICK0_IRQHandler, %function
295UTICK0_IRQHandler:
296    ldr   r0,=UTICK0_DriverIRQHandler
297    bx    r0
298    .size UTICK0_IRQHandler, . - UTICK0_IRQHandler
299
300    .align 1
301    .thumb_func
302    .weak MRT0_IRQHandler
303    .type MRT0_IRQHandler, %function
304MRT0_IRQHandler:
305    ldr   r0,=MRT0_DriverIRQHandler
306    bx    r0
307    .size MRT0_IRQHandler, . - MRT0_IRQHandler
308
309    .align 1
310    .thumb_func
311    .weak CTIMER0_IRQHandler
312    .type CTIMER0_IRQHandler, %function
313CTIMER0_IRQHandler:
314    ldr   r0,=CTIMER0_DriverIRQHandler
315    bx    r0
316    .size CTIMER0_IRQHandler, . - CTIMER0_IRQHandler
317
318    .align 1
319    .thumb_func
320    .weak CTIMER1_IRQHandler
321    .type CTIMER1_IRQHandler, %function
322CTIMER1_IRQHandler:
323    ldr   r0,=CTIMER1_DriverIRQHandler
324    bx    r0
325    .size CTIMER1_IRQHandler, . - CTIMER1_IRQHandler
326
327    .align 1
328    .thumb_func
329    .weak SCT0_IRQHandler
330    .type SCT0_IRQHandler, %function
331SCT0_IRQHandler:
332    ldr   r0,=SCT0_DriverIRQHandler
333    bx    r0
334    .size SCT0_IRQHandler, . - SCT0_IRQHandler
335
336    .align 1
337    .thumb_func
338    .weak CTIMER3_IRQHandler
339    .type CTIMER3_IRQHandler, %function
340CTIMER3_IRQHandler:
341    ldr   r0,=CTIMER3_DriverIRQHandler
342    bx    r0
343    .size CTIMER3_IRQHandler, . - CTIMER3_IRQHandler
344
345    .align 1
346    .thumb_func
347    .weak FLEXCOMM0_IRQHandler
348    .type FLEXCOMM0_IRQHandler, %function
349FLEXCOMM0_IRQHandler:
350    ldr   r0,=FLEXCOMM0_DriverIRQHandler
351    bx    r0
352    .size FLEXCOMM0_IRQHandler, . - FLEXCOMM0_IRQHandler
353
354    .align 1
355    .thumb_func
356    .weak FLEXCOMM1_IRQHandler
357    .type FLEXCOMM1_IRQHandler, %function
358FLEXCOMM1_IRQHandler:
359    ldr   r0,=FLEXCOMM1_DriverIRQHandler
360    bx    r0
361    .size FLEXCOMM1_IRQHandler, . - FLEXCOMM1_IRQHandler
362
363    .align 1
364    .thumb_func
365    .weak FLEXCOMM2_IRQHandler
366    .type FLEXCOMM2_IRQHandler, %function
367FLEXCOMM2_IRQHandler:
368    ldr   r0,=FLEXCOMM2_DriverIRQHandler
369    bx    r0
370    .size FLEXCOMM2_IRQHandler, . - FLEXCOMM2_IRQHandler
371
372    .align 1
373    .thumb_func
374    .weak FLEXCOMM3_IRQHandler
375    .type FLEXCOMM3_IRQHandler, %function
376FLEXCOMM3_IRQHandler:
377    ldr   r0,=FLEXCOMM3_DriverIRQHandler
378    bx    r0
379    .size FLEXCOMM3_IRQHandler, . - FLEXCOMM3_IRQHandler
380
381    .align 1
382    .thumb_func
383    .weak FLEXCOMM4_IRQHandler
384    .type FLEXCOMM4_IRQHandler, %function
385FLEXCOMM4_IRQHandler:
386    ldr   r0,=FLEXCOMM4_DriverIRQHandler
387    bx    r0
388    .size FLEXCOMM4_IRQHandler, . - FLEXCOMM4_IRQHandler
389
390    .align 1
391    .thumb_func
392    .weak FLEXCOMM5_IRQHandler
393    .type FLEXCOMM5_IRQHandler, %function
394FLEXCOMM5_IRQHandler:
395    ldr   r0,=FLEXCOMM5_DriverIRQHandler
396    bx    r0
397    .size FLEXCOMM5_IRQHandler, . - FLEXCOMM5_IRQHandler
398
399    .align 1
400    .thumb_func
401    .weak FLEXCOMM6_IRQHandler
402    .type FLEXCOMM6_IRQHandler, %function
403FLEXCOMM6_IRQHandler:
404    ldr   r0,=FLEXCOMM6_DriverIRQHandler
405    bx    r0
406    .size FLEXCOMM6_IRQHandler, . - FLEXCOMM6_IRQHandler
407
408    .align 1
409    .thumb_func
410    .weak FLEXCOMM7_IRQHandler
411    .type FLEXCOMM7_IRQHandler, %function
412FLEXCOMM7_IRQHandler:
413    ldr   r0,=FLEXCOMM7_DriverIRQHandler
414    bx    r0
415    .size FLEXCOMM7_IRQHandler, . - FLEXCOMM7_IRQHandler
416
417    .align 1
418    .thumb_func
419    .weak ADC0_SEQA_IRQHandler
420    .type ADC0_SEQA_IRQHandler, %function
421ADC0_SEQA_IRQHandler:
422    ldr   r0,=ADC0_SEQA_DriverIRQHandler
423    bx    r0
424    .size ADC0_SEQA_IRQHandler, . - ADC0_SEQA_IRQHandler
425
426    .align 1
427    .thumb_func
428    .weak ADC0_SEQB_IRQHandler
429    .type ADC0_SEQB_IRQHandler, %function
430ADC0_SEQB_IRQHandler:
431    ldr   r0,=ADC0_SEQB_DriverIRQHandler
432    bx    r0
433    .size ADC0_SEQB_IRQHandler, . - ADC0_SEQB_IRQHandler
434
435    .align 1
436    .thumb_func
437    .weak ADC0_THCMP_IRQHandler
438    .type ADC0_THCMP_IRQHandler, %function
439ADC0_THCMP_IRQHandler:
440    ldr   r0,=ADC0_THCMP_DriverIRQHandler
441    bx    r0
442    .size ADC0_THCMP_IRQHandler, . - ADC0_THCMP_IRQHandler
443
444    .align 1
445    .thumb_func
446    .weak Reserved41_IRQHandler
447    .type Reserved41_IRQHandler, %function
448Reserved41_IRQHandler:
449    ldr   r0,=Reserved41_DriverIRQHandler
450    bx    r0
451    .size Reserved41_IRQHandler, . - Reserved41_IRQHandler
452
453    .align 1
454    .thumb_func
455    .weak Reserved42_IRQHandler
456    .type Reserved42_IRQHandler, %function
457Reserved42_IRQHandler:
458    ldr   r0,=Reserved42_DriverIRQHandler
459    bx    r0
460    .size Reserved42_IRQHandler, . - Reserved42_IRQHandler
461
462    .align 1
463    .thumb_func
464    .weak USB0_NEEDCLK_IRQHandler
465    .type USB0_NEEDCLK_IRQHandler, %function
466USB0_NEEDCLK_IRQHandler:
467    ldr   r0,=USB0_NEEDCLK_DriverIRQHandler
468    bx    r0
469    .size USB0_NEEDCLK_IRQHandler, . - USB0_NEEDCLK_IRQHandler
470
471    .align 1
472    .thumb_func
473    .weak USB0_IRQHandler
474    .type USB0_IRQHandler, %function
475USB0_IRQHandler:
476    ldr   r0,=USB0_DriverIRQHandler
477    bx    r0
478    .size USB0_IRQHandler, . - USB0_IRQHandler
479
480    .align 1
481    .thumb_func
482    .weak RTC_IRQHandler
483    .type RTC_IRQHandler, %function
484RTC_IRQHandler:
485    ldr   r0,=RTC_DriverIRQHandler
486    bx    r0
487    .size RTC_IRQHandler, . - RTC_IRQHandler
488
489    .align 1
490    .thumb_func
491    .weak Reserved46_IRQHandler
492    .type Reserved46_IRQHandler, %function
493Reserved46_IRQHandler:
494    ldr   r0,=Reserved46_DriverIRQHandler
495    bx    r0
496    .size Reserved46_IRQHandler, . - Reserved46_IRQHandler
497
498    .align 1
499    .thumb_func
500    .weak Reserved47_IRQHandler
501    .type Reserved47_IRQHandler, %function
502Reserved47_IRQHandler:
503    ldr   r0,=Reserved47_DriverIRQHandler
504    bx    r0
505    .size Reserved47_IRQHandler, . - Reserved47_IRQHandler
506
507
508/*    Macro to define default handlers. Default handler
509 *    will be weak symbol and just dead loops. They can be
510 *    overwritten by other handlers */
511    .macro def_irq_handler  handler_name
512    .weak \handler_name
513    .set  \handler_name, DefaultISR
514    .endm
515    def_irq_handler    WDT_BOD_DriverIRQHandler
516    def_irq_handler    DMA0_DriverIRQHandler
517    def_irq_handler    GINT0_DriverIRQHandler
518    def_irq_handler    GINT1_DriverIRQHandler
519    def_irq_handler    PIN_INT0_DriverIRQHandler
520    def_irq_handler    PIN_INT1_DriverIRQHandler
521    def_irq_handler    PIN_INT2_DriverIRQHandler
522    def_irq_handler    PIN_INT3_DriverIRQHandler
523    def_irq_handler    UTICK0_DriverIRQHandler
524    def_irq_handler    MRT0_DriverIRQHandler
525    def_irq_handler    CTIMER0_DriverIRQHandler
526    def_irq_handler    CTIMER1_DriverIRQHandler
527    def_irq_handler    SCT0_DriverIRQHandler
528    def_irq_handler    CTIMER3_DriverIRQHandler
529    def_irq_handler    FLEXCOMM0_DriverIRQHandler
530    def_irq_handler    FLEXCOMM1_DriverIRQHandler
531    def_irq_handler    FLEXCOMM2_DriverIRQHandler
532    def_irq_handler    FLEXCOMM3_DriverIRQHandler
533    def_irq_handler    FLEXCOMM4_DriverIRQHandler
534    def_irq_handler    FLEXCOMM5_DriverIRQHandler
535    def_irq_handler    FLEXCOMM6_DriverIRQHandler
536    def_irq_handler    FLEXCOMM7_DriverIRQHandler
537    def_irq_handler    ADC0_SEQA_DriverIRQHandler
538    def_irq_handler    ADC0_SEQB_DriverIRQHandler
539    def_irq_handler    ADC0_THCMP_DriverIRQHandler
540    def_irq_handler    Reserved41_DriverIRQHandler
541    def_irq_handler    Reserved42_DriverIRQHandler
542    def_irq_handler    USB0_NEEDCLK_DriverIRQHandler
543    def_irq_handler    USB0_DriverIRQHandler
544    def_irq_handler    RTC_DriverIRQHandler
545    def_irq_handler    Reserved46_DriverIRQHandler
546    def_irq_handler    Reserved47_DriverIRQHandler
547
548    .end
549