1 /******************************************************************************
2 * @file startup_<Device>.c
3 * @brief CMSIS-Core(M) Device Startup File for
6 * @date 20. January 2021
7 ******************************************************************************/
9 * Copyright (c) 2009-2021 Arm Limited. All rights reserved.
11 * SPDX-License-Identifier: Apache-2.0
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
17 * www.apache.org/licenses/LICENSE-2.0
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.
26 /* ToDo: rename this file from 'startup_Device.c' to 'startup_<Device>.c according to your device naming */
31 /*---------------------------------------------------------------------------
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;
40 extern __NO_RETURN void __PROGRAM_START(void);
42 /*---------------------------------------------------------------------------
44 *---------------------------------------------------------------------------*/
45 __NO_RETURN void Reset_Handler (void);
46 __NO_RETURN void Default_Handler(void);
48 /* ToDo: Add Cortex exception handler according the used Cortex-Core */
49 /*---------------------------------------------------------------------------
50 Exception / Interrupt Handler
51 *---------------------------------------------------------------------------*/
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")));
64 /* ToDo: Add your device specific interrupt handler */
65 void <DeviceInterrupt first>_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
67 void <DeviceInterrupt last>_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
70 /*----------------------------------------------------------------------------
71 Exception / Interrupt Vector table
72 *----------------------------------------------------------------------------*/
74 #if defined ( __GNUC__ )
75 #pragma GCC diagnostic push
76 #pragma GCC diagnostic ignored "-Wpedantic"
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 */
93 SVC_Handler, /* -5 SVCall Handler */
94 DebugMon_Handler, /* -4 Debug Monitor Handler */
96 PendSV_Handler, /* -2 PendSV Handler */
97 SysTick_Handler, /* -1 SysTick Handler */
99 /* ToDo: Add your device specific interrupt vectors */
101 <DeviceInterrupt first>_Handler, /* first Device Interrupt */
103 <DeviceInterrupt last>_Handler /* last Device Interrupt */
106 #if defined ( __GNUC__ )
107 #pragma GCC diagnostic pop
110 /*---------------------------------------------------------------------------
111 Reset Handler called on controller reset
112 *---------------------------------------------------------------------------*/
113 __NO_RETURN void Reset_Handler(void)
115 __set_PSP((uint32_t)(&__INITIAL_SP));
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));
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));
126 SystemInit(); /* CMSIS System Initialization */
127 __PROGRAM_START(); /* Enter PreMain (C library entry point) */
131 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
132 #pragma clang diagnostic push
133 #pragma clang diagnostic ignored "-Wmissing-noreturn"
136 /*---------------------------------------------------------------------------
138 *---------------------------------------------------------------------------*/
139 void HardFault_Handler(void)
144 /*---------------------------------------------------------------------------
145 Default Handler for Exceptions / Interrupts
146 *---------------------------------------------------------------------------*/
147 void Default_Handler(void)
152 #if defined(__ARMCC_VERSION) && (__ARMCC_VERSION >= 6010050)
153 #pragma clang diagnostic pop