Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
startup_stm32f10x_md.c
00001 /** 00002 ****************************************************************************** 00003 * @file startup_stm32f10x_md.c 00004 * @author Coocox 00005 * @version V1.0 00006 * @date 12/23/2009 00007 * @brief STM32F10x Medium Density Devices Startup code. 00008 * This module performs: 00009 * - Set the initial SP 00010 * - Set the vector table entries with the exceptions ISR address 00011 * - Initialize data and bss 00012 * - Setup the microcontroller system. 00013 * - Call the application's entry point. 00014 * After Reset the Cortex-M3 processor is in Thread mode, 00015 * priority is Privileged, and the Stack is set to Main. 00016 ******************************************************************************* 00017 */ 00018 00019 00020 /*----------Stack Configuration-----------------------------------------------*/ 00021 #define STACK_SIZE 0x00000100 /*!< The Stack size suggest using even number */ 00022 __attribute__ ((section(".co_stack"))) 00023 unsigned long pulStack[STACK_SIZE]; 00024 00025 00026 /*----------Macro definition--------------------------------------------------*/ 00027 #define WEAK __attribute__ ((weak)) 00028 00029 00030 /*----------Declaration of the default fault handlers-------------------------*/ 00031 /* System exception vector handler */ 00032 __attribute__ ((used)) 00033 void WEAK Reset_Handler(void); 00034 void WEAK NMI_Handler(void); 00035 void WEAK HardFault_Handler(void); 00036 void WEAK MemManage_Handler(void); 00037 void WEAK BusFault_Handler(void); 00038 void WEAK UsageFault_Handler(void); 00039 void WEAK SVC_Handler(void); 00040 void WEAK DebugMon_Handler(void); 00041 void WEAK PendSV_Handler(void); 00042 void WEAK SysTick_Handler(void); 00043 void WEAK WWDG_IRQHandler(void); 00044 void WEAK PVD_IRQHandler(void); 00045 void WEAK TAMPER_IRQHandler(void); 00046 void WEAK RTC_IRQHandler(void); 00047 void WEAK FLASH_IRQHandler(void); 00048 void WEAK RCC_IRQHandler(void); 00049 void WEAK EXTI0_IRQHandler(void); 00050 void WEAK EXTI1_IRQHandler(void); 00051 void WEAK EXTI2_IRQHandler(void); 00052 void WEAK EXTI3_IRQHandler(void); 00053 void WEAK EXTI4_IRQHandler(void); 00054 void WEAK DMA1_Channel1_IRQHandler(void); 00055 void WEAK DMA1_Channel2_IRQHandler(void); 00056 void WEAK DMA1_Channel3_IRQHandler(void); 00057 void WEAK DMA1_Channel4_IRQHandler(void); 00058 void WEAK DMA1_Channel5_IRQHandler(void); 00059 void WEAK DMA1_Channel6_IRQHandler(void); 00060 void WEAK DMA1_Channel7_IRQHandler(void); 00061 void WEAK ADC1_2_IRQHandler(void); 00062 void WEAK USB_HP_CAN1_TX_IRQHandler(void); 00063 void WEAK USB_LP_CAN1_RX0_IRQHandler(void); 00064 void WEAK CAN1_RX1_IRQHandler(void); 00065 void WEAK CAN1_SCE_IRQHandler(void); 00066 void WEAK EXTI9_5_IRQHandler(void); 00067 void WEAK TIM1_BRK_IRQHandler(void); 00068 void WEAK TIM1_UP_IRQHandler(void); 00069 void WEAK TIM1_TRG_COM_IRQHandler(void); 00070 void WEAK TIM1_CC_IRQHandler(void); 00071 void WEAK TIM2_IRQHandler(void); 00072 void WEAK TIM3_IRQHandler(void); 00073 void WEAK TIM4_IRQHandler(void); 00074 void WEAK I2C1_EV_IRQHandler(void); 00075 void WEAK I2C1_ER_IRQHandler(void); 00076 void WEAK I2C2_EV_IRQHandler(void); 00077 void WEAK I2C2_ER_IRQHandler(void); 00078 void WEAK SPI1_IRQHandler(void); 00079 void WEAK SPI2_IRQHandler(void); 00080 void WEAK USART1_IRQHandler(void); 00081 void WEAK USART2_IRQHandler(void); 00082 void WEAK USART3_IRQHandler(void); 00083 void WEAK EXTI15_10_IRQHandler(void); 00084 void WEAK RTCAlarm_IRQHandler(void); 00085 void WEAK USBWakeUp_IRQHandler(void); 00086 00087 00088 /*----------Symbols defined in linker script----------------------------------*/ 00089 extern unsigned long _sidata; /*!< Start address for the initialization 00090 values of the .data section. */ 00091 extern unsigned long _sdata; /*!< Start address for the .data section */ 00092 extern unsigned long _edata; /*!< End address for the .data section */ 00093 extern unsigned long _sbss; /*!< Start address for the .bss section */ 00094 extern unsigned long _ebss; /*!< End address for the .bss section */ 00095 extern void _eram; /*!< End address for ram */ 00096 00097 00098 /*----------Function prototypes-----------------------------------------------*/ 00099 extern int main(void); /*!< The entry point for the application. */ 00100 extern void SystemInit(void); /*!< Setup the microcontroller system(CMSIS) */ 00101 void Default_Reset_Handler(void); /*!< Default reset handler */ 00102 static void Default_Handler(void); /*!< Default exception handler */ 00103 00104 00105 /** 00106 *@brief The minimal vector table for a Cortex M3. Note that the proper constructs 00107 * must be placed on this to ensure that it ends up at physical address 00108 * 0x00000000. 00109 */ 00110 __attribute__ ((used,section(".isr_vector"))) 00111 void (* const g_pfnVectors[])(void) = 00112 { 00113 /*----------Core Exceptions-------------------------------------------------*/ 00114 (void *)&pulStack[STACK_SIZE], /*!< The initial stack pointer */ 00115 Reset_Handler, /*!< Reset Handler */ 00116 NMI_Handler, /*!< NMI Handler */ 00117 HardFault_Handler, /*!< Hard Fault Handler */ 00118 MemManage_Handler, /*!< MPU Fault Handler */ 00119 BusFault_Handler, /*!< Bus Fault Handler */ 00120 UsageFault_Handler, /*!< Usage Fault Handler */ 00121 0,0,0,0, /*!< Reserved */ 00122 SVC_Handler, /*!< SVCall Handler */ 00123 DebugMon_Handler, /*!< Debug Monitor Handler */ 00124 0, /*!< Reserved */ 00125 PendSV_Handler, /*!< PendSV Handler */ 00126 SysTick_Handler, /*!< SysTick Handler */ 00127 00128 /*----------External Exceptions---------------------------------------------*/ 00129 WWDG_IRQHandler, /*!< 0: Window Watchdog */ 00130 PVD_IRQHandler, /*!< 1: PVD through EXTI Line detect */ 00131 TAMPER_IRQHandler, /*!< 2: Tamper */ 00132 RTC_IRQHandler, /*!< 3: RTC */ 00133 FLASH_IRQHandler, /*!< 4: Flash */ 00134 RCC_IRQHandler, /*!< 5: RCC */ 00135 EXTI0_IRQHandler, /*!< 6: EXTI Line 0 */ 00136 EXTI1_IRQHandler, /*!< 7: EXTI Line 1 */ 00137 EXTI2_IRQHandler, /*!< 8: EXTI Line 2 */ 00138 EXTI3_IRQHandler, /*!< 9: EXTI Line 3 */ 00139 EXTI4_IRQHandler, /*!< 10: EXTI Line 4 */ 00140 DMA1_Channel1_IRQHandler, /*!< 11: DMA1 Channel 1 */ 00141 DMA1_Channel2_IRQHandler, /*!< 12: DMA1 Channel 2 */ 00142 DMA1_Channel3_IRQHandler, /*!< 13: DMA1 Channel 3 */ 00143 DMA1_Channel4_IRQHandler, /*!< 14: DMA1 Channel 4 */ 00144 DMA1_Channel5_IRQHandler, /*!< 15: DMA1 Channel 5 */ 00145 DMA1_Channel6_IRQHandler, /*!< 16: DMA1 Channel 6 */ 00146 DMA1_Channel7_IRQHandler, /*!< 17: DMA1 Channel 7 */ 00147 ADC1_2_IRQHandler, /*!< 18: ADC1 & ADC2 */ 00148 USB_HP_CAN1_TX_IRQHandler, /*!< 19: USB High Priority or CAN1 TX */ 00149 USB_LP_CAN1_RX0_IRQHandler, /*!< 20: USB Low Priority or CAN1 RX0 */ 00150 CAN1_RX1_IRQHandler, /*!< 21: CAN1 RX1 */ 00151 CAN1_SCE_IRQHandler, /*!< 22: CAN1 SCE */ 00152 EXTI9_5_IRQHandler, /*!< 23: EXTI Line 9..5 */ 00153 TIM1_BRK_IRQHandler, /*!< 24: TIM1 Break */ 00154 TIM1_UP_IRQHandler, /*!< 25: TIM1 Update */ 00155 TIM1_TRG_COM_IRQHandler, /*!< 26: TIM1 Trigger and Commutation */ 00156 TIM1_CC_IRQHandler, /*!< 27: TIM1 Capture Compare */ 00157 TIM2_IRQHandler, /*!< 28: TIM2 */ 00158 TIM3_IRQHandler, /*!< 29: TIM3 */ 00159 TIM4_IRQHandler, /*!< 30: TIM4 */ 00160 I2C1_EV_IRQHandler, /*!< 31: I2C1 Event */ 00161 I2C1_ER_IRQHandler, /*!< 32: I2C1 Error */ 00162 I2C2_EV_IRQHandler, /*!< 33: I2C2 Event */ 00163 I2C2_ER_IRQHandler, /*!< 34: I2C2 Error */ 00164 SPI1_IRQHandler, /*!< 35: SPI1 */ 00165 SPI2_IRQHandler, /*!< 36: SPI2 */ 00166 USART1_IRQHandler, /*!< 37: USART1 */ 00167 USART2_IRQHandler, /*!< 38: USART2 */ 00168 USART3_IRQHandler, /*!< 39: USART3 */ 00169 EXTI15_10_IRQHandler, /*!< 40: EXTI Line 15..10 */ 00170 RTCAlarm_IRQHandler, /*!< 41: RTC Alarm through EXTI Line */ 00171 USBWakeUp_IRQHandler, /*!< 42: USB Wakeup from suspend */ 00172 0,0,0,0,0,0,0, /*!< Reserved */ 00173 (void *)0xF108F85F /*!< Boot in RAM mode */ 00174 }; 00175 00176 00177 /** 00178 * @brief This is the code that gets called when the processor first 00179 * starts execution following a reset event. Only the absolutely 00180 * necessary set is performed, after which the application 00181 * supplied main() routine is called. 00182 * @param None 00183 * @retval None 00184 */ 00185 void Default_Reset_Handler(void) 00186 { 00187 /* Initialize data and bss */ 00188 unsigned long *pulSrc, *pulDest; 00189 00190 /* Copy the data segment initializers from flash to SRAM */ 00191 pulSrc = &_sidata; 00192 00193 for(pulDest = &_sdata; pulDest < &_edata; ) 00194 { 00195 *(pulDest++) = *(pulSrc++); 00196 } 00197 00198 /* Zero fill the bss segment. This is done with inline assembly since this 00199 will clear the value of pulDest if it is not kept in a register. */ 00200 __asm(" ldr r0, =_sbss\n" 00201 " ldr r1, =_ebss\n" 00202 " mov r2, #0\n" 00203 " .thumb_func\n" 00204 "zero_loop:\n" 00205 " cmp r0, r1\n" 00206 " it lt\n" 00207 " strlt r2, [r0], #4\n" 00208 " blt zero_loop"); 00209 00210 /* Setup the microcontroller system. */ 00211 SystemInit(); 00212 00213 /* Call the application's entry point.*/ 00214 main(); 00215 } 00216 00217 /** 00218 *@brief Provide weak aliases for each Exception handler to the Default_Handler. 00219 * As they are weak aliases, any function with the same name will override 00220 * this definition. 00221 */ 00222 #pragma weak Reset_Handler = Default_Reset_Handler 00223 #pragma weak NMI_Handler = Default_Handler 00224 #pragma weak HardFault_Handler = Default_Handler 00225 #pragma weak MemManage_Handler = Default_Handler 00226 #pragma weak BusFault_Handler = Default_Handler 00227 #pragma weak UsageFault_Handler = Default_Handler 00228 #pragma weak SVC_Handler = Default_Handler 00229 #pragma weak DebugMon_Handler = Default_Handler 00230 #pragma weak PendSV_Handler = Default_Handler 00231 #pragma weak SysTick_Handler = Default_Handler 00232 #pragma weak WWDG_IRQHandler = Default_Handler 00233 #pragma weak PVD_IRQHandler = Default_Handler 00234 #pragma weak TAMPER_IRQHandler = Default_Handler 00235 #pragma weak RTC_IRQHandler = Default_Handler 00236 #pragma weak FLASH_IRQHandler = Default_Handler 00237 #pragma weak RCC_IRQHandler = Default_Handler 00238 #pragma weak EXTI0_IRQHandler = Default_Handler 00239 #pragma weak EXTI1_IRQHandler = Default_Handler 00240 #pragma weak EXTI2_IRQHandler = Default_Handler 00241 #pragma weak EXTI3_IRQHandler = Default_Handler 00242 #pragma weak EXTI4_IRQHandler = Default_Handler 00243 #pragma weak DMA1_Channel1_IRQHandler = Default_Handler 00244 #pragma weak DMA1_Channel2_IRQHandler = Default_Handler 00245 #pragma weak DMA1_Channel3_IRQHandler = Default_Handler 00246 #pragma weak DMA1_Channel4_IRQHandler = Default_Handler 00247 #pragma weak DMA1_Channel5_IRQHandler = Default_Handler 00248 #pragma weak DMA1_Channel6_IRQHandler = Default_Handler 00249 #pragma weak DMA1_Channel7_IRQHandler = Default_Handler 00250 #pragma weak ADC1_2_IRQHandler = Default_Handler 00251 #pragma weak USB_HP_CAN1_TX_IRQHandler = Default_Handler 00252 #pragma weak USB_LP_CAN1_RX0_IRQHandler = Default_Handler 00253 #pragma weak CAN1_RX1_IRQHandler = Default_Handler 00254 #pragma weak CAN1_SCE_IRQHandler = Default_Handler 00255 #pragma weak EXTI9_5_IRQHandler = Default_Handler 00256 #pragma weak TIM1_BRK_IRQHandler = Default_Handler 00257 #pragma weak TIM1_UP_IRQHandler = Default_Handler 00258 #pragma weak TIM1_TRG_COM_IRQHandler = Default_Handler 00259 #pragma weak TIM1_CC_IRQHandler = Default_Handler 00260 #pragma weak TIM2_IRQHandler = Default_Handler 00261 #pragma weak TIM3_IRQHandler = Default_Handler 00262 #pragma weak TIM4_IRQHandler = Default_Handler 00263 #pragma weak I2C1_EV_IRQHandler = Default_Handler 00264 #pragma weak I2C1_ER_IRQHandler = Default_Handler 00265 #pragma weak I2C2_EV_IRQHandler = Default_Handler 00266 #pragma weak I2C2_ER_IRQHandler = Default_Handler 00267 #pragma weak SPI1_IRQHandler = Default_Handler 00268 #pragma weak SPI2_IRQHandler = Default_Handler 00269 #pragma weak USART1_IRQHandler = Default_Handler 00270 #pragma weak USART2_IRQHandler = Default_Handler 00271 #pragma weak USART3_IRQHandler = Default_Handler 00272 #pragma weak EXTI15_10_IRQHandler = Default_Handler 00273 #pragma weak RTCAlarm_IRQHandler = Default_Handler 00274 #pragma weak USBWakeUp_IRQHandler = Default_Handler 00275 00276 00277 /** 00278 * @brief This is the code that gets called when the processor receives an 00279 * unexpected interrupt. This simply enters an infinite loop, 00280 * preserving the system state for examination by a debugger. 00281 * @param None 00282 * @retval None 00283 */ 00284 static void Default_Handler(void) 00285 { 00286 /* Go into an infinite loop. */ 00287 while (1) 00288 { 00289 } 00290 } 00291 00292 /*********************** (C) COPYRIGHT 2009 Coocox ************END OF FILE*****/
Generated on Tue Jul 12 2022 20:45:31 by
1.7.2