]> begriffs open source - cmsis/blob - CMSIS/Core/Template/Device_M/Source/startup_Device.c
Possible bugs in MMU_MemorySection(), MMU_MemoryPage() (#219)
[cmsis] / CMSIS / Core / Template / Device_M / Source / startup_Device.c
1 /******************************************************************************
2  * @file     startup_<Device>.c
3  * @brief    CMSIS-Core(M) Device Startup File for
4  *           Device <Device>
5  * @version  V1.0.0
6  * @date     20. January 2021
7  ******************************************************************************/
8 /*
9  * Copyright (c) 2009-2021 Arm Limited. All rights reserved.
10  *
11  * SPDX-License-Identifier: Apache-2.0
12  *
13  * Licensed under the Apache License, Version 2.0 (the License); you may
14  * not use this file except in compliance with the License.
15  * You may obtain a copy of the License at
16  *
17  * www.apache.org/licenses/LICENSE-2.0
18  *
19  * Unless required by applicable law or agreed to in writing, software
20  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
21  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22  * See the License for the specific language governing permissions and
23  * limitations under the License.
24  */
25
26 /* ToDo: rename this file from 'startup_Device.c' to 'startup_<Device>.c according to your device naming */
27
28
29 #include "<Device>.h"
30
31 /*---------------------------------------------------------------------------
32   External References
33  *---------------------------------------------------------------------------*/
34 extern uint32_t __INITIAL_SP;
35 extern uint32_t __STACK_LIMIT;
36 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
37 extern uint32_t __STACK_SEAL;
38 #endif
39
40 extern __NO_RETURN void __PROGRAM_START(void);
41
42 /*---------------------------------------------------------------------------
43   Internal References
44  *---------------------------------------------------------------------------*/
45 __NO_RETURN void Reset_Handler  (void);
46 __NO_RETURN void Default_Handler(void);
47
48 /* ToDo: Add Cortex exception handler according the used Cortex-Core */
49 /*---------------------------------------------------------------------------
50   Exception / Interrupt Handler
51  *---------------------------------------------------------------------------*/
52 /* Exceptions */
53 void NMI_Handler            (void) __attribute__ ((weak, alias("Default_Handler")));
54 void HardFault_Handler      (void) __attribute__ ((weak));
55 void MemManage_Handler      (void) __attribute__ ((weak, alias("Default_Handler")));
56 void BusFault_Handler       (void) __attribute__ ((weak, alias("Default_Handler")));
57 void UsageFault_Handler     (void) __attribute__ ((weak, alias("Default_Handler")));
58 void SecureFault_Handler    (void) __attribute__ ((weak, alias("Default_Handler")));
59 void SVC_Handler            (void) __attribute__ ((weak, alias("Default_Handler")));
60 void DebugMon_Handler       (void) __attribute__ ((weak, alias("Default_Handler")));
61 void PendSV_Handler         (void) __attribute__ ((weak, alias("Default_Handler")));
62 void SysTick_Handler        (void) __attribute__ ((weak, alias("Default_Handler")));
63
64 /* ToDo: Add your device specific interrupt handler */
65 void <DeviceInterrupt first>_Handler     (void) __attribute__ ((weak, alias("Default_Handler")));
66 ...
67 void <DeviceInterrupt last>_Handler      (void) __attribute__ ((weak, alias("Default_Handler")));
68
69
70 /*----------------------------------------------------------------------------
71   Exception / Interrupt Vector table
72  *----------------------------------------------------------------------------*/
73
74 #if defined ( __GNUC__ )
75 #pragma GCC diagnostic push
76 #pragma GCC diagnostic ignored "-Wpedantic"
77 #endif
78
79 /* ToDo: Add Cortex exception vectors according the used Cortex-Core */
80 extern const VECTOR_TABLE_Type __VECTOR_TABLE[<Device vector table entries>];
81        const VECTOR_TABLE_Type __VECTOR_TABLE[<Device vector table entries>] __VECTOR_TABLE_ATTRIBUTE = {
82   (VECTOR_TABLE_Type)(&__INITIAL_SP),  /*     Initial Stack Pointer */
83   Reset_Handler,                       /*     Reset Handler */
84   NMI_Handler,                         /* -14 NMI Handler */
85   HardFault_Handler,                   /* -13 Hard Fault Handler */
86   MemManage_Handler,                   /* -12 MPU Fault Handler */
87   BusFault_Handler,                    /* -11 Bus Fault Handler */
88   UsageFault_Handler,                  /* -10 Usage Fault Handler */
89   SecureFault_Handler,                 /*  -9 Secure Fault Handler */
90   0,                                   /*     Reserved */
91   0,                                   /*     Reserved */
92   0,                                   /*     Reserved */
93   SVC_Handler,                         /*  -5 SVCall Handler */
94   DebugMon_Handler,                    /*  -4 Debug Monitor Handler */
95   0,                                   /*     Reserved */
96   PendSV_Handler,                      /*  -2 PendSV Handler */
97   SysTick_Handler,                     /*  -1 SysTick Handler */
98
99 /* ToDo: Add your device specific interrupt vectors */
100   /* Interrupts */
101   <DeviceInterrupt first>_Handler,     /* first Device Interrupt */
102   ...
103   <DeviceInterrupt last>_Handler       /* last Device Interrupt */
104 };
105
106 #if defined ( __GNUC__ )
107 #pragma GCC diagnostic pop
108 #endif
109
110 /*---------------------------------------------------------------------------
111   Reset Handler called on controller reset
112  *---------------------------------------------------------------------------*/
113 __NO_RETURN void Reset_Handler(void)
114 {
115   __set_PSP((uint32_t)(&__INITIAL_SP));
116
117 /* ToDo: Initialize stack limit register for Armv8-M Main Extension based processors*/
118   __set_MSPLIM((uint32_t)(&__STACK_LIMIT));
119   __set_PSPLIM((uint32_t)(&__STACK_LIMIT));
120
121 /* ToDo: Add stack sealing for Armv8-M based processors */
122 #if defined (__ARM_FEATURE_CMSE) && (__ARM_FEATURE_CMSE == 3U)
123   __TZ_set_STACKSEAL_S((uint32_t *)(&__STACK_SEAL));
124 #endif
125
126   SystemInit();                    /* CMSIS System Initialization */
127   __PROGRAM_START();               /* Enter PreMain (C library entry point) */
128 }
129
130
131 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
132   #pragma clang diagnostic push
133   #pragma clang diagnostic ignored "-Wmissing-noreturn"
134 #endif
135
136 /*---------------------------------------------------------------------------
137   Hard Fault Handler
138  *---------------------------------------------------------------------------*/
139 void HardFault_Handler(void)
140 {
141   while(1);
142 }
143
144 /*---------------------------------------------------------------------------
145   Default Handler for Exceptions / Interrupts
146  *---------------------------------------------------------------------------*/
147 void Default_Handler(void)
148 {
149   while(1);
150 }
151
152 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
153   #pragma clang diagnostic pop
154 #endif