1 /******************************************************************************
2  * @file     startup_ARMCM3.c
3  * @brief    CMSIS-Core(M) Device Startup File for a Cortex-M3 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 #include "ARMCM3.h"
26 
27 /*----------------------------------------------------------------------------
28   External References
29  *----------------------------------------------------------------------------*/
30 extern uint32_t __INITIAL_SP;
31 
32 extern __NO_RETURN void __PROGRAM_START(void) ;
33 
34 /*----------------------------------------------------------------------------
35   Internal References
36  *----------------------------------------------------------------------------*/
37 __NO_RETURN void Default_Handler(void);
38 __NO_RETURN void Reset_Handler  (void);
39 
40 /*----------------------------------------------------------------------------
41   Exception / Interrupt Handler
42  *----------------------------------------------------------------------------*/
43 /* Exceptions */
44 void NMI_Handler            (void) __attribute__ ((weak, alias("Default_Handler")));
45 void HardFault_Handler      (void) __attribute__ ((weak));
46 void MemManage_Handler      (void) __attribute__ ((weak, alias("Default_Handler")));
47 void BusFault_Handler       (void) __attribute__ ((weak, alias("Default_Handler")));
48 void UsageFault_Handler     (void) __attribute__ ((weak, alias("Default_Handler")));
49 void SVC_Handler            (void) __attribute__ ((weak, alias("Default_Handler")));
50 void DebugMon_Handler       (void) __attribute__ ((weak, alias("Default_Handler")));
51 void PendSV_Handler         (void) __attribute__ ((weak, alias("Default_Handler")));
52 void SysTick_Handler        (void) __attribute__ ((weak, alias("Default_Handler")));
53 
54 void Interrupt0_Handler     (void) __attribute__ ((weak, alias("Default_Handler")));
55 void Interrupt1_Handler     (void) __attribute__ ((weak, alias("Default_Handler")));
56 void Interrupt2_Handler     (void) __attribute__ ((weak, alias("Default_Handler")));
57 void Interrupt3_Handler     (void) __attribute__ ((weak, alias("Default_Handler")));
58 void Interrupt4_Handler     (void) __attribute__ ((weak, alias("Default_Handler")));
59 void Interrupt5_Handler     (void) __attribute__ ((weak, alias("Default_Handler")));
60 void Interrupt6_Handler     (void) __attribute__ ((weak, alias("Default_Handler")));
61 void Interrupt7_Handler     (void) __attribute__ ((weak, alias("Default_Handler")));
62 void Interrupt8_Handler     (void) __attribute__ ((weak, alias("Default_Handler")));
63 void Interrupt9_Handler     (void) __attribute__ ((weak, alias("Default_Handler")));
64 
65 
66 /*----------------------------------------------------------------------------
67   Exception / Interrupt Vector table
68  *----------------------------------------------------------------------------*/
69 
70 #if defined ( __GNUC__ )
71 #pragma GCC diagnostic push
72 #pragma GCC diagnostic ignored "-Wpedantic"
73 #endif
74 
75 extern const VECTOR_TABLE_Type __VECTOR_TABLE[240];
76        const VECTOR_TABLE_Type __VECTOR_TABLE[240] __VECTOR_TABLE_ATTRIBUTE = {
77   (VECTOR_TABLE_Type)(&__INITIAL_SP),       /*     Initial Stack Pointer */
78   Reset_Handler,                            /*     Reset Handler */
79   NMI_Handler,                              /* -14 NMI Handler */
80   HardFault_Handler,                        /* -13 Hard Fault Handler */
81   MemManage_Handler,                        /* -12 MPU Fault Handler */
82   BusFault_Handler,                         /* -11 Bus Fault Handler */
83   UsageFault_Handler,                       /* -10 Usage Fault Handler */
84   0,                                        /*     Reserved */
85   0,                                        /*     Reserved */
86   0,                                        /*     Reserved */
87   0,                                        /*     Reserved */
88   SVC_Handler,                              /*  -5 SVCall Handler */
89   DebugMon_Handler,                         /*  -4 Debug Monitor Handler */
90   0,                                        /*     Reserved */
91   PendSV_Handler,                           /*  -2 PendSV Handler */
92   SysTick_Handler,                          /*  -1 SysTick Handler */
93 
94   /* Interrupts */
95   Interrupt0_Handler,                       /*   0 Interrupt 0 */
96   Interrupt1_Handler,                       /*   1 Interrupt 1 */
97   Interrupt2_Handler,                       /*   2 Interrupt 2 */
98   Interrupt3_Handler,                       /*   3 Interrupt 3 */
99   Interrupt4_Handler,                       /*   4 Interrupt 4 */
100   Interrupt5_Handler,                       /*   5 Interrupt 5 */
101   Interrupt6_Handler,                       /*   6 Interrupt 6 */
102   Interrupt7_Handler,                       /*   7 Interrupt 7 */
103   Interrupt8_Handler,                       /*   8 Interrupt 8 */
104   Interrupt9_Handler                        /*   9 Interrupt 9 */
105                                             /* Interrupts 10 .. 223 are left out */
106 };
107 
108 #if defined ( __GNUC__ )
109 #pragma GCC diagnostic pop
110 #endif
111 
112 /*----------------------------------------------------------------------------
113   Reset Handler called on controller reset
114  *----------------------------------------------------------------------------*/
Reset_Handler(void)115 void Reset_Handler(void)
116 {
117   SystemInit();                             /* CMSIS System Initialization */
118   __PROGRAM_START();                        /* Enter PreMain (C library entry point) */
119 }
120 
121 /*----------------------------------------------------------------------------
122   Hard Fault Handler
123  *----------------------------------------------------------------------------*/
HardFault_Handler(void)124 __NO_RETURN void HardFault_Handler(void)
125 {
126   while(1);
127 }
128 
129 /*----------------------------------------------------------------------------
130   Default Handler for Exceptions / Interrupts
131  *----------------------------------------------------------------------------*/
Default_Handler(void)132 void Default_Handler(void)
133 {
134   while(1);
135 }
136