1/* ------------------------------------------------------------------------- */
2/*  @file:    startup_K32L2A41A.s                                            */
3/*  @purpose: CMSIS Cortex-M0P Core Device Startup File                      */
4/*            K32L2A41A                                                      */
5/*  @version: 1.0                                                            */
6/*  @date:    2019-10-30                                                     */
7/*  @build:   b231018                                                        */
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#if defined (__cplusplus)
119#ifdef __REDLIB__
120#error Redlib does not support C++
121#endif
122#endif
123/* Reset Handler */
124
125    .thumb_func
126    .align 2
127    .globl   Reset_Handler
128    .weak    Reset_Handler
129    .type    Reset_Handler, %function
130Reset_Handler:
131    cpsid   i               /* Mask interrupts */
132    .equ    VTOR, 0xE000ED08
133    ldr     r0, =VTOR
134    ldr     r1, =__isr_vector
135    str     r1, [r0]
136    ldr     r2, [r1]
137    msr     msp, r2
138#ifndef __NO_SYSTEM_INIT
139    ldr   r0,=SystemInit
140    blx   r0
141#endif
142/*     Loop to copy data from read only memory to RAM. The ranges
143 *      of copy from/to are specified by following symbols evaluated in
144 *      linker script.
145 *      __etext: End of code section, i.e., begin of data sections to copy from.
146 *      __data_start__/__data_end__: RAM address range that data should be
147 *      copied to. Both must be aligned to 4 bytes boundary.  */
148
149    ldr    r1, =__etext
150    ldr    r2, =__data_start__
151    ldr    r3, =__data_end__
152
153    subs    r3, r2
154    ble     .LC0
155
156.LC1:
157    subs    r3, 4
158    ldr    r0, [r1,r3]
159    str    r0, [r2,r3]
160    bgt    .LC1
161.LC0:
162
163#ifdef __STARTUP_CLEAR_BSS
164/*     This part of work usually is done in C library startup code. Otherwise,
165 *     define this macro to enable it in this startup.
166 *
167 *     Loop to zero out BSS section, which uses following symbols
168 *     in linker script:
169 *      __bss_start__: start of BSS section. Must align to 4
170 *      __bss_end__: end of BSS section. Must align to 4
171 */
172    ldr r1, =__bss_start__
173    ldr r2, =__bss_end__
174
175    subs    r2, r1
176    ble .LC3
177
178    movs    r0, 0
179.LC2:
180    subs    r2, 4
181    str r0, [r1, r2]
182    bgt .LC2
183.LC3:
184#endif
185    cpsie   i               /* Unmask interrupts */
186#ifndef __START
187#ifdef __REDLIB__
188#define __START __main
189#else
190#define __START _start
191#endif
192#endif
193#ifndef __ATOLLIC__
194    ldr   r0,=__START
195    blx   r0
196#else
197    ldr   r0,=__libc_init_array
198    blx   r0
199    ldr   r0,=main
200    bx    r0
201#endif
202    .pool
203    .size Reset_Handler, . - Reset_Handler
204
205    .align  1
206    .thumb_func
207    .weak DefaultISR
208    .type DefaultISR, %function
209DefaultISR:
210    ldr r0, =DefaultISR
211    bx r0
212    .size DefaultISR, . - DefaultISR
213
214    .align 1
215    .thumb_func
216    .weak NMI_Handler
217    .type NMI_Handler, %function
218NMI_Handler:
219    ldr   r0,=NMI_Handler
220    bx    r0
221    .size NMI_Handler, . - NMI_Handler
222
223    .align 1
224    .thumb_func
225    .weak HardFault_Handler
226    .type HardFault_Handler, %function
227HardFault_Handler:
228    ldr   r0,=HardFault_Handler
229    bx    r0
230    .size HardFault_Handler, . - HardFault_Handler
231
232    .align 1
233    .thumb_func
234    .weak SVC_Handler
235    .type SVC_Handler, %function
236SVC_Handler:
237    ldr   r0,=SVC_Handler
238    bx    r0
239    .size SVC_Handler, . - SVC_Handler
240
241    .align 1
242    .thumb_func
243    .weak PendSV_Handler
244    .type PendSV_Handler, %function
245PendSV_Handler:
246    ldr   r0,=PendSV_Handler
247    bx    r0
248    .size PendSV_Handler, . - PendSV_Handler
249
250    .align 1
251    .thumb_func
252    .weak SysTick_Handler
253    .type SysTick_Handler, %function
254SysTick_Handler:
255    ldr   r0,=SysTick_Handler
256    bx    r0
257    .size SysTick_Handler, . - SysTick_Handler
258
259    .align 1
260    .thumb_func
261    .weak DMA0_04_IRQHandler
262    .type DMA0_04_IRQHandler, %function
263DMA0_04_IRQHandler:
264    ldr   r0,=DMA0_04_DriverIRQHandler
265    bx    r0
266    .size DMA0_04_IRQHandler, . - DMA0_04_IRQHandler
267
268    .align 1
269    .thumb_func
270    .weak DMA0_15_IRQHandler
271    .type DMA0_15_IRQHandler, %function
272DMA0_15_IRQHandler:
273    ldr   r0,=DMA0_15_DriverIRQHandler
274    bx    r0
275    .size DMA0_15_IRQHandler, . - DMA0_15_IRQHandler
276
277    .align 1
278    .thumb_func
279    .weak DMA0_26_IRQHandler
280    .type DMA0_26_IRQHandler, %function
281DMA0_26_IRQHandler:
282    ldr   r0,=DMA0_26_DriverIRQHandler
283    bx    r0
284    .size DMA0_26_IRQHandler, . - DMA0_26_IRQHandler
285
286    .align 1
287    .thumb_func
288    .weak DMA0_37_IRQHandler
289    .type DMA0_37_IRQHandler, %function
290DMA0_37_IRQHandler:
291    ldr   r0,=DMA0_37_DriverIRQHandler
292    bx    r0
293    .size DMA0_37_IRQHandler, . - DMA0_37_IRQHandler
294
295    .align 1
296    .thumb_func
297    .weak CTI0_DMA0_Error_IRQHandler
298    .type CTI0_DMA0_Error_IRQHandler, %function
299CTI0_DMA0_Error_IRQHandler:
300    ldr   r0,=CTI0_DMA0_Error_DriverIRQHandler
301    bx    r0
302    .size CTI0_DMA0_Error_IRQHandler, . - CTI0_DMA0_Error_IRQHandler
303
304    .align 1
305    .thumb_func
306    .weak FLEXIO0_IRQHandler
307    .type FLEXIO0_IRQHandler, %function
308FLEXIO0_IRQHandler:
309    ldr   r0,=FLEXIO0_DriverIRQHandler
310    bx    r0
311    .size FLEXIO0_IRQHandler, . - FLEXIO0_IRQHandler
312
313    .align 1
314    .thumb_func
315    .weak LPSPI0_IRQHandler
316    .type LPSPI0_IRQHandler, %function
317LPSPI0_IRQHandler:
318    ldr   r0,=LPSPI0_DriverIRQHandler
319    bx    r0
320    .size LPSPI0_IRQHandler, . - LPSPI0_IRQHandler
321
322    .align 1
323    .thumb_func
324    .weak LPSPI1_IRQHandler
325    .type LPSPI1_IRQHandler, %function
326LPSPI1_IRQHandler:
327    ldr   r0,=LPSPI1_DriverIRQHandler
328    bx    r0
329    .size LPSPI1_IRQHandler, . - LPSPI1_IRQHandler
330
331    .align 1
332    .thumb_func
333    .weak LPUART0_IRQHandler
334    .type LPUART0_IRQHandler, %function
335LPUART0_IRQHandler:
336    ldr   r0,=LPUART0_DriverIRQHandler
337    bx    r0
338    .size LPUART0_IRQHandler, . - LPUART0_IRQHandler
339
340    .align 1
341    .thumb_func
342    .weak LPUART1_IRQHandler
343    .type LPUART1_IRQHandler, %function
344LPUART1_IRQHandler:
345    ldr   r0,=LPUART1_DriverIRQHandler
346    bx    r0
347    .size LPUART1_IRQHandler, . - LPUART1_IRQHandler
348
349    .align 1
350    .thumb_func
351    .weak LPI2C0_IRQHandler
352    .type LPI2C0_IRQHandler, %function
353LPI2C0_IRQHandler:
354    ldr   r0,=LPI2C0_DriverIRQHandler
355    bx    r0
356    .size LPI2C0_IRQHandler, . - LPI2C0_IRQHandler
357
358    .align 1
359    .thumb_func
360    .weak LPI2C1_IRQHandler
361    .type LPI2C1_IRQHandler, %function
362LPI2C1_IRQHandler:
363    ldr   r0,=LPI2C1_DriverIRQHandler
364    bx    r0
365    .size LPI2C1_IRQHandler, . - LPI2C1_IRQHandler
366
367    .align 1
368    .thumb_func
369    .weak INTMUX0_0_IRQHandler
370    .type INTMUX0_0_IRQHandler, %function
371INTMUX0_0_IRQHandler:
372    ldr   r0,=INTMUX0_0_DriverIRQHandler
373    bx    r0
374    .size INTMUX0_0_IRQHandler, . - INTMUX0_0_IRQHandler
375
376    .align 1
377    .thumb_func
378    .weak INTMUX0_1_IRQHandler
379    .type INTMUX0_1_IRQHandler, %function
380INTMUX0_1_IRQHandler:
381    ldr   r0,=INTMUX0_1_DriverIRQHandler
382    bx    r0
383    .size INTMUX0_1_IRQHandler, . - INTMUX0_1_IRQHandler
384
385    .align 1
386    .thumb_func
387    .weak INTMUX0_2_IRQHandler
388    .type INTMUX0_2_IRQHandler, %function
389INTMUX0_2_IRQHandler:
390    ldr   r0,=INTMUX0_2_DriverIRQHandler
391    bx    r0
392    .size INTMUX0_2_IRQHandler, . - INTMUX0_2_IRQHandler
393
394    .align 1
395    .thumb_func
396    .weak INTMUX0_3_IRQHandler
397    .type INTMUX0_3_IRQHandler, %function
398INTMUX0_3_IRQHandler:
399    ldr   r0,=INTMUX0_3_DriverIRQHandler
400    bx    r0
401    .size INTMUX0_3_IRQHandler, . - INTMUX0_3_IRQHandler
402
403    .align 1
404    .thumb_func
405    .weak LPSPI2_IRQHandler
406    .type LPSPI2_IRQHandler, %function
407LPSPI2_IRQHandler:
408    ldr   r0,=LPSPI2_DriverIRQHandler
409    bx    r0
410    .size LPSPI2_IRQHandler, . - LPSPI2_IRQHandler
411
412    .align 1
413    .thumb_func
414    .weak LPUART2_IRQHandler
415    .type LPUART2_IRQHandler, %function
416LPUART2_IRQHandler:
417    ldr   r0,=LPUART2_DriverIRQHandler
418    bx    r0
419    .size LPUART2_IRQHandler, . - LPUART2_IRQHandler
420
421    .align 1
422    .thumb_func
423    .weak LPI2C2_IRQHandler
424    .type LPI2C2_IRQHandler, %function
425LPI2C2_IRQHandler:
426    ldr   r0,=LPI2C2_DriverIRQHandler
427    bx    r0
428    .size LPI2C2_IRQHandler, . - LPI2C2_IRQHandler
429
430
431/*    Macro to define default handlers. Default handler
432 *    will be weak symbol and just dead loops. They can be
433 *    overwritten by other handlers */
434    .macro def_irq_handler  handler_name
435    .weak \handler_name
436    .set  \handler_name, DefaultISR
437    .endm
438/* Exception Handlers */
439    def_irq_handler    DMA0_04_DriverIRQHandler
440    def_irq_handler    DMA0_15_DriverIRQHandler
441    def_irq_handler    DMA0_26_DriverIRQHandler
442    def_irq_handler    DMA0_37_DriverIRQHandler
443    def_irq_handler    CTI0_DMA0_Error_DriverIRQHandler
444    def_irq_handler    FLEXIO0_DriverIRQHandler
445    def_irq_handler    TPM0_IRQHandler
446    def_irq_handler    TPM1_IRQHandler
447    def_irq_handler    TPM2_IRQHandler
448    def_irq_handler    LPIT0_IRQHandler
449    def_irq_handler    LPSPI0_DriverIRQHandler
450    def_irq_handler    LPSPI1_DriverIRQHandler
451    def_irq_handler    LPUART0_DriverIRQHandler
452    def_irq_handler    LPUART1_DriverIRQHandler
453    def_irq_handler    LPI2C0_DriverIRQHandler
454    def_irq_handler    LPI2C1_DriverIRQHandler
455    def_irq_handler    Reserved32_IRQHandler
456    def_irq_handler    PORTA_IRQHandler
457    def_irq_handler    PORTB_IRQHandler
458    def_irq_handler    PORTC_IRQHandler
459    def_irq_handler    PORTD_IRQHandler
460    def_irq_handler    PORTE_IRQHandler
461    def_irq_handler    LLWU_IRQHandler
462    def_irq_handler    Reserved39_IRQHandler
463    def_irq_handler    USB0_IRQHandler
464    def_irq_handler    ADC0_IRQHandler
465    def_irq_handler    LPTMR0_IRQHandler
466    def_irq_handler    RTC_Seconds_IRQHandler
467    def_irq_handler    INTMUX0_0_DriverIRQHandler
468    def_irq_handler    INTMUX0_1_DriverIRQHandler
469    def_irq_handler    INTMUX0_2_DriverIRQHandler
470    def_irq_handler    INTMUX0_3_DriverIRQHandler
471    def_irq_handler    LPTMR1_IRQHandler
472    def_irq_handler    Reserved49_IRQHandler
473    def_irq_handler    Reserved50_IRQHandler
474    def_irq_handler    Reserved51_IRQHandler
475    def_irq_handler    LPSPI2_DriverIRQHandler
476    def_irq_handler    LPUART2_DriverIRQHandler
477    def_irq_handler    EMVSIM0_IRQHandler
478    def_irq_handler    LPI2C2_DriverIRQHandler
479    def_irq_handler    TSI0_IRQHandler
480    def_irq_handler    PMC_IRQHandler
481    def_irq_handler    FTFA_IRQHandler
482    def_irq_handler    SCG_IRQHandler
483    def_irq_handler    WDOG0_IRQHandler
484    def_irq_handler    DAC0_IRQHandler
485    def_irq_handler    TRNG_IRQHandler
486    def_irq_handler    RCM_IRQHandler
487    def_irq_handler    CMP0_IRQHandler
488    def_irq_handler    CMP1_IRQHandler
489    def_irq_handler    RTC_IRQHandler
490    def_irq_handler    Reserved67_IRQHandler
491    def_irq_handler    Reserved68_IRQHandler
492    def_irq_handler    Reserved69_IRQHandler
493    def_irq_handler    Reserved70_IRQHandler
494    def_irq_handler    Reserved71_IRQHandler
495    def_irq_handler    Reserved72_IRQHandler
496    def_irq_handler    Reserved73_IRQHandler
497    def_irq_handler    Reserved74_IRQHandler
498    def_irq_handler    Reserved75_IRQHandler
499    def_irq_handler    Reserved76_IRQHandler
500    def_irq_handler    Reserved77_IRQHandler
501    def_irq_handler    Reserved78_IRQHandler
502    def_irq_handler    Reserved79_IRQHandler
503
504    .end
505