Mercurial > ~darius > hgwebdir.cgi > stm32test
comparison startup_stm32f10x_md_mthomas.c @ 0:c59513fd84fb
Initial commit of STM32 test code.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Mon, 03 Oct 2011 21:19:15 +1030 |
parents | |
children | 74e9b3baac1e |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c59513fd84fb |
---|---|
1 /** | |
2 ****************************************************************************** | |
3 * @file startup_stm32f10x_md.c | |
4 * @author MCD Application Team, modified by Martin Thomas | |
5 * @version V3.0.0-mthomas4 | |
6 * @date 19. Mar. 2010 | |
7 * @brief STM32F10x Medium Density Devices vector table for GNU toolchain. | |
8 * This module performs: | |
9 * - Set the initial SP | |
10 * - Set the initial PC == Reset_Handler, | |
11 * - Set the vector table entries with the exceptions ISR address | |
12 * - Configure the clock system | |
13 * - Branches to main in the C library (which eventually | |
14 * calls main()). | |
15 * After Reset the Cortex-M3 processor is in Thread mode, | |
16 * priority is Privileged, and the Stack is set to Main. | |
17 ******************************************************************************* | |
18 * @copy | |
19 * | |
20 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS | |
21 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE | |
22 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY | |
23 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING | |
24 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE | |
25 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. | |
26 * | |
27 * <h2><center>© COPYRIGHT 2009 STMicroelectronics, 2010 M.Thomas</center></h2> | |
28 */ | |
29 | |
30 /* Modified by Martin Thomas | |
31 - to take VECT_TAB_RAM setting into account, also see the linker-script | |
32 - to avoid warning "ISO C forbids initialization between function pointer and 'void *'". | |
33 - added optional startup-delay to avoid unwanted operations while connecting with | |
34 debugger/programmer | |
35 - tested with the GNU arm-eabi toolchain as in CS G++ lite Q1/2009-161 | |
36 - minor modification in .data copy to avoid copy while "run from RAM" | |
37 during debugging | |
38 */ | |
39 | |
40 /* Includes ------------------------------------------------------------------*/ | |
41 /* Private typedef -----------------------------------------------------------*/ | |
42 /* Private typedef -----------------------------------------------------------*/ | |
43 typedef void( *const intfunc )( void ); | |
44 | |
45 /* Private define ------------------------------------------------------------*/ | |
46 #define WEAK __attribute__ ((weak)) | |
47 | |
48 /* Private macro -------------------------------------------------------------*/ | |
49 extern unsigned long _etext; | |
50 /* start address for the initialization values of the .data section. | |
51 defined in linker script */ | |
52 extern unsigned long _sidata; | |
53 | |
54 /* start address for the .data section. defined in linker script */ | |
55 extern unsigned long _sdata; | |
56 | |
57 /* end address for the .data section. defined in linker script */ | |
58 extern unsigned long _edata; | |
59 | |
60 /* start address for the .bss section. defined in linker script */ | |
61 extern unsigned long _sbss; | |
62 | |
63 /* end address for the .bss section. defined in linker script */ | |
64 extern unsigned long _ebss; | |
65 | |
66 /* init value for the stack pointer. defined in linker script */ | |
67 extern unsigned long _estack; | |
68 | |
69 /* Private variables ---------------------------------------------------------*/ | |
70 | |
71 /* Private function prototypes -----------------------------------------------*/ | |
72 void Reset_Handler(void) __attribute__((__interrupt__)); | |
73 void __Init_Data_and_BSS(void); | |
74 void Default_Handler(void); | |
75 | |
76 /* External function prototypes ----------------------------------------------*/ | |
77 extern int main(void); /* Application's main function */ | |
78 extern void SystemInit(void); /* STM's system init */ | |
79 extern void __libc_init_array(void); /* calls CTORS of static objects */ | |
80 | |
81 | |
82 /******************************************************************************* | |
83 * | |
84 * Forward declaration of the default fault handlers. | |
85 * | |
86 *******************************************************************************/ | |
87 //mthomas void WEAK Reset_Handler(void); | |
88 void WEAK NMI_Handler(void); | |
89 void WEAK HardFault_Handler(void); | |
90 void WEAK MemManage_Handler(void); | |
91 void WEAK BusFault_Handler(void); | |
92 void WEAK UsageFault_Handler(void); | |
93 //mthomas void WEAK MemManage_Handler(void); | |
94 void WEAK SVC_Handler(void); | |
95 void WEAK DebugMon_Handler(void); | |
96 void WEAK PendSV_Handler(void); | |
97 void WEAK SysTick_Handler(void); | |
98 | |
99 /* External Interrupts */ | |
100 void WEAK WWDG_IRQHandler(void); | |
101 void WEAK PVD_IRQHandler(void); | |
102 void WEAK TAMPER_IRQHandler(void); | |
103 void WEAK RTC_IRQHandler(void); | |
104 void WEAK FLASH_IRQHandler(void); | |
105 void WEAK RCC_IRQHandler(void); | |
106 void WEAK EXTI0_IRQHandler(void); | |
107 void WEAK EXTI1_IRQHandler(void); | |
108 void WEAK EXTI2_IRQHandler(void); | |
109 void WEAK EXTI3_IRQHandler(void); | |
110 void WEAK EXTI4_IRQHandler(void); | |
111 void WEAK DMA1_Channel1_IRQHandler(void); | |
112 void WEAK DMA1_Channel2_IRQHandler(void); | |
113 void WEAK DMA1_Channel3_IRQHandler(void); | |
114 void WEAK DMA1_Channel4_IRQHandler(void); | |
115 void WEAK DMA1_Channel5_IRQHandler(void); | |
116 void WEAK DMA1_Channel6_IRQHandler(void); | |
117 void WEAK DMA1_Channel7_IRQHandler(void); | |
118 void WEAK ADC1_2_IRQHandler(void); | |
119 void WEAK USB_HP_CAN1_TX_IRQHandler(void); | |
120 void WEAK USB_LP_CAN1_RX0_IRQHandler(void); | |
121 void WEAK CAN1_RX1_IRQHandler(void); | |
122 void WEAK CAN1_SCE_IRQHandler(void); | |
123 void WEAK EXTI9_5_IRQHandler(void); | |
124 void WEAK TIM1_BRK_IRQHandler(void); | |
125 void WEAK TIM1_UP_IRQHandler(void); | |
126 void WEAK TIM1_TRG_COM_IRQHandler(void); | |
127 void WEAK TIM1_CC_IRQHandler(void); | |
128 void WEAK TIM2_IRQHandler(void); | |
129 void WEAK TIM3_IRQHandler(void); | |
130 void WEAK TIM4_IRQHandler(void); | |
131 void WEAK I2C1_EV_IRQHandler(void); | |
132 void WEAK I2C1_ER_IRQHandler(void); | |
133 void WEAK I2C2_EV_IRQHandler(void); | |
134 void WEAK I2C2_ER_IRQHandler(void); | |
135 void WEAK SPI1_IRQHandler(void); | |
136 void WEAK SPI2_IRQHandler(void); | |
137 void WEAK USART1_IRQHandler(void); | |
138 void WEAK USART2_IRQHandler(void); | |
139 void WEAK USART3_IRQHandler(void); | |
140 void WEAK EXTI15_10_IRQHandler(void); | |
141 void WEAK RTCAlarm_IRQHandler(void); | |
142 void WEAK USBWakeUp_IRQHandler(void); | |
143 | |
144 /* Private functions ---------------------------------------------------------*/ | |
145 /****************************************************************************** | |
146 * | |
147 * mthomas: If been built with VECT_TAB_RAM this creates two tables: | |
148 * (1) a minimal table (stack-pointer, reset-vector) used during startup | |
149 * before relocation of the vector table using SCB_VTOR | |
150 * (2) a full table which is copied to RAM and used after vector relocation | |
151 * (NVIC_SetVectorTable) | |
152 * If been built without VECT_TAB_RAM the following comment from STM is valid: | |
153 * The minimal vector table for a Cortex M3. Note that the proper constructs | |
154 * must be placed on this to ensure that it ends up at physical address | |
155 * 0x0000.0000. | |
156 * | |
157 ******************************************************************************/ | |
158 | |
159 #ifdef VECT_TAB_RAM | |
160 __attribute__ ((section(".isr_vectorsflash"))) | |
161 void (* const g_pfnVectorsStartup[])(void) = | |
162 { | |
163 (intfunc)((unsigned long)&_estack), /* The initial stack pointer during startup */ | |
164 Reset_Handler, /* The reset handler during startup */ | |
165 HardFault_Handler, /* Hard Fault Handler */ | |
166 MemManage_Handler, /* MPU Fault Handler */ | |
167 BusFault_Handler, /* Bus Fault Handler */ | |
168 UsageFault_Handler, /* Usage Fault Handler */ | |
169 }; | |
170 __attribute__ ((section(".isr_vectorsram"))) | |
171 void (* g_pfnVectors[])(void) = | |
172 #else /* VECT_TAB_RAM */ | |
173 __attribute__ ((section(".isr_vectorsflash"))) | |
174 void (* const g_pfnVectors[])(void) = | |
175 #endif /* VECT_TAB_RAM */ | |
176 { | |
177 (intfunc)((unsigned long)&_estack), /* The stack pointer after relocation */ | |
178 Reset_Handler, /* Reset Handler */ | |
179 NMI_Handler, /* NMI Handler */ | |
180 HardFault_Handler, /* Hard Fault Handler */ | |
181 MemManage_Handler, /* MPU Fault Handler */ | |
182 BusFault_Handler, /* Bus Fault Handler */ | |
183 UsageFault_Handler, /* Usage Fault Handler */ | |
184 0, /* Reserved */ | |
185 0, /* Reserved */ | |
186 0, /* Reserved */ | |
187 0, /* Reserved */ | |
188 SVC_Handler, /* SVCall Handler */ | |
189 DebugMon_Handler, /* Debug Monitor Handler */ | |
190 0, /* Reserved */ | |
191 PendSV_Handler, /* PendSV Handler */ | |
192 SysTick_Handler, /* SysTick Handler */ | |
193 | |
194 /* External Interrupts */ | |
195 WWDG_IRQHandler, /* Window Watchdog */ | |
196 PVD_IRQHandler, /* PVD through EXTI Line detect */ | |
197 TAMPER_IRQHandler, /* Tamper */ | |
198 RTC_IRQHandler, /* RTC */ | |
199 FLASH_IRQHandler, /* Flash */ | |
200 RCC_IRQHandler, /* RCC */ | |
201 EXTI0_IRQHandler, /* EXTI Line 0 */ | |
202 EXTI1_IRQHandler, /* EXTI Line 1 */ | |
203 EXTI2_IRQHandler, /* EXTI Line 2 */ | |
204 EXTI3_IRQHandler, /* EXTI Line 3 */ | |
205 EXTI4_IRQHandler, /* EXTI Line 4 */ | |
206 DMA1_Channel1_IRQHandler, /* DMA1 Channel 1 */ | |
207 DMA1_Channel2_IRQHandler, /* DMA1 Channel 2 */ | |
208 DMA1_Channel3_IRQHandler, /* DMA1 Channel 3 */ | |
209 DMA1_Channel4_IRQHandler, /* DMA1 Channel 4 */ | |
210 DMA1_Channel5_IRQHandler, /* DMA1 Channel 5 */ | |
211 DMA1_Channel6_IRQHandler, /* DMA1 Channel 6 */ | |
212 DMA1_Channel7_IRQHandler, /* DMA1 Channel 7 */ | |
213 ADC1_2_IRQHandler, /* ADC1 & ADC2 */ | |
214 USB_HP_CAN1_TX_IRQHandler, /* USB High Priority or CAN1 TX */ | |
215 USB_LP_CAN1_RX0_IRQHandler, /* USB Low Priority or CAN1 RX0 */ | |
216 CAN1_RX1_IRQHandler, /* CAN1 RX1 */ | |
217 CAN1_SCE_IRQHandler, /* CAN1 SCE */ | |
218 EXTI9_5_IRQHandler, /* EXTI Line 9..5 */ | |
219 TIM1_BRK_IRQHandler, /* TIM1 Break */ | |
220 TIM1_UP_IRQHandler, /* TIM1 Update */ | |
221 TIM1_TRG_COM_IRQHandler, /* TIM1 Trigger and Commutation */ | |
222 TIM1_CC_IRQHandler, /* TIM1 Capture Compare */ | |
223 TIM2_IRQHandler, /* TIM2 */ | |
224 TIM3_IRQHandler, /* TIM3 */ | |
225 TIM4_IRQHandler, /* TIM4 */ | |
226 I2C1_EV_IRQHandler, /* I2C1 Event */ | |
227 I2C1_ER_IRQHandler, /* I2C1 Error */ | |
228 I2C2_EV_IRQHandler, /* I2C2 Event */ | |
229 I2C2_ER_IRQHandler, /* I2C2 Error */ | |
230 SPI1_IRQHandler, /* SPI1 */ | |
231 SPI2_IRQHandler, /* SPI2 */ | |
232 USART1_IRQHandler, /* USART1 */ | |
233 USART2_IRQHandler, /* USART2 */ | |
234 USART3_IRQHandler, /* USART3 */ | |
235 EXTI15_10_IRQHandler, /* EXTI Line 15..10 */ | |
236 RTCAlarm_IRQHandler, /* RTC Alarm through EXTI Line */ | |
237 USBWakeUp_IRQHandler, /* USB Wakeup from suspend */ | |
238 0,0,0,0,0,0,0, | |
239 (intfunc)0xF108F85F /* @0x108. This is for boot in RAM mode for | |
240 STM32F10x Medium Density devices. */ | |
241 }; | |
242 | |
243 /** | |
244 * @brief This is the code that gets called when the processor first | |
245 * starts execution following a reset event. Only the absolutely | |
246 * necessary set is performed, after which the application | |
247 * supplied main() routine is called. | |
248 * @param None | |
249 * @retval : None | |
250 */ | |
251 | |
252 void Reset_Handler(void) | |
253 { | |
254 | |
255 #ifdef STARTUP_DELAY | |
256 volatile unsigned long i; | |
257 for (i=0;i<500000;i++) { ; } | |
258 #endif | |
259 | |
260 /* Initialize data and bss */ | |
261 __Init_Data_and_BSS(); | |
262 | |
263 /* Call CTORS of static objects, not needed for "pure C": */ | |
264 /* __libc_init_array(); */ | |
265 /* if ( __libc_init_array ) | |
266 __libc_init_array() | |
267 } */ | |
268 | |
269 /* Setup the microcontroller system. Initialize the Embedded Flash Interface, | |
270 initialize the PLL and update the SystemFrequency variable. */ | |
271 SystemInit(); | |
272 | |
273 /* Call the application's entry point.*/ | |
274 main(); | |
275 | |
276 while(1) { ; } | |
277 } | |
278 | |
279 /** | |
280 * @brief initializes data and bss sections | |
281 * @param None | |
282 * @retval : None | |
283 */ | |
284 | |
285 void __Init_Data_and_BSS(void) | |
286 { | |
287 unsigned long *pulSrc, *pulDest; | |
288 | |
289 /* Copy the data segment initializers from flash to SRAM */ | |
290 pulSrc = &_sidata; | |
291 pulDest = &_sdata; | |
292 if ( pulSrc != pulDest ) | |
293 { | |
294 for(; pulDest < &_edata; ) | |
295 { | |
296 *(pulDest++) = *(pulSrc++); | |
297 } | |
298 } | |
299 /* Zero fill the bss segment. */ | |
300 for(pulDest = &_sbss; pulDest < &_ebss; ) | |
301 { | |
302 *(pulDest++) = 0; | |
303 } | |
304 } | |
305 | |
306 /******************************************************************************* | |
307 * | |
308 * Provide weak aliases for each Exception handler to the Default_Handler. | |
309 * As they are weak aliases, any function with the same name will override | |
310 * this definition. | |
311 * | |
312 *******************************************************************************/ | |
313 #pragma weak MMI_Handler = Default_Handler | |
314 #pragma weak MemManage_Handler = Default_Handler | |
315 #pragma weak BusFault_Handler = Default_Handler | |
316 #pragma weak UsageFault_Handler = Default_Handler | |
317 #pragma weak SVC_Handler = Default_Handler | |
318 #pragma weak DebugMon_Handler = Default_Handler | |
319 #pragma weak PendSV_Handler = Default_Handler | |
320 #pragma weak SysTick_Handler = Default_Handler | |
321 #pragma weak WWDG_IRQHandler = Default_Handler | |
322 #pragma weak PVD_IRQHandler = Default_Handler | |
323 #pragma weak TAMPER_IRQHandler = Default_Handler | |
324 #pragma weak RTC_IRQHandler = Default_Handler | |
325 #pragma weak FLASH_IRQHandler = Default_Handler | |
326 #pragma weak RCC_IRQHandler = Default_Handler | |
327 #pragma weak EXTI0_IRQHandler = Default_Handler | |
328 #pragma weak EXTI1_IRQHandler = Default_Handler | |
329 #pragma weak EXTI2_IRQHandler = Default_Handler | |
330 #pragma weak EXTI3_IRQHandler = Default_Handler | |
331 #pragma weak EXTI4_IRQHandler = Default_Handler | |
332 #pragma weak DMA1_Channel1_IRQHandler = Default_Handler | |
333 #pragma weak DMA1_Channel2_IRQHandler = Default_Handler | |
334 #pragma weak DMA1_Channel3_IRQHandler = Default_Handler | |
335 #pragma weak DMA1_Channel4_IRQHandler = Default_Handler | |
336 #pragma weak DMA1_Channel5_IRQHandler = Default_Handler | |
337 #pragma weak DMA1_Channel6_IRQHandler = Default_Handler | |
338 #pragma weak DMA1_Channel7_IRQHandler = Default_Handler | |
339 #pragma weak ADC1_2_IRQHandler = Default_Handler | |
340 #pragma weak USB_HP_CAN1_TX_IRQHandler = Default_Handler | |
341 #pragma weak USB_LP_CAN1_RX0_IRQHandler = Default_Handler | |
342 #pragma weak CAN1_RX1_IRQHandler = Default_Handler | |
343 #pragma weak CAN1_SCE_IRQHandler = Default_Handler | |
344 #pragma weak EXTI9_5_IRQHandler = Default_Handler | |
345 #pragma weak TIM1_BRK_IRQHandler = Default_Handler | |
346 #pragma weak TIM1_UP_IRQHandler = Default_Handler | |
347 #pragma weak TIM1_TRG_COM_IRQHandler = Default_Handler | |
348 #pragma weak TIM1_CC_IRQHandler = Default_Handler | |
349 #pragma weak TIM2_IRQHandler = Default_Handler | |
350 #pragma weak TIM3_IRQHandler = Default_Handler | |
351 #pragma weak TIM4_IRQHandler = Default_Handler | |
352 #pragma weak I2C1_EV_IRQHandler = Default_Handler | |
353 #pragma weak I2C1_ER_IRQHandler = Default_Handler | |
354 #pragma weak I2C2_EV_IRQHandler = Default_Handler | |
355 #pragma weak I2C2_ER_IRQHandler = Default_Handler | |
356 #pragma weak SPI1_IRQHandler = Default_Handler | |
357 #pragma weak SPI2_IRQHandler = Default_Handler | |
358 #pragma weak USART1_IRQHandler = Default_Handler | |
359 #pragma weak USART2_IRQHandler = Default_Handler | |
360 #pragma weak USART3_IRQHandler = Default_Handler | |
361 #pragma weak EXTI15_10_IRQHandler = Default_Handler | |
362 #pragma weak RTCAlarm_IRQHandler = Default_Handler | |
363 #pragma weak USBWakeUp_IRQHandler = Default_Handler | |
364 | |
365 /** | |
366 * @brief This is the code that gets called when the processor receives an | |
367 * unexpected interrupt. This simply enters an infinite loop, preserving | |
368 * the system state for examination by a debugger. | |
369 * | |
370 * @param None | |
371 * @retval : None | |
372 */ | |
373 | |
374 void Default_Handler(void) | |
375 { | |
376 /* Go into an infinite loop. */ | |
377 while (1) | |
378 { | |
379 } | |
380 } | |
381 | |
382 /******************* (C) COPYRIGHT 2009 STMicroelectronics *****END OF FILE****/ |