1 /******************************************************************************
2 * @file startup_ARMCM4.c
3 * @brief CMSIS-Core(M) Device Startup File for a Cortex-M4 Device
4 * @version V2.0.2
5 * @date 15. November 2019
6 ******************************************************************************/
7 /*
8 * Copyright (c) 2009-2019 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 (ARMCM4)
26 #include "ARMCM4.h"
27 #elif defined (ARMCM4_FP)
28 #include "ARMCM4_FP.h"
29 #else
30 #error device not specified!
31 #endif
32
33 /*----------------------------------------------------------------------------
34 External References
35 *----------------------------------------------------------------------------*/
36 extern uint32_t __INITIAL_SP;
37
38 extern __NO_RETURN void __PROGRAM_START(void);
39
40 /*----------------------------------------------------------------------------
41 Internal References
42 *----------------------------------------------------------------------------*/
43 void __NO_RETURN Default_Handler(void);
44 void __NO_RETURN Reset_Handler (void);
45
46 /*----------------------------------------------------------------------------
47 Exception / Interrupt Handler
48 *----------------------------------------------------------------------------*/
49 /* Exceptions */
50 void NMI_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
51 void HardFault_Handler (void) __attribute__ ((weak));
52 void MemManage_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
53 void BusFault_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
54 void UsageFault_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
55 void SVC_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
56 void DebugMon_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 MemManage_Handler, /* -12 MPU Fault Handler */
88 BusFault_Handler, /* -11 Bus Fault Handler */
89 UsageFault_Handler, /* -10 Usage Fault Handler */
90 0, /* Reserved */
91 0, /* Reserved */
92 0, /* Reserved */
93 0, /* Reserved */
94 SVC_Handler, /* -5 SVCall Handler */
95 DebugMon_Handler, /* -4 Debug Monitor Handler */
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 void Reset_Handler(void)
122 {
123 SystemInit(); /* CMSIS System Initialization */
124 __PROGRAM_START(); /* Enter PreMain (C library entry point) */
125 }
126
127 /*----------------------------------------------------------------------------
128 Hard Fault Handler
129 *----------------------------------------------------------------------------*/
HardFault_Handler(void)130 __NO_RETURN void HardFault_Handler(void)
131 {
132 while(1);
133 }
134
135 /*----------------------------------------------------------------------------
136 Default Handler for Exceptions / Interrupts
137 *----------------------------------------------------------------------------*/
Default_Handler(void)138 void Default_Handler(void)
139 {
140 while(1);
141 }
142