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(MPC_Handler)
72 DEFAULT_IRQ_HANDLER(PPC_Handler)
73 DEFAULT_IRQ_HANDLER(MSC_Handler)
74 DEFAULT_IRQ_HANDLER(BRIDGE_ERROR_Handler)
75 DEFAULT_IRQ_HANDLER(INVALID_INSTR_CACHE_Handler)
76 DEFAULT_IRQ_HANDLER(SYS_PPU_Handler)
77 DEFAULT_IRQ_HANDLER(CPU0_PPU_Handler)
78 DEFAULT_IRQ_HANDLER(CPU1_PPU_Handler)
79 DEFAULT_IRQ_HANDLER(CPU0_DBG_PPU_Handler)
80 DEFAULT_IRQ_HANDLER(CPU1_DBG_PPU_Handler)
81 DEFAULT_IRQ_HANDLER(CRYPT_PPU_Handler)
82 DEFAULT_IRQ_HANDLER(RAM0_PPU_Handler)
83 DEFAULT_IRQ_HANDLER(RAM1_PPU_Handler)
84 DEFAULT_IRQ_HANDLER(RAM2_PPU_Handler)
85 DEFAULT_IRQ_HANDLER(RAM3_PPU_Handler)
86 DEFAULT_IRQ_HANDLER(DBG_PPU_Handler)
87 DEFAULT_IRQ_HANDLER(CPU0_CTI_Handler)
88 DEFAULT_IRQ_HANDLER(CPU1_CTI_Handler)
89
90 DEFAULT_IRQ_HANDLER(UARTRX0_Handler)
91 DEFAULT_IRQ_HANDLER(UARTTX0_Handler)
92 DEFAULT_IRQ_HANDLER(UARTRX1_Handler)
93 DEFAULT_IRQ_HANDLER(UARTTX1_Handler)
94 DEFAULT_IRQ_HANDLER(UARTRX2_Handler)
95 DEFAULT_IRQ_HANDLER(UARTTX2_Handler)
96 DEFAULT_IRQ_HANDLER(UARTRX3_Handler)
97 DEFAULT_IRQ_HANDLER(UARTTX3_Handler)
98 DEFAULT_IRQ_HANDLER(UARTRX4_Handler)
99 DEFAULT_IRQ_HANDLER(UARTTX4_Handler)
100 DEFAULT_IRQ_HANDLER(UART0_Combined_Handler)
101 DEFAULT_IRQ_HANDLER(UART1_Combined_Handler)
102 DEFAULT_IRQ_HANDLER(UART2_Combined_Handler)
103 DEFAULT_IRQ_HANDLER(UART3_Combined_Handler)
104 DEFAULT_IRQ_HANDLER(UART4_Combined_Handler)
105 DEFAULT_IRQ_HANDLER(UARTOVF_Handler)
106 DEFAULT_IRQ_HANDLER(ETHERNET_Handler)
107 DEFAULT_IRQ_HANDLER(I2S_Handler)
108 DEFAULT_IRQ_HANDLER(TOUCH_SCREEN_Handler)
109 DEFAULT_IRQ_HANDLER(SPI_ADC_Handler)
110 DEFAULT_IRQ_HANDLER(SPI_SHIELD0_Handler)
111 DEFAULT_IRQ_HANDLER(SPI_SHIELD1_Handler)
112 DEFAULT_IRQ_HANDLER(GPIO0_Combined_Handler)
113 DEFAULT_IRQ_HANDLER(GPIO1_Combined_Handler)
114 DEFAULT_IRQ_HANDLER(GPIO2_Combined_Handler)
115 DEFAULT_IRQ_HANDLER(GPIO3_Combined_Handler)
116 DEFAULT_IRQ_HANDLER(GPIO0_0_Handler)
117 DEFAULT_IRQ_HANDLER(GPIO0_1_Handler)
118 DEFAULT_IRQ_HANDLER(GPIO0_2_Handler)
119 DEFAULT_IRQ_HANDLER(GPIO0_3_Handler)
120 DEFAULT_IRQ_HANDLER(GPIO0_4_Handler)
121 DEFAULT_IRQ_HANDLER(GPIO0_5_Handler)
122 DEFAULT_IRQ_HANDLER(GPIO0_6_Handler)
123 DEFAULT_IRQ_HANDLER(GPIO0_7_Handler)
124 DEFAULT_IRQ_HANDLER(GPIO0_8_Handler)
125 DEFAULT_IRQ_HANDLER(GPIO0_9_Handler)
126 DEFAULT_IRQ_HANDLER(GPIO0_10_Handler)
127 DEFAULT_IRQ_HANDLER(GPIO0_11_Handler)
128 DEFAULT_IRQ_HANDLER(GPIO0_12_Handler)
129 DEFAULT_IRQ_HANDLER(GPIO0_13_Handler)
130 DEFAULT_IRQ_HANDLER(GPIO0_14_Handler)
131 DEFAULT_IRQ_HANDLER(GPIO0_15_Handler)
132 DEFAULT_IRQ_HANDLER(GPIO1_0_Handler)
133 DEFAULT_IRQ_HANDLER(GPIO1_1_Handler)
134 DEFAULT_IRQ_HANDLER(GPIO1_2_Handler)
135 DEFAULT_IRQ_HANDLER(GPIO1_3_Handler)
136 DEFAULT_IRQ_HANDLER(GPIO1_4_Handler)
137 DEFAULT_IRQ_HANDLER(GPIO1_5_Handler)
138 DEFAULT_IRQ_HANDLER(GPIO1_6_Handler)
139 DEFAULT_IRQ_HANDLER(GPIO1_7_Handler)
140 DEFAULT_IRQ_HANDLER(GPIO1_8_Handler)
141 DEFAULT_IRQ_HANDLER(GPIO1_9_Handler)
142 DEFAULT_IRQ_HANDLER(GPIO1_10_Handler)
143 DEFAULT_IRQ_HANDLER(GPIO1_11_Handler)
144 DEFAULT_IRQ_HANDLER(GPIO1_12_Handler)
145 DEFAULT_IRQ_HANDLER(GPIO1_13_Handler)
146 DEFAULT_IRQ_HANDLER(GPIO1_14_Handler)
147 DEFAULT_IRQ_HANDLER(GPIO1_15_Handler)
148 DEFAULT_IRQ_HANDLER(GPIO2_0_Handler)
149 DEFAULT_IRQ_HANDLER(GPIO2_1_Handler)
150 DEFAULT_IRQ_HANDLER(GPIO2_2_Handler)
151 DEFAULT_IRQ_HANDLER(GPIO2_3_Handler)
152 DEFAULT_IRQ_HANDLER(GPIO2_4_Handler)
153 DEFAULT_IRQ_HANDLER(GPIO2_5_Handler)
154 DEFAULT_IRQ_HANDLER(GPIO2_6_Handler)
155 DEFAULT_IRQ_HANDLER(GPIO2_7_Handler)
156 DEFAULT_IRQ_HANDLER(GPIO2_8_Handler)
157 DEFAULT_IRQ_HANDLER(GPIO2_9_Handler)
158 DEFAULT_IRQ_HANDLER(GPIO2_10_Handler)
159 DEFAULT_IRQ_HANDLER(GPIO2_11_Handler)
160 DEFAULT_IRQ_HANDLER(GPIO2_12_Handler)
161 DEFAULT_IRQ_HANDLER(GPIO2_13_Handler)
162 DEFAULT_IRQ_HANDLER(GPIO2_14_Handler)
163 DEFAULT_IRQ_HANDLER(GPIO2_15_Handler)
164 DEFAULT_IRQ_HANDLER(GPIO3_0_Handler)
165 DEFAULT_IRQ_HANDLER(GPIO3_1_Handler)
166 DEFAULT_IRQ_HANDLER(GPIO3_2_Handler)
167 DEFAULT_IRQ_HANDLER(GPIO3_3_Handler)
168 DEFAULT_IRQ_HANDLER(UARTRX5_Handler)
169 DEFAULT_IRQ_HANDLER(UARTTX5_Handler)
170 DEFAULT_IRQ_HANDLER(UART5_Handler)
171 DEFAULT_IRQ_HANDLER(HDLCD_Handler)
172
173 /*----------------------------------------------------------------------------
174 Exception / Interrupt Vector table
175 *----------------------------------------------------------------------------*/
176
177 #if defined ( __GNUC__ )
178 #pragma GCC diagnostic push
179 #pragma GCC diagnostic ignored "-Wpedantic"
180 #endif
181
182 extern const VECTOR_TABLE_Type __VECTOR_TABLE[];
183 const VECTOR_TABLE_Type __VECTOR_TABLE[] __VECTOR_TABLE_ATTRIBUTE = {
184 (VECTOR_TABLE_Type)(&__INITIAL_SP), /* Initial Stack Pointer */
185 Reset_Handler, /* Reset Handler */
186 NMI_Handler, /* -14: NMI Handler */
187 HardFault_Handler, /* -13: Hard Fault Handler */
188 MemManage_Handler, /* -12: MPU Fault Handler */
189 BusFault_Handler, /* -11: Bus Fault Handler */
190 UsageFault_Handler, /* -10: Usage Fault Handler */
191 SecureFault_Handler, /* -9: Secure Fault Handler */
192 0, /* -8: Reserved */
193 0, /* -7: Reserved */
194 0, /* -6: Reserved */
195 SVC_Handler, /* -5: SVCall Handler */
196 DebugMon_Handler, /* -4: Debug Monitor Handler */
197 0, /* -3: Reserved */
198 PendSV_Handler, /* -2: PendSV Handler */
199 SysTick_Handler, /* -1: SysTick Handler */
200
201 NONSEC_WATCHDOG_RESET_Handler, /* 0: Non-Secure Watchdog Reset Request Handler */
202 NONSEC_WATCHDOG_Handler, /* 1: Non-Secure Watchdog Interrupt Handler */
203 S32K_TIMER_Handler, /* 2: S32K Timer Handler */
204 TFM_TIMER0_IRQ_Handler, /* 3: TIMER 0 Handler */
205 TIMER1_Handler, /* 4: TIMER 1 Handler */
206 DUALTIMER_Handler, /* 5: Dual Timer Handler */
207 MHU0_Handler, /* 6: Message Handling Unit 0 */
208 MHU1_Handler, /* 7: Message Handling Unit 1 */
209 0, /* 8: Reserved */
210 MPC_Handler, /* 9: MPC Combined (Secure) Handler */
211 PPC_Handler, /* 10: PPC Combined (Secure) Handler */
212 MSC_Handler, /* 11: MSC Combined (Secure) Handler */
213 BRIDGE_ERROR_Handler, /* 12: Bridge Error (Secure) Handler */
214 INVALID_INSTR_CACHE_Handler, /* 13: CPU Instruction Cache Invalidation Handler */
215 0, /* 14: Reserved */
216 SYS_PPU_Handler, /* 15: SYS PPU Handler */
217 CPU0_PPU_Handler, /* 16: CPU0 PPU Handler */
218 CPU1_PPU_Handler, /* 17: CPU1 PPU Handler */
219 CPU0_DBG_PPU_Handler, /* 18: CPU0 DBG PPU_Handler */
220 CPU1_DBG_PPU_Handler, /* 19: CPU1 DBG PPU_Handler */
221 CRYPT_PPU_Handler, /* 20: CRYPT PPU Handler */
222 0, /* 21: Reserved */
223 RAM0_PPU_Handler, /* 22: RAM0 PPU Handler */
224 RAM1_PPU_Handler, /* 23: RAM1 PPU Handler */
225 RAM2_PPU_Handler, /* 24: RAM2 PPU Handler */
226 RAM3_PPU_Handler, /* 25: RAM3 PPU Handler */
227 DBG_PPU_Handler, /* 26: DBG PPU Handler */
228 0, /* 27: Reserved */
229 CPU0_CTI_Handler, /* 28: CPU0 CTI Handler */
230 CPU1_CTI_Handler, /* 29: CPU1 CTI Handler */
231 0, /* 30: Reserved */
232 0, /* 31: Reserved */
233
234 /* External interrupts */
235 UARTRX0_Handler, /* 32: UART 0 RX Handler */
236 UARTTX0_Handler, /* 33: UART 0 TX Handler */
237 UARTRX1_Handler, /* 34: UART 1 RX Handler */
238 UARTTX1_Handler, /* 35: UART 1 TX Handler */
239 UARTRX2_Handler, /* 36: UART 2 RX Handler */
240 UARTTX2_Handler, /* 37: UART 2 TX Handler */
241 UARTRX3_Handler, /* 38: UART 3 RX Handler */
242 UARTTX3_Handler, /* 39: UART 3 TX Handler */
243 UARTRX4_Handler, /* 40: UART 4 RX Handler */
244 UARTTX4_Handler, /* 41: UART 4 TX Handler */
245 UART0_Combined_Handler, /* 42: UART 0 Combined Handler */
246 UART1_Combined_Handler, /* 43: UART 1 Combined Handler */
247 UART2_Combined_Handler, /* 44: UART 2 Combined Handler */
248 UART3_Combined_Handler, /* 45: UART 3 Combined Handler */
249 UART4_Combined_Handler, /* 46: UART 4 Combined Handler */
250 UARTOVF_Handler, /* 47: UART 0, 1, 2, 3, 4 & 5 Overflow Handler */
251 ETHERNET_Handler, /* 48: Ethernet Handler */
252 I2S_Handler, /* 49: Audio I2S Handler */
253 TOUCH_SCREEN_Handler, /* 50: Touch Screen Handler */
254 0, /* 51: Reserved */
255 SPI_ADC_Handler, /* 52: SPI ADC Handler */
256 SPI_SHIELD0_Handler, /* 53: SPI (Shield 0) Handler */
257 SPI_SHIELD1_Handler, /* 54: SPI (Shield 0) Handler */
258 0, /* 55: Reserved */
259 0, /* 56: Reserved */
260 0, /* 57: Reserved */
261 0, /* 58: Reserved */
262 0, /* 59: Reserved */
263 0, /* 60: Reserved */
264 0, /* 61: Reserved */
265 0, /* 62: Reserved */
266 0, /* 63: Reserved */
267 0, /* 64: Reserved */
268 0, /* 65: Reserved */
269 0, /* 66: Reserved */
270 0, /* 67: Reserved */
271 GPIO0_Combined_Handler, /* 68: GPIO 0 Combined Handler */
272 GPIO1_Combined_Handler, /* 69: GPIO 1 Combined Handler */
273 GPIO2_Combined_Handler, /* 70: GPIO 2 Combined Handler */
274 GPIO3_Combined_Handler, /* 71: GPIO 3 Combined Handler */
275 GPIO0_0_Handler, /* 72: GPIO0 Pin 0 Handler */
276 GPIO0_1_Handler, /* 73: GPIO0 Pin 1 Handler */
277 GPIO0_2_Handler, /* 74: GPIO0 Pin 2 Handler */
278 GPIO0_3_Handler, /* 75: GPIO0 Pin 3 Handler */
279 GPIO0_4_Handler, /* 76: GPIO0 Pin 4 Handler */
280 GPIO0_5_Handler, /* 77: GPIO0 Pin 5 Handler */
281 GPIO0_6_Handler, /* 78: GPIO0 Pin 6 Handler */
282 GPIO0_7_Handler, /* 79: GPIO0 Pin 7 Handler */
283 GPIO0_8_Handler, /* 80: GPIO0 Pin 8 Handler */
284 GPIO0_9_Handler, /* 81: GPIO0 Pin 9 Handler */
285 GPIO0_10_Handler, /* 82: GPIO0 Pin 10 Handler */
286 GPIO0_11_Handler, /* 83: GPIO0 Pin 11 Handler */
287 GPIO0_12_Handler, /* 84: GPIO0 Pin 12 Handler */
288 GPIO0_13_Handler, /* 85: GPIO0 Pin 13 Handler */
289 GPIO0_14_Handler, /* 86: GPIO0 Pin 14 Handler */
290 GPIO0_15_Handler, /* 87: GPIO0 Pin 15 Handler */
291 GPIO1_0_Handler, /* 88: GPIO1 Pin 0 Handler */
292 GPIO1_1_Handler, /* 89: GPIO1 Pin 1 Handler */
293 GPIO1_2_Handler, /* 90: GPIO1 Pin 2 Handler */
294 GPIO1_3_Handler, /* 91: GPIO1 Pin 3 Handler */
295 GPIO1_4_Handler, /* 92: GPIO1 Pin 4 Handler */
296 GPIO1_5_Handler, /* 93: GPIO1 Pin 5 Handler */
297 GPIO1_6_Handler, /* 94: GPIO1 Pin 6 Handler */
298 GPIO1_7_Handler, /* 95: GPIO1 Pin 7 Handler */
299 GPIO1_8_Handler, /* 96: GPIO1 Pin 8 Handler */
300 GPIO1_9_Handler, /* 97: GPIO1 Pin 9 Handler */
301 GPIO1_10_Handler, /* 98: GPIO1 Pin 10 Handler */
302 GPIO1_11_Handler, /* 99: GPIO1 Pin 11 Handler */
303 GPIO1_12_Handler, /* 100: GPIO1 Pin 12 Handler */
304 GPIO1_13_Handler, /* 101: GPIO1 Pin 13 Handler */
305 GPIO1_14_Handler, /* 102: GPIO1 Pin 14 Handler */
306 GPIO1_15_Handler, /* 103: GPIO1 Pin 15 Handler */
307 GPIO2_0_Handler, /* 104: GPIO2 Pin 0 Handler */
308 GPIO2_1_Handler, /* 105: GPIO2 Pin 1 Handler */
309 GPIO2_2_Handler, /* 106: GPIO2 Pin 2 Handler */
310 GPIO2_3_Handler, /* 107: GPIO2 Pin 3 Handler */
311 GPIO2_4_Handler, /* 108: GPIO2 Pin 4 Handler */
312 GPIO2_5_Handler, /* 109: GPIO2 Pin 5 Handler */
313 GPIO2_6_Handler, /* 110: GPIO2 Pin 6 Handler */
314 GPIO2_7_Handler, /* 111: GPIO2 Pin 7 Handler */
315 GPIO2_8_Handler, /* 112: GPIO2 Pin 8 Handler */
316 GPIO2_9_Handler, /* 113: GPIO2 Pin 9 Handler */
317 GPIO2_10_Handler, /* 114: GPIO2 Pin 10 Handler */
318 GPIO2_11_Handler, /* 115: GPIO2 Pin 11 Handler */
319 GPIO2_12_Handler, /* 116: GPIO2 Pin 12 Handler */
320 GPIO2_13_Handler, /* 117: GPIO2 Pin 13 Handler */
321 GPIO2_14_Handler, /* 118: GPIO2 Pin 14 Handler */
322 GPIO2_15_Handler, /* 119: GPIO2 Pin 15 Handler */
323 GPIO3_0_Handler, /* 120: GPIO3 Pin 0 Handler */
324 GPIO3_1_Handler, /* 121: GPIO3 Pin 1 Handler */
325 GPIO3_2_Handler, /* 122: GPIO3 Pin 2 Handler */
326 GPIO3_3_Handler, /* 123: GPIO3 Pin 3 Handler */
327 UARTRX5_Handler, /* 124: UART 5 RX Interrupt */
328 UARTTX5_Handler, /* 125: UART 5 TX Interrupt */
329 UART5_Handler, /* 126: UART 5 combined Interrupt */
330 HDLCD_Handler, /* 127: HDCLCD interrupt */
331 };
332
333 #if defined ( __GNUC__ )
334 #pragma GCC diagnostic pop
335 #endif
336
337 /*----------------------------------------------------------------------------
338 Reset Handler called on controller reset
339 *----------------------------------------------------------------------------*/
Reset_Handler(void)340 void Reset_Handler(void)
341 {
342 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
343 __disable_irq();
344 #endif
345 __set_PSP((uint32_t)(&__INITIAL_SP));
346
347 __set_MSPLIM((uint32_t)(&__STACK_LIMIT));
348 __set_PSPLIM((uint32_t)(&__STACK_LIMIT));
349
350 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
351 __TZ_set_STACKSEAL_S((uint32_t *)(&__STACK_SEAL));
352 #endif
353
354 SystemInit(); /* CMSIS System Initialization */
355 __PROGRAM_START(); /* Enter PreMain (C library entry point) */
356 }
357