1 /*
2 * This file is part of the MicroPython project, http://micropython.org/
3 *
4 * The MIT License (MIT)
5 *
6 * Copyright (c) 2017 Glenn Ruben Bakke
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
25 */
26
27 #include <stdint.h>
28
29 extern uint32_t _estack;
30 extern uint32_t _sidata;
31 extern uint32_t _sdata;
32 extern uint32_t _edata;
33 extern uint32_t _sbss;
34 extern uint32_t _ebss;
35
36 typedef void (*func)(void);
37
38 extern void _start(void) __attribute__((noreturn));
39 extern void SystemInit(void);
40
Default_Handler(void)41 void Default_Handler(void) {
42 while (1);
43 }
44
Reset_Handler(void)45 void Reset_Handler(void) {
46 uint32_t * p_src = &_sidata;
47 uint32_t * p_dest = &_sdata;
48
49 while (p_dest < &_edata) {
50 *p_dest++ = *p_src++;
51 }
52
53 uint32_t * p_bss = &_sbss;
54 uint32_t * p_bss_end = &_ebss;
55 while (p_bss < p_bss_end) {
56 *p_bss++ = 0ul;
57 }
58
59 SystemInit();
60 _start();
61 }
62
63 void NMI_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
64 void HardFault_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
65 void MemoryManagement_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
66 void BusFault_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
67 void UsageFault_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
68 void SVC_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
69 void DebugMon_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
70 void PendSV_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
71 void SysTick_Handler (void) __attribute__ ((weak, alias("Default_Handler")));
72
73 void POWER_CLOCK_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
74 void RADIO_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
75 void UARTE0_UART0_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
76 void SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
77 void SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
78 void NFCT_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
79 void GPIOTE_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
80 void SAADC_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
81 void TIMER0_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
82 void TIMER1_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
83 void TIMER2_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
84 void RTC0_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
85 void TEMP_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
86 void RNG_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
87 void ECB_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
88 void CCM_AAR_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
89 void WDT_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
90 void RTC1_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
91 void QDEC_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
92 void COMP_LPCOMP_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
93 void SWI0_EGU0_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
94 void SWI1_EGU1_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
95 void SWI2_EGU2_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
96 void SWI3_EGU3_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
97 void SWI4_EGU4_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
98 void SWI5_EGU5_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
99 void TIMER3_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
100 void TIMER4_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
101 void PWM0_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
102 void PDM_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
103 void MWU_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
104 void PWM1_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
105 void PWM2_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
106 void SPIM2_SPIS2_SPI2_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
107 void RTC2_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
108 void I2S_IRQHandler (void) __attribute__ ((weak, alias("Default_Handler")));
109
110 const func __Vectors[] __attribute__ ((section(".isr_vector"),used)) = {
111 (func)&_estack,
112 Reset_Handler,
113 NMI_Handler,
114 HardFault_Handler,
115 MemoryManagement_Handler,
116 BusFault_Handler,
117 UsageFault_Handler,
118 0,
119 0,
120 0,
121 0,
122 SVC_Handler,
123 DebugMon_Handler,
124 0,
125 PendSV_Handler,
126 SysTick_Handler,
127
128 /* External Interrupts */
129 POWER_CLOCK_IRQHandler,
130 RADIO_IRQHandler,
131 UARTE0_UART0_IRQHandler,
132 SPIM0_SPIS0_TWIM0_TWIS0_SPI0_TWI0_IRQHandler,
133 SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQHandler,
134 NFCT_IRQHandler,
135 GPIOTE_IRQHandler,
136 SAADC_IRQHandler,
137 TIMER0_IRQHandler,
138 TIMER1_IRQHandler,
139 TIMER2_IRQHandler,
140 RTC0_IRQHandler,
141 TEMP_IRQHandler,
142 RNG_IRQHandler,
143 ECB_IRQHandler,
144 CCM_AAR_IRQHandler,
145 WDT_IRQHandler,
146 RTC1_IRQHandler,
147 QDEC_IRQHandler,
148 COMP_LPCOMP_IRQHandler,
149 SWI0_EGU0_IRQHandler,
150 SWI1_EGU1_IRQHandler,
151 SWI2_EGU2_IRQHandler,
152 SWI3_EGU3_IRQHandler,
153 SWI4_EGU4_IRQHandler,
154 SWI5_EGU5_IRQHandler,
155 TIMER3_IRQHandler,
156 TIMER4_IRQHandler,
157 PWM0_IRQHandler,
158 PDM_IRQHandler,
159 0,
160 0,
161 MWU_IRQHandler,
162 PWM1_IRQHandler,
163 PWM2_IRQHandler,
164 SPIM2_SPIS2_SPI2_IRQHandler,
165 RTC2_IRQHandler,
166 I2S_IRQHandler
167 };
168