1 /******************************************************************************
2  * @file     startup_ARMCM23.c
3  * @brief    CMSIS-Core Device Startup File for a Cortex-M23 Device
4  * @version  V2.1.0
5  * @date     16. December 2020
6  ******************************************************************************/
7 /*
8  * Copyright (c) 2009-2020 Arm Limited. All rights reserved.
9  *
10  * SPDX-License-Identifier: Apache-2.0
11  *
12  * Licensed under the Apache License, Version 2.0 (the License); you may
13  * not use this file except in compliance with the License.
14  * You may obtain a copy of the License at
15  *
16  * www.apache.org/licenses/LICENSE-2.0
17  *
18  * Unless required by applicable law or agreed to in writing, software
19  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
20  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  * See the License for the specific language governing permissions and
22  * limitations under the License.
23  */
24 
25 #if defined (ARMCM23)
26   #include "ARMCM23.h"
27 #elif defined (ARMCM23_TZ)
28   #include "ARMCM23_TZ.h"
29 #else
30   #error device not specified!
31 #endif
32 
33 /*----------------------------------------------------------------------------
34   External References
35  *----------------------------------------------------------------------------*/
36 extern uint32_t __INITIAL_SP;
37 extern uint32_t __STACK_LIMIT;
38 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
39 extern uint32_t __STACK_SEAL;
40 #endif
41 
42 extern __NO_RETURN void __PROGRAM_START(void);
43 
44 /*----------------------------------------------------------------------------
45   Internal References
46  *----------------------------------------------------------------------------*/
47 __NO_RETURN void Reset_Handler  (void);
48             void Default_Handler(void);
49 
50 /*----------------------------------------------------------------------------
51   Exception / Interrupt Handler
52  *----------------------------------------------------------------------------*/
53 /* Exceptions */
54 void NMI_Handler            (void) __attribute__ ((weak, alias("Default_Handler")));
55 void HardFault_Handler      (void) __attribute__ ((weak));
56 void SVC_Handler            (void) __attribute__ ((weak, alias("Default_Handler")));
57 void PendSV_Handler         (void) __attribute__ ((weak, alias("Default_Handler")));
58 void SysTick_Handler        (void) __attribute__ ((weak, alias("Default_Handler")));
59 
60 void Interrupt0_Handler     (void) __attribute__ ((weak, alias("Default_Handler")));
61 void Interrupt1_Handler     (void) __attribute__ ((weak, alias("Default_Handler")));
62 void Interrupt2_Handler     (void) __attribute__ ((weak, alias("Default_Handler")));
63 void Interrupt3_Handler     (void) __attribute__ ((weak, alias("Default_Handler")));
64 void Interrupt4_Handler     (void) __attribute__ ((weak, alias("Default_Handler")));
65 void Interrupt5_Handler     (void) __attribute__ ((weak, alias("Default_Handler")));
66 void Interrupt6_Handler     (void) __attribute__ ((weak, alias("Default_Handler")));
67 void Interrupt7_Handler     (void) __attribute__ ((weak, alias("Default_Handler")));
68 void Interrupt8_Handler     (void) __attribute__ ((weak, alias("Default_Handler")));
69 void Interrupt9_Handler     (void) __attribute__ ((weak, alias("Default_Handler")));
70 
71 
72 /*----------------------------------------------------------------------------
73   Exception / Interrupt Vector table
74  *----------------------------------------------------------------------------*/
75 
76 #if defined ( __GNUC__ )
77 #pragma GCC diagnostic push
78 #pragma GCC diagnostic ignored "-Wpedantic"
79 #endif
80 
81 extern const VECTOR_TABLE_Type __VECTOR_TABLE[240];
82        const VECTOR_TABLE_Type __VECTOR_TABLE[240] __VECTOR_TABLE_ATTRIBUTE = {
83   (VECTOR_TABLE_Type)(&__INITIAL_SP),       /*     Initial Stack Pointer */
84   Reset_Handler,                            /*     Reset Handler */
85   NMI_Handler,                              /* -14 NMI Handler */
86   HardFault_Handler,                        /* -13 Hard Fault Handler */
87   0,                                        /*     Reserved */
88   0,                                        /*     Reserved */
89   0,                                        /*     Reserved */
90   0,                                        /*     Reserved */
91   0,                                        /*     Reserved */
92   0,                                        /*     Reserved */
93   0,                                        /*     Reserved */
94   SVC_Handler,                              /*  -5 SVCall Handler */
95   0,                                        /*     Reserved */
96   0,                                        /*     Reserved */
97   PendSV_Handler,                           /*  -2 PendSV Handler */
98   SysTick_Handler,                          /*  -1 SysTick Handler */
99 
100   /* Interrupts */
101   Interrupt0_Handler,                       /*   0 Interrupt 0 */
102   Interrupt1_Handler,                       /*   1 Interrupt 1 */
103   Interrupt2_Handler,                       /*   2 Interrupt 2 */
104   Interrupt3_Handler,                       /*   3 Interrupt 3 */
105   Interrupt4_Handler,                       /*   4 Interrupt 4 */
106   Interrupt5_Handler,                       /*   5 Interrupt 5 */
107   Interrupt6_Handler,                       /*   6 Interrupt 6 */
108   Interrupt7_Handler,                       /*   7 Interrupt 7 */
109   Interrupt8_Handler,                       /*   8 Interrupt 8 */
110   Interrupt9_Handler                        /*   9 Interrupt 9 */
111                                             /* Interrupts 10 .. 223 are left out */
112 };
113 
114 #if defined ( __GNUC__ )
115 #pragma GCC diagnostic pop
116 #endif
117 
118 /*----------------------------------------------------------------------------
119   Reset Handler called on controller reset
120  *----------------------------------------------------------------------------*/
Reset_Handler(void)121 __NO_RETURN void Reset_Handler(void)
122 {
123   __set_PSP((uint32_t)(&__INITIAL_SP));
124 
125 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
126   __set_MSPLIM((uint32_t)(&__STACK_LIMIT));
127   __set_PSPLIM((uint32_t)(&__STACK_LIMIT));
128 
129   __TZ_set_STACKSEAL_S((uint32_t *)(&__STACK_SEAL));
130 #endif
131 
132   SystemInit();                             /* CMSIS System Initialization */
133   __PROGRAM_START();                        /* Enter PreMain (C library entry point) */
134 }
135 
136 
137 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
138   #pragma clang diagnostic push
139   #pragma clang diagnostic ignored "-Wmissing-noreturn"
140 #endif
141 
142 /*----------------------------------------------------------------------------
143   Hard Fault Handler
144  *----------------------------------------------------------------------------*/
HardFault_Handler(void)145 void HardFault_Handler(void)
146 {
147   while(1);
148 }
149 
150 /*----------------------------------------------------------------------------
151   Default Handler for Exceptions / Interrupts
152  *----------------------------------------------------------------------------*/
Default_Handler(void)153 void Default_Handler(void)
154 {
155   while(1);
156 }
157 
158 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
159   #pragma clang diagnostic pop
160 #endif
161 
162