1/* ------------------------------------------------------------------------- */
2/*  @file:    startup_K32L2A31A.s                                            */
3/*  @purpose: CMSIS Cortex-M0P Core Device Startup File                      */
4/*            K32L2A31A                                                      */
5/*  @version: 1.0                                                            */
6/*  @date:    2019-10-30                                                     */
7/*  @build:   b230525                                                        */
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 __isr_vector
22__isr_vector:
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   DMA0_04_IRQHandler                              /* DMA0 channel 0/4 transfer complete*/
42    .long   DMA0_15_IRQHandler                              /* DMA0 channel 1/5 transfer complete*/
43    .long   DMA0_26_IRQHandler                              /* DMA0 channel 2/6 transfer complete*/
44    .long   DMA0_37_IRQHandler                              /* DMA0 channel 3/7 transfer complete*/
45    .long   CTI0_DMA0_Error_IRQHandler                      /* CTI0 or DMA0 error*/
46    .long   FLEXIO0_IRQHandler                              /* FLEXIO0*/
47    .long   TPM0_IRQHandler                                 /* TPM0 single interrupt vector for all sources*/
48    .long   TPM1_IRQHandler                                 /* TPM1 single interrupt vector for all sources*/
49    .long   TPM2_IRQHandler                                 /* TPM2 single interrupt vector for all sources*/
50    .long   LPIT0_IRQHandler                                /* LPIT0 interrupt*/
51    .long   LPSPI0_IRQHandler                               /* LPSPI0 single interrupt vector for all sources*/
52    .long   LPSPI1_IRQHandler                               /* LPSPI1 single interrupt vector for all sources*/
53    .long   LPUART0_IRQHandler                              /* LPUART0 status and error*/
54    .long   LPUART1_IRQHandler                              /* LPUART1 status and error*/
55    .long   LPI2C0_IRQHandler                               /* LPI2C0 interrupt*/
56    .long   LPI2C1_IRQHandler                               /* LPI2C1 interrupt*/
57    .long   Reserved32_IRQHandler                           /* Reserved interrupt*/
58    .long   PORTA_IRQHandler                                /* PORTA Pin detect*/
59    .long   PORTB_IRQHandler                                /* PORTB Pin detect*/
60    .long   PORTC_IRQHandler                                /* PORTC Pin detect*/
61    .long   PORTD_IRQHandler                                /* PORTD Pin detect*/
62    .long   PORTE_IRQHandler                                /* PORTE Pin detect*/
63    .long   LLWU_IRQHandler                                 /* Low leakage wakeup */
64    .long   Reserved39_IRQHandler                           /* Reserved interrupt*/
65    .long   USB0_IRQHandler                                 /* USB0 interrupt*/
66    .long   ADC0_IRQHandler                                 /* ADC0 interrupt*/
67    .long   LPTMR0_IRQHandler                               /* LPTMR0 interrupt*/
68    .long   RTC_Seconds_IRQHandler                          /* RTC seconds*/
69    .long   INTMUX0_0_IRQHandler                            /* INTMUX0 channel 0 interrupt*/
70    .long   INTMUX0_1_IRQHandler                            /* INTMUX0 channel 1 interrupt*/
71    .long   INTMUX0_2_IRQHandler                            /* INTMUX0 channel 2 interrupt*/
72    .long   INTMUX0_3_IRQHandler                            /* INTMUX0 channel 3 interrupt*/
73    .long   LPTMR1_IRQHandler                               /* LPTMR1 interrupt  (INTMUX source IRQ0)*/
74    .long   Reserved49_IRQHandler                           /* Reserved interrupt*/
75    .long   Reserved50_IRQHandler                           /* Reserved interrupt*/
76    .long   Reserved51_IRQHandler                           /* Reserved interrupt*/
77    .long   LPSPI2_IRQHandler                               /* LPSPI2 single interrupt vector for all sources (INTMUX source IRQ4)*/
78    .long   LPUART2_IRQHandler                              /* LPUART2 status and error (INTMUX source IRQ5)*/
79    .long   EMVSIM0_IRQHandler                              /* EMVSIM0 interrupt (INTMUX source IRQ6)*/
80    .long   LPI2C2_IRQHandler                               /* LPI2C2 interrupt (INTMUX source IRQ7)*/
81    .long   TSI0_IRQHandler                                 /* TSI0 interrupt (INTMUX source IRQ8)*/
82    .long   PMC_IRQHandler                                  /* PMC interrupt (INTMUX source IRQ9)*/
83    .long   FTFA_IRQHandler                                 /* FTFA interrupt (INTMUX source IRQ10)*/
84    .long   SCG_IRQHandler                                  /* SCG interrupt (INTMUX source IRQ11)*/
85    .long   WDOG0_IRQHandler                                /* WDOG0 interrupt (INTMUX source IRQ12)*/
86    .long   DAC0_IRQHandler                                 /* DAC0 interrupt (INTMUX source IRQ13)*/
87    .long   TRNG_IRQHandler                                 /* TRNG interrupt (INTMUX source IRQ14)*/
88    .long   RCM_IRQHandler                                  /* RCM interrupt (INTMUX source IRQ15)*/
89    .long   CMP0_IRQHandler                                 /* CMP0 interrupt (INTMUX source IRQ16)*/
90    .long   CMP1_IRQHandler                                 /* CMP1 interrupt (INTMUX source IRQ17)*/
91    .long   RTC_IRQHandler                                  /* RTC Alarm interrupt (INTMUX source IRQ18)*/
92    .long   Reserved67_IRQHandler                           /* Reserved interrupt*/
93    .long   Reserved68_IRQHandler                           /* Reserved interrupt*/
94    .long   Reserved69_IRQHandler                           /* Reserved interrupt*/
95    .long   Reserved70_IRQHandler                           /* Reserved interrupt*/
96    .long   Reserved71_IRQHandler                           /* Reserved interrupt*/
97    .long   Reserved72_IRQHandler                           /* Reserved interrupt*/
98    .long   Reserved73_IRQHandler                           /* Reserved interrupt*/
99    .long   Reserved74_IRQHandler                           /* Reserved interrupt*/
100    .long   Reserved75_IRQHandler                           /* Reserved interrupt*/
101    .long   Reserved76_IRQHandler                           /* Reserved interrupt*/
102    .long   Reserved77_IRQHandler                           /* Reserved interrupt*/
103    .long   Reserved78_IRQHandler                           /* Reserved interrupt*/
104    .long   Reserved79_IRQHandler                           /* Reserved interrupt*/
105
106    .size   __isr_vector, . - __isr_vector
107
108/* Flash Configuration */
109    .section .FlashConfig, "a"
110    .long 0xFFFFFFFF
111    .long 0xFFFFFFFF
112    .long 0xFFFFFFFF
113    .long 0xFFFF3DFE
114
115    .text
116    .thumb
117
118/* Reset Handler */
119
120    .thumb_func
121    .align 2
122    .globl   Reset_Handler
123    .weak    Reset_Handler
124    .type    Reset_Handler, %function
125Reset_Handler:
126    cpsid   i               /* Mask interrupts */
127    .equ    VTOR, 0xE000ED08
128    ldr     r0, =VTOR
129    ldr     r1, =__isr_vector
130    str     r1, [r0]
131    ldr     r2, [r1]
132    msr     msp, r2
133#ifndef __NO_SYSTEM_INIT
134    ldr   r0,=SystemInit
135    blx   r0
136#endif
137/*     Loop to copy data from read only memory to RAM. The ranges
138 *      of copy from/to are specified by following symbols evaluated in
139 *      linker script.
140 *      __etext: End of code section, i.e., begin of data sections to copy from.
141 *      __data_start__/__data_end__: RAM address range that data should be
142 *      copied to. Both must be aligned to 4 bytes boundary.  */
143
144    ldr    r1, =__etext
145    ldr    r2, =__data_start__
146    ldr    r3, =__data_end__
147
148    subs    r3, r2
149    ble     .LC0
150
151.LC1:
152    subs    r3, 4
153    ldr    r0, [r1,r3]
154    str    r0, [r2,r3]
155    bgt    .LC1
156.LC0:
157
158#ifdef __STARTUP_CLEAR_BSS
159/*     This part of work usually is done in C library startup code. Otherwise,
160 *     define this macro to enable it in this startup.
161 *
162 *     Loop to zero out BSS section, which uses following symbols
163 *     in linker script:
164 *      __bss_start__: start of BSS section. Must align to 4
165 *      __bss_end__: end of BSS section. Must align to 4
166 */
167    ldr r1, =__bss_start__
168    ldr r2, =__bss_end__
169
170    subs    r2, r1
171    ble .LC3
172
173    movs    r0, 0
174.LC2:
175    subs    r2, 4
176    str r0, [r1, r2]
177    bgt .LC2
178.LC3:
179#endif
180    cpsie   i               /* Unmask interrupts */
181#ifndef __START
182#define __START _start
183#endif
184#ifndef __ATOLLIC__
185    ldr   r0,=__START
186    blx   r0
187#else
188    ldr   r0,=__libc_init_array
189    blx   r0
190    ldr   r0,=main
191    bx    r0
192#endif
193    .pool
194    .size Reset_Handler, . - Reset_Handler
195
196    .align  1
197    .thumb_func
198    .weak DefaultISR
199    .type DefaultISR, %function
200DefaultISR:
201    ldr r0, =DefaultISR
202    bx r0
203    .size DefaultISR, . - DefaultISR
204
205    .align 1
206    .thumb_func
207    .weak NMI_Handler
208    .type NMI_Handler, %function
209NMI_Handler:
210    ldr   r0,=NMI_Handler
211    bx    r0
212    .size NMI_Handler, . - NMI_Handler
213
214    .align 1
215    .thumb_func
216    .weak HardFault_Handler
217    .type HardFault_Handler, %function
218HardFault_Handler:
219    ldr   r0,=HardFault_Handler
220    bx    r0
221    .size HardFault_Handler, . - HardFault_Handler
222
223    .align 1
224    .thumb_func
225    .weak SVC_Handler
226    .type SVC_Handler, %function
227SVC_Handler:
228    ldr   r0,=SVC_Handler
229    bx    r0
230    .size SVC_Handler, . - SVC_Handler
231
232    .align 1
233    .thumb_func
234    .weak PendSV_Handler
235    .type PendSV_Handler, %function
236PendSV_Handler:
237    ldr   r0,=PendSV_Handler
238    bx    r0
239    .size PendSV_Handler, . - PendSV_Handler
240
241    .align 1
242    .thumb_func
243    .weak SysTick_Handler
244    .type SysTick_Handler, %function
245SysTick_Handler:
246    ldr   r0,=SysTick_Handler
247    bx    r0
248    .size SysTick_Handler, . - SysTick_Handler
249
250    .align 1
251    .thumb_func
252    .weak DMA0_04_IRQHandler
253    .type DMA0_04_IRQHandler, %function
254DMA0_04_IRQHandler:
255    ldr   r0,=DMA0_04_DriverIRQHandler
256    bx    r0
257    .size DMA0_04_IRQHandler, . - DMA0_04_IRQHandler
258
259    .align 1
260    .thumb_func
261    .weak DMA0_15_IRQHandler
262    .type DMA0_15_IRQHandler, %function
263DMA0_15_IRQHandler:
264    ldr   r0,=DMA0_15_DriverIRQHandler
265    bx    r0
266    .size DMA0_15_IRQHandler, . - DMA0_15_IRQHandler
267
268    .align 1
269    .thumb_func
270    .weak DMA0_26_IRQHandler
271    .type DMA0_26_IRQHandler, %function
272DMA0_26_IRQHandler:
273    ldr   r0,=DMA0_26_DriverIRQHandler
274    bx    r0
275    .size DMA0_26_IRQHandler, . - DMA0_26_IRQHandler
276
277    .align 1
278    .thumb_func
279    .weak DMA0_37_IRQHandler
280    .type DMA0_37_IRQHandler, %function
281DMA0_37_IRQHandler:
282    ldr   r0,=DMA0_37_DriverIRQHandler
283    bx    r0
284    .size DMA0_37_IRQHandler, . - DMA0_37_IRQHandler
285
286    .align 1
287    .thumb_func
288    .weak CTI0_DMA0_Error_IRQHandler
289    .type CTI0_DMA0_Error_IRQHandler, %function
290CTI0_DMA0_Error_IRQHandler:
291    ldr   r0,=CTI0_DMA0_Error_DriverIRQHandler
292    bx    r0
293    .size CTI0_DMA0_Error_IRQHandler, . - CTI0_DMA0_Error_IRQHandler
294
295    .align 1
296    .thumb_func
297    .weak FLEXIO0_IRQHandler
298    .type FLEXIO0_IRQHandler, %function
299FLEXIO0_IRQHandler:
300    ldr   r0,=FLEXIO0_DriverIRQHandler
301    bx    r0
302    .size FLEXIO0_IRQHandler, . - FLEXIO0_IRQHandler
303
304    .align 1
305    .thumb_func
306    .weak LPSPI0_IRQHandler
307    .type LPSPI0_IRQHandler, %function
308LPSPI0_IRQHandler:
309    ldr   r0,=LPSPI0_DriverIRQHandler
310    bx    r0
311    .size LPSPI0_IRQHandler, . - LPSPI0_IRQHandler
312
313    .align 1
314    .thumb_func
315    .weak LPSPI1_IRQHandler
316    .type LPSPI1_IRQHandler, %function
317LPSPI1_IRQHandler:
318    ldr   r0,=LPSPI1_DriverIRQHandler
319    bx    r0
320    .size LPSPI1_IRQHandler, . - LPSPI1_IRQHandler
321
322    .align 1
323    .thumb_func
324    .weak LPUART0_IRQHandler
325    .type LPUART0_IRQHandler, %function
326LPUART0_IRQHandler:
327    ldr   r0,=LPUART0_DriverIRQHandler
328    bx    r0
329    .size LPUART0_IRQHandler, . - LPUART0_IRQHandler
330
331    .align 1
332    .thumb_func
333    .weak LPUART1_IRQHandler
334    .type LPUART1_IRQHandler, %function
335LPUART1_IRQHandler:
336    ldr   r0,=LPUART1_DriverIRQHandler
337    bx    r0
338    .size LPUART1_IRQHandler, . - LPUART1_IRQHandler
339
340    .align 1
341    .thumb_func
342    .weak LPI2C0_IRQHandler
343    .type LPI2C0_IRQHandler, %function
344LPI2C0_IRQHandler:
345    ldr   r0,=LPI2C0_DriverIRQHandler
346    bx    r0
347    .size LPI2C0_IRQHandler, . - LPI2C0_IRQHandler
348
349    .align 1
350    .thumb_func
351    .weak LPI2C1_IRQHandler
352    .type LPI2C1_IRQHandler, %function
353LPI2C1_IRQHandler:
354    ldr   r0,=LPI2C1_DriverIRQHandler
355    bx    r0
356    .size LPI2C1_IRQHandler, . - LPI2C1_IRQHandler
357
358    .align 1
359    .thumb_func
360    .weak INTMUX0_0_IRQHandler
361    .type INTMUX0_0_IRQHandler, %function
362INTMUX0_0_IRQHandler:
363    ldr   r0,=INTMUX0_0_DriverIRQHandler
364    bx    r0
365    .size INTMUX0_0_IRQHandler, . - INTMUX0_0_IRQHandler
366
367    .align 1
368    .thumb_func
369    .weak INTMUX0_1_IRQHandler
370    .type INTMUX0_1_IRQHandler, %function
371INTMUX0_1_IRQHandler:
372    ldr   r0,=INTMUX0_1_DriverIRQHandler
373    bx    r0
374    .size INTMUX0_1_IRQHandler, . - INTMUX0_1_IRQHandler
375
376    .align 1
377    .thumb_func
378    .weak INTMUX0_2_IRQHandler
379    .type INTMUX0_2_IRQHandler, %function
380INTMUX0_2_IRQHandler:
381    ldr   r0,=INTMUX0_2_DriverIRQHandler
382    bx    r0
383    .size INTMUX0_2_IRQHandler, . - INTMUX0_2_IRQHandler
384
385    .align 1
386    .thumb_func
387    .weak INTMUX0_3_IRQHandler
388    .type INTMUX0_3_IRQHandler, %function
389INTMUX0_3_IRQHandler:
390    ldr   r0,=INTMUX0_3_DriverIRQHandler
391    bx    r0
392    .size INTMUX0_3_IRQHandler, . - INTMUX0_3_IRQHandler
393
394    .align 1
395    .thumb_func
396    .weak LPSPI2_IRQHandler
397    .type LPSPI2_IRQHandler, %function
398LPSPI2_IRQHandler:
399    ldr   r0,=LPSPI2_DriverIRQHandler
400    bx    r0
401    .size LPSPI2_IRQHandler, . - LPSPI2_IRQHandler
402
403    .align 1
404    .thumb_func
405    .weak LPUART2_IRQHandler
406    .type LPUART2_IRQHandler, %function
407LPUART2_IRQHandler:
408    ldr   r0,=LPUART2_DriverIRQHandler
409    bx    r0
410    .size LPUART2_IRQHandler, . - LPUART2_IRQHandler
411
412    .align 1
413    .thumb_func
414    .weak LPI2C2_IRQHandler
415    .type LPI2C2_IRQHandler, %function
416LPI2C2_IRQHandler:
417    ldr   r0,=LPI2C2_DriverIRQHandler
418    bx    r0
419    .size LPI2C2_IRQHandler, . - LPI2C2_IRQHandler
420
421
422/*    Macro to define default handlers. Default handler
423 *    will be weak symbol and just dead loops. They can be
424 *    overwritten by other handlers */
425    .macro def_irq_handler  handler_name
426    .weak \handler_name
427    .set  \handler_name, DefaultISR
428    .endm
429/* Exception Handlers */
430    def_irq_handler    DMA0_04_DriverIRQHandler
431    def_irq_handler    DMA0_15_DriverIRQHandler
432    def_irq_handler    DMA0_26_DriverIRQHandler
433    def_irq_handler    DMA0_37_DriverIRQHandler
434    def_irq_handler    CTI0_DMA0_Error_DriverIRQHandler
435    def_irq_handler    FLEXIO0_DriverIRQHandler
436    def_irq_handler    TPM0_IRQHandler
437    def_irq_handler    TPM1_IRQHandler
438    def_irq_handler    TPM2_IRQHandler
439    def_irq_handler    LPIT0_IRQHandler
440    def_irq_handler    LPSPI0_DriverIRQHandler
441    def_irq_handler    LPSPI1_DriverIRQHandler
442    def_irq_handler    LPUART0_DriverIRQHandler
443    def_irq_handler    LPUART1_DriverIRQHandler
444    def_irq_handler    LPI2C0_DriverIRQHandler
445    def_irq_handler    LPI2C1_DriverIRQHandler
446    def_irq_handler    Reserved32_IRQHandler
447    def_irq_handler    PORTA_IRQHandler
448    def_irq_handler    PORTB_IRQHandler
449    def_irq_handler    PORTC_IRQHandler
450    def_irq_handler    PORTD_IRQHandler
451    def_irq_handler    PORTE_IRQHandler
452    def_irq_handler    LLWU_IRQHandler
453    def_irq_handler    Reserved39_IRQHandler
454    def_irq_handler    USB0_IRQHandler
455    def_irq_handler    ADC0_IRQHandler
456    def_irq_handler    LPTMR0_IRQHandler
457    def_irq_handler    RTC_Seconds_IRQHandler
458    def_irq_handler    INTMUX0_0_DriverIRQHandler
459    def_irq_handler    INTMUX0_1_DriverIRQHandler
460    def_irq_handler    INTMUX0_2_DriverIRQHandler
461    def_irq_handler    INTMUX0_3_DriverIRQHandler
462    def_irq_handler    LPTMR1_IRQHandler
463    def_irq_handler    Reserved49_IRQHandler
464    def_irq_handler    Reserved50_IRQHandler
465    def_irq_handler    Reserved51_IRQHandler
466    def_irq_handler    LPSPI2_DriverIRQHandler
467    def_irq_handler    LPUART2_DriverIRQHandler
468    def_irq_handler    EMVSIM0_IRQHandler
469    def_irq_handler    LPI2C2_DriverIRQHandler
470    def_irq_handler    TSI0_IRQHandler
471    def_irq_handler    PMC_IRQHandler
472    def_irq_handler    FTFA_IRQHandler
473    def_irq_handler    SCG_IRQHandler
474    def_irq_handler    WDOG0_IRQHandler
475    def_irq_handler    DAC0_IRQHandler
476    def_irq_handler    TRNG_IRQHandler
477    def_irq_handler    RCM_IRQHandler
478    def_irq_handler    CMP0_IRQHandler
479    def_irq_handler    CMP1_IRQHandler
480    def_irq_handler    RTC_IRQHandler
481    def_irq_handler    Reserved67_IRQHandler
482    def_irq_handler    Reserved68_IRQHandler
483    def_irq_handler    Reserved69_IRQHandler
484    def_irq_handler    Reserved70_IRQHandler
485    def_irq_handler    Reserved71_IRQHandler
486    def_irq_handler    Reserved72_IRQHandler
487    def_irq_handler    Reserved73_IRQHandler
488    def_irq_handler    Reserved74_IRQHandler
489    def_irq_handler    Reserved75_IRQHandler
490    def_irq_handler    Reserved76_IRQHandler
491    def_irq_handler    Reserved77_IRQHandler
492    def_irq_handler    Reserved78_IRQHandler
493    def_irq_handler    Reserved79_IRQHandler
494
495    .end
496