1 /*
2  * Copyright (c) 2022 Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Licensed under the Apache License, Version 2.0 (the License); you may
7  * not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 /*
20  * This file is derivative of CMSIS V5.9.0 startup_ARMCM33.c
21  * Git SHA: 2b7495b8535bdcb306dac29b9ded4cfb679d7e5c
22  */
23 
24 #include "cmsis.h"
25 
26 /*----------------------------------------------------------------------------
27   External References
28  *----------------------------------------------------------------------------*/
29 extern uint32_t __INITIAL_SP;
30 extern uint32_t __STACK_LIMIT;
31 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
32 extern uint64_t __STACK_SEAL;
33 #endif
34 
35 extern void __PROGRAM_START(void) __NO_RETURN;
36 
37 /*----------------------------------------------------------------------------
38   Internal References
39  *----------------------------------------------------------------------------*/
40 void Reset_Handler  (void) __NO_RETURN;
41 
42 /*----------------------------------------------------------------------------
43   Exception / Interrupt Handler
44  *----------------------------------------------------------------------------*/
45 #define DEFAULT_IRQ_HANDLER(handler_name)  \
46 void __WEAK handler_name(void) __NO_RETURN; \
47 void handler_name(void) { \
48     while(1); \
49 }
50 
51 /* Exceptions */
52 DEFAULT_IRQ_HANDLER(NMI_Handler)
53 DEFAULT_IRQ_HANDLER(HardFault_Handler)
54 DEFAULT_IRQ_HANDLER(MemManage_Handler)
55 DEFAULT_IRQ_HANDLER(BusFault_Handler)
56 DEFAULT_IRQ_HANDLER(UsageFault_Handler)
57 DEFAULT_IRQ_HANDLER(SecureFault_Handler)
58 DEFAULT_IRQ_HANDLER(SVC_Handler)
59 DEFAULT_IRQ_HANDLER(DebugMon_Handler)
60 DEFAULT_IRQ_HANDLER(PendSV_Handler)
61 DEFAULT_IRQ_HANDLER(SysTick_Handler)
62 
63 DEFAULT_IRQ_HANDLER(NONSEC_WATCHDOG_RESET_Handler)
64 DEFAULT_IRQ_HANDLER(NONSEC_WATCHDOG_Handler)
65 DEFAULT_IRQ_HANDLER(S32K_TIMER_Handler)
66 DEFAULT_IRQ_HANDLER(TFM_TIMER0_IRQ_Handler)
67 DEFAULT_IRQ_HANDLER(TIMER1_Handler)
68 DEFAULT_IRQ_HANDLER(DUALTIMER_Handler)
69 DEFAULT_IRQ_HANDLER(MHU0_Handler)
70 DEFAULT_IRQ_HANDLER(MHU1_Handler)
71 DEFAULT_IRQ_HANDLER(CRYPTOCELL_Handler)
72 DEFAULT_IRQ_HANDLER(MPC_Handler)
73 DEFAULT_IRQ_HANDLER(PPC_Handler)
74 DEFAULT_IRQ_HANDLER(MSC_Handler)
75 DEFAULT_IRQ_HANDLER(BRIDGE_ERROR_Handler)
76 DEFAULT_IRQ_HANDLER(INVALID_INSTR_CACHE_Handler)
77 DEFAULT_IRQ_HANDLER(SYS_PPU_Handler)
78 DEFAULT_IRQ_HANDLER(CPU0_PPU_Handler)
79 DEFAULT_IRQ_HANDLER(CPU1_PPU_Handler)
80 DEFAULT_IRQ_HANDLER(CPU0_DBG_PPU_Handler)
81 DEFAULT_IRQ_HANDLER(CPU1_DBG_PPU_Handler)
82 DEFAULT_IRQ_HANDLER(CRYPT_PPU_Handler)
83 DEFAULT_IRQ_HANDLER(RAM0_PPU_Handler)
84 DEFAULT_IRQ_HANDLER(RAM1_PPU_Handler)
85 DEFAULT_IRQ_HANDLER(RAM2_PPU_Handler)
86 DEFAULT_IRQ_HANDLER(RAM3_PPU_Handler)
87 DEFAULT_IRQ_HANDLER(DBG_PPU_Handler)
88 DEFAULT_IRQ_HANDLER(CPU0_CTI_Handler)
89 DEFAULT_IRQ_HANDLER(CPU1_CTI_Handler)
90 
91 DEFAULT_IRQ_HANDLER(GpTimer_IRQHandler)
92 DEFAULT_IRQ_HANDLER(I2C0_IRQHandler)
93 DEFAULT_IRQ_HANDLER(I2C1_IRQHandler)
94 DEFAULT_IRQ_HANDLER(I2S_IRQHandler)
95 DEFAULT_IRQ_HANDLER(SPI_IRQHandler)
96 DEFAULT_IRQ_HANDLER(QSPI_IRQHandler)
97 DEFAULT_IRQ_HANDLER(UARTRX0_Handler)
98 DEFAULT_IRQ_HANDLER(UARTTX0_Handler)
99 DEFAULT_IRQ_HANDLER(UART0_RxTimeout_IRQHandler)
100 DEFAULT_IRQ_HANDLER(UART0_ModemStatus_IRQHandler)
101 DEFAULT_IRQ_HANDLER(UART0_Error_IRQHandler)
102 DEFAULT_IRQ_HANDLER(UART0_IRQHandler)
103 DEFAULT_IRQ_HANDLER(UARTRX1_Handler)
104 DEFAULT_IRQ_HANDLER(UARTTX1_Handler)
105 DEFAULT_IRQ_HANDLER(UART1_RxTimeout_IRQHandler)
106 DEFAULT_IRQ_HANDLER(UART1_ModemStatus_IRQHandler)
107 DEFAULT_IRQ_HANDLER(UART1_Error_IRQHandler)
108 DEFAULT_IRQ_HANDLER(UART1_IRQHandler)
109 DEFAULT_IRQ_HANDLER(GPIO_0_IRQHandler)
110 DEFAULT_IRQ_HANDLER(GPIO_1_IRQHandler)
111 DEFAULT_IRQ_HANDLER(GPIO_2_IRQHandler)
112 DEFAULT_IRQ_HANDLER(GPIO_3_IRQHandler)
113 DEFAULT_IRQ_HANDLER(GPIO_4_IRQHandler)
114 DEFAULT_IRQ_HANDLER(GPIO_5_IRQHandler)
115 DEFAULT_IRQ_HANDLER(GPIO_6_IRQHandler)
116 DEFAULT_IRQ_HANDLER(GPIO_7_IRQHandler)
117 DEFAULT_IRQ_HANDLER(GPIO_8_IRQHandler)
118 DEFAULT_IRQ_HANDLER(GPIO_9_IRQHandler)
119 DEFAULT_IRQ_HANDLER(GPIO_10_IRQHandler)
120 DEFAULT_IRQ_HANDLER(GPIO_11_IRQHandler)
121 DEFAULT_IRQ_HANDLER(GPIO_12_IRQHandler)
122 DEFAULT_IRQ_HANDLER(GPIO_13_IRQHandler)
123 DEFAULT_IRQ_HANDLER(GPIO_14_IRQHandler)
124 DEFAULT_IRQ_HANDLER(GPIO_15_IRQHandler)
125 DEFAULT_IRQ_HANDLER(Combined_IRQHandler)
126 DEFAULT_IRQ_HANDLER(PVT_IRQHandler)
127 DEFAULT_IRQ_HANDLER(PWM_0_IRQHandler)
128 DEFAULT_IRQ_HANDLER(RTC_IRQHandler)
129 DEFAULT_IRQ_HANDLER(GpTimer0_IRQHandler)
130 DEFAULT_IRQ_HANDLER(GpTimer1_IRQHandler)
131 DEFAULT_IRQ_HANDLER(PWM_1_IRQHandler)
132 DEFAULT_IRQ_HANDLER(PWM_2_IRQHandler)
133 DEFAULT_IRQ_HANDLER(IOMUX_IRQHandler)
134 DEFAULT_IRQ_HANDLER(TFM_FPU_S_TEST_Handler)
135 DEFAULT_IRQ_HANDLER(TFM_FPU_NS_TEST_Handler)
136 
137 /*----------------------------------------------------------------------------
138   Exception / Interrupt Vector table
139  *----------------------------------------------------------------------------*/
140 
141 #if defined ( __GNUC__ )
142 #pragma GCC diagnostic push
143 #pragma GCC diagnostic ignored "-Wpedantic"
144 #endif
145 
146 extern const VECTOR_TABLE_Type __VECTOR_TABLE[];
147        const VECTOR_TABLE_Type __VECTOR_TABLE[] __VECTOR_TABLE_ATTRIBUTE = {
148   (VECTOR_TABLE_Type)(&__INITIAL_SP),            /*      Initial Stack Pointer */
149   Reset_Handler,                     /*      Reset Handler */
150   NMI_Handler,                       /* -14: NMI Handler */
151   HardFault_Handler,                 /* -13: Hard Fault Handler */
152   MemManage_Handler,                 /* -12: MPU Fault Handler */
153   BusFault_Handler,                  /* -11: Bus Fault Handler */
154   UsageFault_Handler,                /* -10: Usage Fault Handler */
155   SecureFault_Handler,               /*  -9: Secure Fault Handler */
156   0,                                 /*  -8: Reserved */
157   0,                                 /*  -7: Reserved */
158   0,                                 /*  -6: Reserved */
159   SVC_Handler,                       /*  -5: SVCall Handler */
160   DebugMon_Handler,                  /*  -4: Debug Monitor Handler */
161   0,                                 /*  -3: Reserved */
162   PendSV_Handler,                    /*  -2: PendSV Handler */
163   SysTick_Handler,                   /*  -1: SysTick Handler */
164 
165   NONSEC_WATCHDOG_RESET_Handler,     /*   0: Non-Secure Watchdog Reset Request Handler */
166   NONSEC_WATCHDOG_Handler,           /*   1: Non-Secure Watchdog Interrupt Handler */
167   S32K_TIMER_Handler,                /*   2: S32K Timer Handler */
168   TFM_TIMER0_IRQ_Handler,            /*   3: TIMER 0 Handler */
169   TIMER1_Handler,                    /*   4: TIMER 1 Handler */
170   DUALTIMER_Handler,                 /*   5: Dual Timer Handler */
171   MHU0_Handler,                      /*   6: Message Handling Unit 0 */
172   MHU1_Handler,                      /*   7: Message Handling Unit 1 */
173   CRYPTOCELL_Handler,                /*   8: CryptoCell-312 Handler */
174   MPC_Handler,                       /*   9: MPC Combined (Secure) Handler */
175   PPC_Handler,                       /*  10: PPC Combined (Secure) Handler */
176   MSC_Handler,                       /*  11: MSC Combined (Secure) Handler */
177   BRIDGE_ERROR_Handler,              /*  12: Bridge Error (Secure) Handler */
178   INVALID_INSTR_CACHE_Handler,       /*  13: CPU Instruction Cache Invalidation Handler */
179   0,                                 /*  14: Reserved */
180   SYS_PPU_Handler,                   /*  15: SYS PPU Handler */
181   CPU0_PPU_Handler,                  /*  16: CPU0 PPU Handler */
182   CPU1_PPU_Handler,                  /*  17: CPU1 PPU Handler */
183   CPU0_DBG_PPU_Handler,              /*  18: CPU0 DBG PPU_Handler */
184   CPU1_DBG_PPU_Handler,              /*  19: CPU1 DBG PPU_Handler */
185   CRYPT_PPU_Handler,                 /*  20: CRYPT PPU Handler */
186   0,                                 /*  21: Reserved */
187   RAM0_PPU_Handler,                  /*  22: RAM0 PPU Handler */
188   RAM1_PPU_Handler,                  /*  23: RAM1 PPU Handler */
189   RAM2_PPU_Handler,                  /*  24: RAM2 PPU Handler */
190   RAM3_PPU_Handler,                  /*  25: RAM3 PPU Handler */
191   DBG_PPU_Handler,                   /*  26: DBG PPU Handler */
192   0,                                 /*  27: Reserved */
193   CPU0_CTI_Handler,                  /*  28: CPU0 CTI Handler */
194   CPU1_CTI_Handler,                  /*  29: CPU1 CTI Handler */
195   0,                                 /*  30: Reserved */
196   0,                                 /*  31: Reserved */
197 
198 /* External interrupts */
199   0,                                 /* 32: Reserved */
200   GpTimer_IRQHandler,                /* 33: General Purpose Timer */
201   I2C0_IRQHandler,                   /* 34: I2C0 */
202   I2C1_IRQHandler,                   /* 35: I2C1 */
203   I2S_IRQHandler,                    /* 36: I2S */
204   SPI_IRQHandler,                    /* 37: SPI */
205   QSPI_IRQHandler,                   /* 38: QSPI */
206   UARTRX0_Handler,                   /* 39: UART0 receive FIFO interrupt */
207   UARTTX0_Handler,                   /* 40: UART0 transmit FIFO interrupt */
208   UART0_RxTimeout_IRQHandler,        /* 41: UART0 receive timeout interrupt */
209   UART0_ModemStatus_IRQHandler,      /* 42: UART0 modem status interrupt */
210   UART0_Error_IRQHandler,            /* 43: UART0 error interrupt */
211   UART0_IRQHandler,                  /* 44: UART0 interrupt */
212   UARTRX1_Handler,                   /* 45: UART0 receive FIFO interrupt */
213   UARTTX1_Handler,                   /* 46: UART0 transmit FIFO interrupt */
214   UART1_RxTimeout_IRQHandler,        /* 47: UART0 receive timeout interrupt */
215   UART1_ModemStatus_IRQHandler,      /* 48: UART0 modem status interrupt */
216   UART1_Error_IRQHandler,            /* 49: UART0 error interrupt */
217   UART1_IRQHandler,                  /* 50: UART0 interrupt */
218   GPIO_0_IRQHandler,                 /* 51: GPIO 0 interrupt */
219   GPIO_1_IRQHandler,                 /* 52: GPIO 1 interrupt */
220   GPIO_2_IRQHandler,                 /* 53: GPIO 2 interrupt */
221   GPIO_3_IRQHandler,                 /* 54: GPIO 3 interrupt */
222   GPIO_4_IRQHandler,                 /* 55: GPIO 4 interrupt */
223   GPIO_5_IRQHandler,                 /* 56: GPIO 5 interrupt */
224   GPIO_6_IRQHandler,                 /* 57: GPIO 6 interrupt */
225   GPIO_7_IRQHandler,                 /* 58: GPIO 7 interrupt */
226   GPIO_8_IRQHandler,                 /* 59: GPIO 8 interrupt */
227   GPIO_9_IRQHandler,                 /* 60: GPIO 9 interrupt */
228   GPIO_10_IRQHandler,                /* 61: GPIO 10 interrupt */
229   GPIO_11_IRQHandler,                /* 62: GPIO 11 interrupt */
230   GPIO_12_IRQHandler,                /* 63: GPIO 12 interrupt */
231   GPIO_13_IRQHandler,                /* 64: GPIO 13 interrupt */
232   GPIO_14_IRQHandler,                /* 65: GPIO 14 interrupt */
233   GPIO_15_IRQHandler,                /* 66: GPIO 15 interrupt */
234   Combined_IRQHandler,               /* 67: Combined interrupt */
235   PVT_IRQHandler,                    /* 68: PVT sensor interrupt */
236   0,                                 /* 69: Reserved */
237   PWM_0_IRQHandler,                  /* 70: PWM0 interrupt */
238   RTC_IRQHandler,                    /* 71: RTC interrupt */
239   GpTimer0_IRQHandler,               /* 72: General Purpose Timer0 */
240   GpTimer1_IRQHandler,               /* 73: General Purpose Timer1 */
241   PWM_1_IRQHandler,                  /* 74: PWM1 interrupt */
242   PWM_2_IRQHandler,                  /* 75: PWM2 interrupt */
243   IOMUX_IRQHandler,                  /* 76: IOMUX interrupt */
244   TFM_FPU_S_TEST_Handler,            /* 77: TFM FPU Secure Test Interrupt */
245   TFM_FPU_NS_TEST_Handler,           /* 78: TFM FPU Non-Secure Test Interrupt */
246 };
247 
248 #if defined ( __GNUC__ )
249 #pragma GCC diagnostic pop
250 #endif
251 
252 /*----------------------------------------------------------------------------
253   Reset Handler called on controller reset
254  *----------------------------------------------------------------------------*/
Reset_Handler(void)255 void Reset_Handler(void)
256 {
257 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
258     __disable_irq();
259 #endif
260     __set_PSP((uint32_t)(&__INITIAL_SP));
261 
262     __set_MSPLIM((uint32_t)(&__STACK_LIMIT));
263     __set_PSPLIM((uint32_t)(&__STACK_LIMIT));
264 
265 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
266     __TZ_set_STACKSEAL_S((uint32_t *)(&__STACK_SEAL));
267 #endif
268 
269     SystemInit();                             /* CMSIS System Initialization */
270     __PROGRAM_START();                        /* Enter PreMain (C library entry point) */
271 }
272