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