1/* ------------------------------------------------------------------------- */
2/*  @file:    startup_LPC832.s                                               */
3/*  @purpose: CMSIS Cortex-M0P Core Device Startup File                      */
4/*            LPC832                                                         */
5/*  @version: 1.1                                                            */
6/*  @date:    2018-2-25                                                      */
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   SPI0_IRQHandler                                 /* SPI0 interrupt*/
42    .long   SPI1_IRQHandler                                 /* SPI1 interrupt*/
43    .long   Reserved18_IRQHandler                           /* Reserved interrupt*/
44    .long   USART0_IRQHandler                               /* USART0 interrupt*/
45    .long   Reserved20_IRQHandler                           /* Reserved interrupt*/
46    .long   Reserved21_IRQHandler                           /* Reserved interrupt*/
47    .long   Reserved22_IRQHandler                           /* Reserved interrupt*/
48    .long   Reserved23_IRQHandler                           /* Reserved interrupt*/
49    .long   I2C0_IRQHandler                                 /* I2C0 interrupt*/
50    .long   SCT0_IRQHandler                                 /* State configurable timer interrupt*/
51    .long   MRT0_IRQHandler                                 /* Multi-rate timer interrupt*/
52    .long   Reserved27_IRQHandler                           /* Reserved interrupt*/
53    .long   WDT_IRQHandler                                  /* Windowed watchdog timer interrupt*/
54    .long   BOD_IRQHandler                                  /* BOD interrupts*/
55    .long   FLASH_IRQHandler                                /* flash interrupt*/
56    .long   WKT_IRQHandler                                  /* Self-wake-up timer interrupt*/
57    .long   ADC0_SEQA_IRQHandler                            /* ADC0 sequence A completion.*/
58    .long   ADC0_SEQB_IRQHandler                            /* ADC0 sequence B completion.*/
59    .long   ADC0_THCMP_IRQHandler                           /* ADC0 threshold compare and error.*/
60    .long   ADC0_OVR_IRQHandler                             /* ADC0 overrun*/
61    .long   DMA0_IRQHandler                                 /* DMA0 interrupt*/
62    .long   Reserved37_IRQHandler                           /* Reserved interrupt*/
63    .long   Reserved38_IRQHandler                           /* Reserved interrupt*/
64    .long   Reserved39_IRQHandler                           /* Reserved interrupt*/
65    .long   PIN_INT0_IRQHandler                             /* Pin interrupt 0 or pattern match engine slice 0 interrupt*/
66    .long   PIN_INT1_IRQHandler                             /* Pin interrupt 1 or pattern match engine slice 1 interrupt*/
67    .long   PIN_INT2_IRQHandler                             /* Pin interrupt 2 or pattern match engine slice 2 interrupt*/
68    .long   PIN_INT3_IRQHandler                             /* Pin interrupt 3 or pattern match engine slice 3 interrupt*/
69    .long   PIN_INT4_IRQHandler                             /* Pin interrupt 4 or pattern match engine slice 4 interrupt*/
70    .long   PIN_INT5_IRQHandler                             /* Pin interrupt 5 or pattern match engine slice 5 interrupt*/
71    .long   PIN_INT6_IRQHandler                             /* Pin interrupt 6 or pattern match engine slice 6 interrupt*/
72    .long   PIN_INT7_IRQHandler                             /* Pin interrupt 7 or pattern match engine slice 7 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 SPI0_IRQHandler
222    .type SPI0_IRQHandler, %function
223SPI0_IRQHandler:
224    ldr   r0,=SPI0_DriverIRQHandler
225    bx    r0
226    .size SPI0_IRQHandler, . - SPI0_IRQHandler
227
228    .align 1
229    .thumb_func
230    .weak SPI1_IRQHandler
231    .type SPI1_IRQHandler, %function
232SPI1_IRQHandler:
233    ldr   r0,=SPI1_DriverIRQHandler
234    bx    r0
235    .size SPI1_IRQHandler, . - SPI1_IRQHandler
236
237    .align 1
238    .thumb_func
239    .weak Reserved18_IRQHandler
240    .type Reserved18_IRQHandler, %function
241Reserved18_IRQHandler:
242    ldr   r0,=Reserved18_DriverIRQHandler
243    bx    r0
244    .size Reserved18_IRQHandler, . - Reserved18_IRQHandler
245
246    .align 1
247    .thumb_func
248    .weak USART0_IRQHandler
249    .type USART0_IRQHandler, %function
250USART0_IRQHandler:
251    ldr   r0,=USART0_DriverIRQHandler
252    bx    r0
253    .size USART0_IRQHandler, . - USART0_IRQHandler
254
255    .align 1
256    .thumb_func
257    .weak Reserved20_IRQHandler
258    .type Reserved20_IRQHandler, %function
259Reserved20_IRQHandler:
260    ldr   r0,=Reserved20_DriverIRQHandler
261    bx    r0
262    .size Reserved20_IRQHandler, . - Reserved20_IRQHandler
263
264    .align 1
265    .thumb_func
266    .weak Reserved21_IRQHandler
267    .type Reserved21_IRQHandler, %function
268Reserved21_IRQHandler:
269    ldr   r0,=Reserved21_DriverIRQHandler
270    bx    r0
271    .size Reserved21_IRQHandler, . - Reserved21_IRQHandler
272
273    .align 1
274    .thumb_func
275    .weak Reserved22_IRQHandler
276    .type Reserved22_IRQHandler, %function
277Reserved22_IRQHandler:
278    ldr   r0,=Reserved22_DriverIRQHandler
279    bx    r0
280    .size Reserved22_IRQHandler, . - Reserved22_IRQHandler
281
282    .align 1
283    .thumb_func
284    .weak Reserved23_IRQHandler
285    .type Reserved23_IRQHandler, %function
286Reserved23_IRQHandler:
287    ldr   r0,=Reserved23_DriverIRQHandler
288    bx    r0
289    .size Reserved23_IRQHandler, . - Reserved23_IRQHandler
290
291    .align 1
292    .thumb_func
293    .weak I2C0_IRQHandler
294    .type I2C0_IRQHandler, %function
295I2C0_IRQHandler:
296    ldr   r0,=I2C0_DriverIRQHandler
297    bx    r0
298    .size I2C0_IRQHandler, . - I2C0_IRQHandler
299
300    .align 1
301    .thumb_func
302    .weak SCT0_IRQHandler
303    .type SCT0_IRQHandler, %function
304SCT0_IRQHandler:
305    ldr   r0,=SCT0_DriverIRQHandler
306    bx    r0
307    .size SCT0_IRQHandler, . - SCT0_IRQHandler
308
309    .align 1
310    .thumb_func
311    .weak MRT0_IRQHandler
312    .type MRT0_IRQHandler, %function
313MRT0_IRQHandler:
314    ldr   r0,=MRT0_DriverIRQHandler
315    bx    r0
316    .size MRT0_IRQHandler, . - MRT0_IRQHandler
317
318    .align 1
319    .thumb_func
320    .weak Reserved27_IRQHandler
321    .type Reserved27_IRQHandler, %function
322Reserved27_IRQHandler:
323    ldr   r0,=Reserved27_DriverIRQHandler
324    bx    r0
325    .size Reserved27_IRQHandler, . - Reserved27_IRQHandler
326
327    .align 1
328    .thumb_func
329    .weak WDT_IRQHandler
330    .type WDT_IRQHandler, %function
331WDT_IRQHandler:
332    ldr   r0,=WDT_DriverIRQHandler
333    bx    r0
334    .size WDT_IRQHandler, . - WDT_IRQHandler
335
336    .align 1
337    .thumb_func
338    .weak BOD_IRQHandler
339    .type BOD_IRQHandler, %function
340BOD_IRQHandler:
341    ldr   r0,=BOD_DriverIRQHandler
342    bx    r0
343    .size BOD_IRQHandler, . - BOD_IRQHandler
344
345    .align 1
346    .thumb_func
347    .weak FLASH_IRQHandler
348    .type FLASH_IRQHandler, %function
349FLASH_IRQHandler:
350    ldr   r0,=FLASH_DriverIRQHandler
351    bx    r0
352    .size FLASH_IRQHandler, . - FLASH_IRQHandler
353
354    .align 1
355    .thumb_func
356    .weak WKT_IRQHandler
357    .type WKT_IRQHandler, %function
358WKT_IRQHandler:
359    ldr   r0,=WKT_DriverIRQHandler
360    bx    r0
361    .size WKT_IRQHandler, . - WKT_IRQHandler
362
363    .align 1
364    .thumb_func
365    .weak ADC0_SEQA_IRQHandler
366    .type ADC0_SEQA_IRQHandler, %function
367ADC0_SEQA_IRQHandler:
368    ldr   r0,=ADC0_SEQA_DriverIRQHandler
369    bx    r0
370    .size ADC0_SEQA_IRQHandler, . - ADC0_SEQA_IRQHandler
371
372    .align 1
373    .thumb_func
374    .weak ADC0_SEQB_IRQHandler
375    .type ADC0_SEQB_IRQHandler, %function
376ADC0_SEQB_IRQHandler:
377    ldr   r0,=ADC0_SEQB_DriverIRQHandler
378    bx    r0
379    .size ADC0_SEQB_IRQHandler, . - ADC0_SEQB_IRQHandler
380
381    .align 1
382    .thumb_func
383    .weak ADC0_THCMP_IRQHandler
384    .type ADC0_THCMP_IRQHandler, %function
385ADC0_THCMP_IRQHandler:
386    ldr   r0,=ADC0_THCMP_DriverIRQHandler
387    bx    r0
388    .size ADC0_THCMP_IRQHandler, . - ADC0_THCMP_IRQHandler
389
390    .align 1
391    .thumb_func
392    .weak ADC0_OVR_IRQHandler
393    .type ADC0_OVR_IRQHandler, %function
394ADC0_OVR_IRQHandler:
395    ldr   r0,=ADC0_OVR_DriverIRQHandler
396    bx    r0
397    .size ADC0_OVR_IRQHandler, . - ADC0_OVR_IRQHandler
398
399    .align 1
400    .thumb_func
401    .weak DMA0_IRQHandler
402    .type DMA0_IRQHandler, %function
403DMA0_IRQHandler:
404    ldr   r0,=DMA0_DriverIRQHandler
405    bx    r0
406    .size DMA0_IRQHandler, . - DMA0_IRQHandler
407
408    .align 1
409    .thumb_func
410    .weak Reserved37_IRQHandler
411    .type Reserved37_IRQHandler, %function
412Reserved37_IRQHandler:
413    ldr   r0,=Reserved37_DriverIRQHandler
414    bx    r0
415    .size Reserved37_IRQHandler, . - Reserved37_IRQHandler
416
417    .align 1
418    .thumb_func
419    .weak Reserved38_IRQHandler
420    .type Reserved38_IRQHandler, %function
421Reserved38_IRQHandler:
422    ldr   r0,=Reserved38_DriverIRQHandler
423    bx    r0
424    .size Reserved38_IRQHandler, . - Reserved38_IRQHandler
425
426    .align 1
427    .thumb_func
428    .weak Reserved39_IRQHandler
429    .type Reserved39_IRQHandler, %function
430Reserved39_IRQHandler:
431    ldr   r0,=Reserved39_DriverIRQHandler
432    bx    r0
433    .size Reserved39_IRQHandler, . - Reserved39_IRQHandler
434
435    .align 1
436    .thumb_func
437    .weak PIN_INT0_IRQHandler
438    .type PIN_INT0_IRQHandler, %function
439PIN_INT0_IRQHandler:
440    ldr   r0,=PIN_INT0_DriverIRQHandler
441    bx    r0
442    .size PIN_INT0_IRQHandler, . - PIN_INT0_IRQHandler
443
444    .align 1
445    .thumb_func
446    .weak PIN_INT1_IRQHandler
447    .type PIN_INT1_IRQHandler, %function
448PIN_INT1_IRQHandler:
449    ldr   r0,=PIN_INT1_DriverIRQHandler
450    bx    r0
451    .size PIN_INT1_IRQHandler, . - PIN_INT1_IRQHandler
452
453    .align 1
454    .thumb_func
455    .weak PIN_INT2_IRQHandler
456    .type PIN_INT2_IRQHandler, %function
457PIN_INT2_IRQHandler:
458    ldr   r0,=PIN_INT2_DriverIRQHandler
459    bx    r0
460    .size PIN_INT2_IRQHandler, . - PIN_INT2_IRQHandler
461
462    .align 1
463    .thumb_func
464    .weak PIN_INT3_IRQHandler
465    .type PIN_INT3_IRQHandler, %function
466PIN_INT3_IRQHandler:
467    ldr   r0,=PIN_INT3_DriverIRQHandler
468    bx    r0
469    .size PIN_INT3_IRQHandler, . - PIN_INT3_IRQHandler
470
471    .align 1
472    .thumb_func
473    .weak PIN_INT4_IRQHandler
474    .type PIN_INT4_IRQHandler, %function
475PIN_INT4_IRQHandler:
476    ldr   r0,=PIN_INT4_DriverIRQHandler
477    bx    r0
478    .size PIN_INT4_IRQHandler, . - PIN_INT4_IRQHandler
479
480    .align 1
481    .thumb_func
482    .weak PIN_INT5_IRQHandler
483    .type PIN_INT5_IRQHandler, %function
484PIN_INT5_IRQHandler:
485    ldr   r0,=PIN_INT5_DriverIRQHandler
486    bx    r0
487    .size PIN_INT5_IRQHandler, . - PIN_INT5_IRQHandler
488
489    .align 1
490    .thumb_func
491    .weak PIN_INT6_IRQHandler
492    .type PIN_INT6_IRQHandler, %function
493PIN_INT6_IRQHandler:
494    ldr   r0,=PIN_INT6_DriverIRQHandler
495    bx    r0
496    .size PIN_INT6_IRQHandler, . - PIN_INT6_IRQHandler
497
498    .align 1
499    .thumb_func
500    .weak PIN_INT7_IRQHandler
501    .type PIN_INT7_IRQHandler, %function
502PIN_INT7_IRQHandler:
503    ldr   r0,=PIN_INT7_DriverIRQHandler
504    bx    r0
505    .size PIN_INT7_IRQHandler, . - PIN_INT7_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    SPI0_DriverIRQHandler
516    def_irq_handler    SPI1_DriverIRQHandler
517    def_irq_handler    Reserved18_DriverIRQHandler
518    def_irq_handler    USART0_DriverIRQHandler
519    def_irq_handler    Reserved20_DriverIRQHandler
520    def_irq_handler    Reserved21_DriverIRQHandler
521    def_irq_handler    Reserved22_DriverIRQHandler
522    def_irq_handler    Reserved23_DriverIRQHandler
523    def_irq_handler    I2C0_DriverIRQHandler
524    def_irq_handler    SCT0_DriverIRQHandler
525    def_irq_handler    MRT0_DriverIRQHandler
526    def_irq_handler    Reserved27_DriverIRQHandler
527    def_irq_handler    WDT_DriverIRQHandler
528    def_irq_handler    BOD_DriverIRQHandler
529    def_irq_handler    FLASH_DriverIRQHandler
530    def_irq_handler    WKT_DriverIRQHandler
531    def_irq_handler    ADC0_SEQA_DriverIRQHandler
532    def_irq_handler    ADC0_SEQB_DriverIRQHandler
533    def_irq_handler    ADC0_THCMP_DriverIRQHandler
534    def_irq_handler    ADC0_OVR_DriverIRQHandler
535    def_irq_handler    DMA0_DriverIRQHandler
536    def_irq_handler    Reserved37_DriverIRQHandler
537    def_irq_handler    Reserved38_DriverIRQHandler
538    def_irq_handler    Reserved39_DriverIRQHandler
539    def_irq_handler    PIN_INT0_DriverIRQHandler
540    def_irq_handler    PIN_INT1_DriverIRQHandler
541    def_irq_handler    PIN_INT2_DriverIRQHandler
542    def_irq_handler    PIN_INT3_DriverIRQHandler
543    def_irq_handler    PIN_INT4_DriverIRQHandler
544    def_irq_handler    PIN_INT5_DriverIRQHandler
545    def_irq_handler    PIN_INT6_DriverIRQHandler
546    def_irq_handler    PIN_INT7_DriverIRQHandler
547
548    .end
549