-
Notifications
You must be signed in to change notification settings - Fork 0
/
stm32f4_startup.c
245 lines (228 loc) · 11.3 KB
/
stm32f4_startup.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#include<stdint.h>
#define SRAM_START 0x20000000U
#define SRAM_SIZE (128 * 1024) //128KB
#define SRAM_END ((SRAM_START) + (SRAM_SIZE))
#define STACK_START SRAM_END
extern uint32_t _etext;
extern uint32_t _sdata;
extern uint32_t _edata;
extern uint32_t _sbss;
extern uint32_t _ebss;
extern uint32_t _lo_data;
int main(void);
void __libc_init_array(void);
void Default_Handler(void);
void Reset_Handler(void);
void NMI_Handler(void) __attribute__((weak,alias("Default_Handler")));
void HardFault_Handler(void) __attribute__((weak,alias("Default_Handler")));
void MemManage_Handler(void) __attribute__((weak,alias("Default_Handler")));
void BusFault_Handler(void) __attribute__((weak,alias("Default_Handler")));
void UsageFault_Handler(void) __attribute__((weak,alias("Default_Handler")));
void SVCall_Handler(void) __attribute__((weak,alias("Default_Handler")));
void Debug_Monitor_Handler(void) __attribute__((weak,alias("Default_Handler")));
void PendSV_Handler(void) __attribute__((weak,alias("Default_Handler")));
void SysTick_Handler(void) __attribute__((weak,alias("Default_Handler")));
void WWDG_Handler(void) __attribute__((weak,alias("Default_Handler")));
void PVD_Handler(void) __attribute__((weak,alias("Default_Handler")));
void TAMP_STAMP_Handler(void) __attribute__((weak,alias("Default_Handler")));
void RTC_WKUP_Handler(void) __attribute__((weak,alias("Default_Handler")));
void FLASH_Handler(void) __attribute__((weak,alias("Default_Handler")));
void RCC_Handler(void) __attribute__((weak,alias("Default_Handler")));
void EXTI0_Handler(void) __attribute__((weak,alias("Default_Handler")));
void EXTI1_Handler(void) __attribute__((weak,alias("Default_Handler")));
void EXTI2_Handler(void) __attribute__((weak,alias("Default_Handler")));
void EXTI3_Handler(void) __attribute__((weak,alias("Default_Handler")));
void EXTI4_Handler(void) __attribute__((weak,alias("Default_Handler")));
void DMA1_Stream0_Handler(void) __attribute__((weak,alias("Default_Handler")));
void DMA1_Stream1_Handler(void) __attribute__((weak,alias("Default_Handler")));
void DMA1_Stream2_Handler(void) __attribute__((weak,alias("Default_Handler")));
void DMA1_Stream3_Handler(void) __attribute__((weak,alias("Default_Handler")));
void DMA1_Stream4_Handler(void) __attribute__((weak,alias("Default_Handler")));
void DMA1_Stream5_Handler(void) __attribute__((weak,alias("Default_Handler")));
void DMA1_Stream6_Handler(void) __attribute__((weak,alias("Default_Handler")));
void ADC_Handler(void) __attribute__((weak,alias("Default_Handler")));
void CAN1_TX_Handler(void) __attribute__((weak,alias("Default_Handler")));
void CAN1_RX0_Handler(void) __attribute__((weak,alias("Default_Handler")));
void CAN1_RX1_Handler(void) __attribute__((weak,alias("Default_Handler")));
void CAN1_SCE_Handler(void) __attribute__((weak,alias("Default_Handler")));
void EXTI9_5_Handler(void) __attribute__((weak,alias("Default_Handler")));
void TIM1_BRK_TIM9_Handler(void) __attribute__((weak,alias("Default_Handler")));
void TIM1_UP_TIM10_Handler(void) __attribute__((weak,alias("Default_Handler")));
void TIM1_TRG_COM_TIM11_Handler(void) __attribute__((weak,alias("Default_Handler")));
void TIM1_CC_Handler(void) __attribute__((weak,alias("Default_Handler")));
void TIM2_Handler(void) __attribute__((weak,alias("Default_Handler")));
void TIM3_Handler(void) __attribute__((weak,alias("Default_Handler")));
void TIM4_Handler(void) __attribute__((weak,alias("Default_Handler")));
void I2C1_EV_Handler(void) __attribute__((weak,alias("Default_Handler")));
void I2C1_ER_Handler(void) __attribute__((weak,alias("Default_Handler")));
void I2C2_EV_Handler(void) __attribute__((weak,alias("Default_Handler")));
void I2C2_ER_Handler(void) __attribute__((weak,alias("Default_Handler")));
void SPI1_Handler(void) __attribute__((weak,alias("Default_Handler")));
void SPI2_Handler(void) __attribute__((weak,alias("Default_Handler")));
void USART1_Handler(void) __attribute__((weak,alias("Default_Handler")));
void USART2_Handler(void) __attribute__((weak,alias("Default_Handler")));
void USART3_Handler(void) __attribute__((weak,alias("Default_Handler")));
void EXTI15_10_Handler(void) __attribute__((weak,alias("Default_Handler")));
void RTC_Alarm_Handler(void) __attribute__((weak,alias("Default_Handler")));
void OTG_FS_WKUP_Handler(void) __attribute__((weak,alias("Default_Handler")));
void TIM8_BRK_TIM12_Handler(void) __attribute__((weak,alias("Default_Handler")));
void TIM8_UP_TIM13_Handler(void) __attribute__((weak,alias("Default_Handler")));
void TIM8_TRG_COM_TIM14_Handler(void) __attribute__((weak,alias("Default_Handler")));
void TIM8_CC_Handler(void) __attribute__((weak,alias("Default_Handler")));
void DMA1_Stream7_Handler(void) __attribute__((weak,alias("Default_Handler")));
void FSMC_Handler(void) __attribute__((weak,alias("Default_Handler")));
void SDIO_Handler(void) __attribute__((weak,alias("Default_Handler")));
void TIM5_Handler(void) __attribute__((weak,alias("Default_Handler")));
void SPI3_Handler(void) __attribute__((weak,alias("Default_Handler")));
void UART4_Handler(void) __attribute__((weak,alias("Default_Handler")));
void UART5_Handler(void) __attribute__((weak,alias("Default_Handler")));
void TIM6_DAC_Handler(void) __attribute__((weak,alias("Default_Handler")));
void TIM7_Handler(void) __attribute__((weak,alias("Default_Handler")));
void DMA2_Stream0_Handler(void) __attribute__((weak,alias("Default_Handler")));
void DMA2_Stream1_Handler(void) __attribute__((weak,alias("Default_Handler")));
void DMA2_Stream2_Handler(void) __attribute__((weak,alias("Default_Handler")));
void DMA2_Stream3_Handler(void) __attribute__((weak,alias("Default_Handler")));
void DMA2_Stream4_Handler(void) __attribute__((weak,alias("Default_Handler")));
void ETH_Handler(void) __attribute__((weak,alias("Default_Handler")));
void ETH_WKUP_Handler(void) __attribute__((weak,alias("Default_Handler")));
void CAN2_TX_Handler(void) __attribute__((weak,alias("Default_Handler")));
void CAN2_RX0_Handler(void) __attribute__((weak,alias("Default_Handler")));
void CAN2_RX1_Handler(void) __attribute__((weak,alias("Default_Handler")));
void CAN2_SCE_Handler(void) __attribute__((weak,alias("Default_Handler")));
void OTG_FS_Handler(void) __attribute__((weak,alias("Default_Handler")));
void DMA2_Stream5_Handler(void) __attribute__((weak,alias("Default_Handler")));
void DMA2_Stream6_Handler(void) __attribute__((weak,alias("Default_Handler")));
void DMA2_Stream7_Handler(void) __attribute__((weak,alias("Default_Handler")));
void USART6_Handler(void) __attribute__((weak,alias("Default_Handler")));
void I2C3_EV_Handler(void) __attribute__((weak,alias("Default_Handler")));
void I2C3_ER_Handler(void) __attribute__((weak,alias("Default_Handler")));
void OTG_HS_EP1_OUT_Handler(void) __attribute__((weak,alias("Default_Handler")));
void OTG_HS_EP1_IN_Handler(void) __attribute__((weak,alias("Default_Handler")));
void OTG_HS_WKUP_Handler(void) __attribute__((weak,alias("Default_Handler")));
void OTG_HS_Handler(void) __attribute__((weak,alias("Default_Handler")));
void DCMI_Handler(void) __attribute__((weak,alias("Default_Handler")));
void CRYP_Handler(void) __attribute__((weak,alias("Default_Handler")));
void HASH_RNG_Handler(void) __attribute__((weak,alias("Default_Handler")));
void FPU_Handler(void) __attribute__((weak,alias("Default_Handler")));
uint32_t vectors[] __attribute__((section(".isr_vector"))) = {
STACK_START,
(uint32_t)Reset_Handler,
(uint32_t)&NMI_Handler,
(uint32_t)&HardFault_Handler,
(uint32_t)&MemManage_Handler,
(uint32_t)&BusFault_Handler,
(uint32_t)&UsageFault_Handler,
0,
0,
0,
0,
(uint32_t)&SVCall_Handler,
(uint32_t)&Debug_Monitor_Handler,
0,
(uint32_t)&PendSV_Handler,
(uint32_t)&SysTick_Handler,
(uint32_t)&WWDG_Handler,
(uint32_t)&PVD_Handler,
(uint32_t)&TAMP_STAMP_Handler,
(uint32_t)&RTC_WKUP_Handler,
(uint32_t)&FLASH_Handler,
(uint32_t)&RCC_Handler,
(uint32_t)&EXTI0_Handler,
(uint32_t)&EXTI1_Handler,
(uint32_t)&EXTI2_Handler,
(uint32_t)&EXTI3_Handler,
(uint32_t)&EXTI4_Handler,
(uint32_t)&DMA1_Stream0_Handler,
(uint32_t)&DMA1_Stream1_Handler,
(uint32_t)&DMA1_Stream2_Handler,
(uint32_t)&DMA1_Stream3_Handler,
(uint32_t)&DMA1_Stream4_Handler,
(uint32_t)&DMA1_Stream5_Handler,
(uint32_t)&DMA1_Stream6_Handler,
(uint32_t)&ADC_Handler,
(uint32_t)&CAN1_TX_Handler,
(uint32_t)&CAN1_RX0_Handler,
(uint32_t)&CAN1_RX1_Handler,
(uint32_t)&CAN1_SCE_Handler,
(uint32_t)&EXTI9_5_Handler,
(uint32_t)&TIM1_BRK_TIM9_Handler,
(uint32_t)&TIM1_UP_TIM10_Handler,
(uint32_t)&TIM1_TRG_COM_TIM11_Handler,
(uint32_t)&TIM1_CC_Handler,
(uint32_t)&TIM2_Handler,
(uint32_t)&TIM3_Handler,
(uint32_t)&TIM4_Handler,
(uint32_t)&I2C1_EV_Handler,
(uint32_t)&I2C1_ER_Handler,
(uint32_t)&I2C2_EV_Handler,
(uint32_t)&I2C2_ER_Handler,
(uint32_t)&SPI1_Handler,
(uint32_t)&SPI2_Handler,
(uint32_t)&USART1_Handler,
(uint32_t)&USART2_Handler,
(uint32_t)&USART3_Handler,
(uint32_t)&EXTI15_10_Handler,
(uint32_t)&RTC_Alarm_Handler,
(uint32_t)&OTG_FS_WKUP_Handler,
(uint32_t)&TIM8_BRK_TIM12_Handler,
(uint32_t)&TIM8_UP_TIM13_Handler,
(uint32_t)&TIM8_TRG_COM_TIM14_Handler,
(uint32_t)&TIM8_CC_Handler,
(uint32_t)&DMA1_Stream7_Handler,
(uint32_t)&FSMC_Handler,
(uint32_t)&SDIO_Handler,
(uint32_t)&TIM5_Handler,
(uint32_t)&SPI3_Handler,
(uint32_t)&UART4_Handler,
(uint32_t)&UART5_Handler,
(uint32_t)&TIM6_DAC_Handler,
(uint32_t)&TIM7_Handler,
(uint32_t)&DMA2_Stream0_Handler,
(uint32_t)&DMA2_Stream1_Handler,
(uint32_t)&DMA2_Stream2_Handler,
(uint32_t)&DMA2_Stream3_Handler,
(uint32_t)&DMA2_Stream4_Handler,
(uint32_t)Ð_Handler,
(uint32_t)Ð_WKUP_Handler,
(uint32_t)&CAN2_TX_Handler,
(uint32_t)&CAN2_RX0_Handler,
(uint32_t)&CAN2_RX1_Handler,
(uint32_t)&CAN2_SCE_Handler,
(uint32_t)&OTG_FS_Handler,
(uint32_t)&DMA2_Stream5_Handler,
(uint32_t)&DMA2_Stream6_Handler,
(uint32_t)&DMA2_Stream7_Handler,
(uint32_t)&USART6_Handler,
(uint32_t)&I2C3_EV_Handler,
(uint32_t)&I2C3_ER_Handler,
(uint32_t)&OTG_HS_EP1_OUT_Handler,
(uint32_t)&OTG_HS_EP1_IN_Handler,
(uint32_t)&OTG_HS_WKUP_Handler,
(uint32_t)&OTG_HS_Handler,
(uint32_t)&DCMI_Handler,
(uint32_t)&CRYP_Handler,
(uint32_t)&HASH_RNG_Handler,
(uint32_t)&FPU_Handler
};
void Default_Handler(void){
while(1); //hangs here
}
void Reset_Handler(void){
//copy .data section to SRAM
uint32_t size = (uint32_t)&_edata - (uint32_t)&_sdata;
uint8_t *pDst = (uint8_t*)&_sdata;
uint8_t *pSrc = (uint8_t*)&_lo_data;
for(uint32_t i=0; i<size; i++){
*pDst++ = *pSrc++;
}
//Init .bss section to sero is SRAM
size = (uint32_t)&_ebss - (uint32_t)&_sbss;
pDst = (uint8_t*)&_sbss;
for(uint32_t i=0; i<size; i++){
*pDst++=0;
}
//call init function of std. library
__libc_init_array();
//call main()
main();
}