STM32F103启动分析

A: 启动文件中调用 Sys_Init() 函数, 设置了系统时钟, 但外设时钟为节省功耗而默认关闭, 故而在使用外设之时需要手动开启对应的外设时钟:
【STM32F103启动分析】RCC_APB1PeriphClockCmd()
RCC_APB2PeriphClockCmd()
附录:
start_up_stm32f10x_hd.s
; ******************** (C) COPYRIGHT 2011 STMicroelectronics ********************
; * File Name: startup_stm32f10x_hd.s
; * Author: MCD Application Team
; * Version: V3.5.0
; * Date: 11-March-2011
; * Description: STM32F10x High Density Devices vector table for MDK-ARM
; *toolchain.
; *This module performs:
; *- Set the initial SP
; *- Set the initial PC == Reset_Handler
; *- Set the vector table entries with the exceptions ISR address
; *- Configure the clock system and also configure the external
; *SRAM mounted on STM3210E-EVAL board to be used as data
; *memory (optional, to be enabled by user)
; *- Branches to __main in the C library (which eventually
; *calls main()).
; *After Reset the CortexM3 processor is in Thread mode,
; *priority is Privileged, and the Stack is set to Main.
; * <<< Use Configuration Wizard in Context Menu >>>
; *******************************************************************************
; THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
; WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
; AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
; INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
; CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
; INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
; *******************************************************************************


; Amount of memory (in bytes) allocated for Stack
; Tailor this value to your application needs
; Stack Configuration
; Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
;


Stack_SizeEQU0x00000400


AREASTACK, NOINIT, READWRITE, ALIGN=3
Stack_MemSPACEStack_Size
__initial_sp

; Heap Configuration
; Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
;


Heap_SizeEQU0x00000200


AREAHEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
Heap_MemSPACEHeap_Size
__heap_limit


PRESERVE8
THUMB




; Vector Table Mapped to Address 0 at Reset
AREARESET, DATA, READONLY
EXPORT__Vectors
EXPORT__Vectors_End
EXPORT__Vectors_Size


__VectorsDCD__initial_sp; Top of Stack
DCDReset_Handler; Reset Handler
DCDNMI_Handler; NMI Handler
DCDHardFault_Handler; Hard Fault Handler
DCDMemManage_Handler; MPU Fault Handler
DCDBusFault_Handler; Bus Fault Handler
DCDUsageFault_Handler; Usage Fault Handler
DCD0; Reserved
DCD0; Reserved
DCD0; Reserved
DCD0; Reserved
DCDSVC_Handler; SVCall Handler
DCDDebugMon_Handler; Debug Monitor Handler
DCD0; Reserved
DCDPendSV_Handler; PendSV Handler
DCDSysTick_Handler; SysTick Handler


; External Interrupts
DCDWWDG_IRQHandler; Window Watchdog
DCDPVD_IRQHandler; PVD through EXTI Line detect
DCDTAMPER_IRQHandler; Tamper
DCDRTC_IRQHandler; RTC
DCDFLASH_IRQHandler; Flash
DCDRCC_IRQHandler; RCC
DCDEXTI0_IRQHandler; EXTI Line 0
DCDEXTI1_IRQHandler; EXTI Line 1
DCDEXTI2_IRQHandler; EXTI Line 2
DCDEXTI3_IRQHandler; EXTI Line 3
DCDEXTI4_IRQHandler; EXTI Line 4
DCDDMA1_Channel1_IRQHandler; DMA1 Channel 1
DCDDMA1_Channel2_IRQHandler; DMA1 Channel 2
DCDDMA1_Channel3_IRQHandler; DMA1 Channel 3
DCDDMA1_Channel4_IRQHandler; DMA1 Channel 4
DCDDMA1_Channel5_IRQHandler; DMA1 Channel 5
DCDDMA1_Channel6_IRQHandler; DMA1 Channel 6
DCDDMA1_Channel7_IRQHandler; DMA1 Channel 7
DCDADC1_2_IRQHandler; ADC1 & ADC2
DCDUSB_HP_CAN1_TX_IRQHandler; USB High Priority or CAN1 TX
DCDUSB_LP_CAN1_RX0_IRQHandler ; USB LowPriority or CAN1 RX0
DCDCAN1_RX1_IRQHandler; CAN1 RX1
DCDCAN1_SCE_IRQHandler; CAN1 SCE
DCDEXTI9_5_IRQHandler; EXTI Line 9..5
DCDTIM1_BRK_IRQHandler; TIM1 Break
DCDTIM1_UP_IRQHandler; TIM1 Update
DCDTIM1_TRG_COM_IRQHandler; TIM1 Trigger and Commutation
DCDTIM1_CC_IRQHandler; TIM1 Capture Compare
DCDTIM2_IRQHandler; TIM2
DCDTIM3_IRQHandler; TIM3
DCDTIM4_IRQHandler; TIM4
DCDI2C1_EV_IRQHandler; I2C1 Event
DCDI2C1_ER_IRQHandler; I2C1 Error
DCDI2C2_EV_IRQHandler; I2C2 Event
DCDI2C2_ER_IRQHandler; I2C2 Error
DCDSPI1_IRQHandler; SPI1
DCDSPI2_IRQHandler; SPI2
DCDUSART1_IRQHandler; USART1
DCDUSART2_IRQHandler; USART2
DCDUSART3_IRQHandler; USART3
DCDEXTI15_10_IRQHandler; EXTI Line 15..10
DCDRTCAlarm_IRQHandler; RTC Alarm through EXTI Line
DCDUSBWakeUp_IRQHandler; USB Wakeup from suspend
DCDTIM8_BRK_IRQHandler; TIM8 Break
DCDTIM8_UP_IRQHandler; TIM8 Update
DCDTIM8_TRG_COM_IRQHandler; TIM8 Trigger and Commutation
DCDTIM8_CC_IRQHandler; TIM8 Capture Compare
DCDADC3_IRQHandler; ADC3
DCDFSMC_IRQHandler; FSMC
DCDSDIO_IRQHandler; SDIO
DCDTIM5_IRQHandler; TIM5
DCDSPI3_IRQHandler; SPI3
DCDUART4_IRQHandler; UART4
DCDUART5_IRQHandler; UART5
DCDTIM6_IRQHandler; TIM6
DCDTIM7_IRQHandler; TIM7
DCDDMA2_Channel1_IRQHandler; DMA2 Channel1
DCDDMA2_Channel2_IRQHandler; DMA2 Channel2
DCDDMA2_Channel3_IRQHandler; DMA2 Channel3
DCDDMA2_Channel4_5_IRQHandler ; DMA2 Channel4 & Channel5
__Vectors_End


__Vectors_SizeEQU__Vectors_End - __Vectors


AREA|.text|, CODE, READONLY

; Reset handler
Reset_HandlerPROC
EXPORTReset_Handler[WEAK]
IMPORT__main
IMPORTSystemInit
LDRR0, =SystemInit
BLXR0
LDRR0, =__main
BXR0
ENDP

; Dummy Exception Handlers (infinite loops which can be modified)


NMI_HandlerPROC
EXPORTNMI_Handler[WEAK]
B.
ENDP
HardFault_Handler\
PROC
EXPORTHardFault_Handler[WEAK]
B.
ENDP
MemManage_Handler\
PROC
EXPORTMemManage_Handler[WEAK]
B.
ENDP
BusFault_Handler\
PROC
EXPORTBusFault_Handler[WEAK]
B.
ENDP
UsageFault_Handler\
PROC
EXPORTUsageFault_Handler[WEAK]
B.
ENDP
SVC_HandlerPROC
EXPORTSVC_Handler[WEAK]
B.
ENDP
DebugMon_Handler\
PROC
EXPORTDebugMon_Handler[WEAK]
B.
ENDP
PendSV_HandlerPROC
EXPORTPendSV_Handler[WEAK]
B.
ENDP
SysTick_Handler PROC
EXPORTSysTick_Handler[WEAK]
B.
ENDP


Default_Handler PROC


EXPORTWWDG_IRQHandler[WEAK]
EXPORTPVD_IRQHandler[WEAK]
EXPORTTAMPER_IRQHandler[WEAK]
EXPORTRTC_IRQHandler[WEAK]
EXPORTFLASH_IRQHandler[WEAK]
EXPORTRCC_IRQHandler[WEAK]
EXPORTEXTI0_IRQHandler[WEAK]
EXPORTEXTI1_IRQHandler[WEAK]
EXPORTEXTI2_IRQHandler[WEAK]
EXPORTEXTI3_IRQHandler[WEAK]
EXPORTEXTI4_IRQHandler[WEAK]
EXPORTDMA1_Channel1_IRQHandler[WEAK]
EXPORTDMA1_Channel2_IRQHandler[WEAK]
EXPORTDMA1_Channel3_IRQHandler[WEAK]
EXPORTDMA1_Channel4_IRQHandler[WEAK]
EXPORTDMA1_Channel5_IRQHandler[WEAK]
EXPORTDMA1_Channel6_IRQHandler[WEAK]
EXPORTDMA1_Channel7_IRQHandler[WEAK]
EXPORTADC1_2_IRQHandler[WEAK]
EXPORTUSB_HP_CAN1_TX_IRQHandler[WEAK]
EXPORTUSB_LP_CAN1_RX0_IRQHandler [WEAK]
EXPORTCAN1_RX1_IRQHandler[WEAK]
EXPORTCAN1_SCE_IRQHandler[WEAK]
EXPORTEXTI9_5_IRQHandler[WEAK]
EXPORTTIM1_BRK_IRQHandler[WEAK]
EXPORTTIM1_UP_IRQHandler[WEAK]
EXPORTTIM1_TRG_COM_IRQHandler[WEAK]
EXPORTTIM1_CC_IRQHandler[WEAK]
EXPORTTIM2_IRQHandler[WEAK]
EXPORTTIM3_IRQHandler[WEAK]
EXPORTTIM4_IRQHandler[WEAK]
EXPORTI2C1_EV_IRQHandler[WEAK]
EXPORTI2C1_ER_IRQHandler[WEAK]
EXPORTI2C2_EV_IRQHandler[WEAK]
EXPORTI2C2_ER_IRQHandler[WEAK]
EXPORTSPI1_IRQHandler[WEAK]
EXPORTSPI2_IRQHandler[WEAK]
EXPORTUSART1_IRQHandler[WEAK]
EXPORTUSART2_IRQHandler[WEAK]
EXPORTUSART3_IRQHandler[WEAK]
EXPORTEXTI15_10_IRQHandler[WEAK]
EXPORTRTCAlarm_IRQHandler[WEAK]
EXPORTUSBWakeUp_IRQHandler[WEAK]
EXPORTTIM8_BRK_IRQHandler[WEAK]
EXPORTTIM8_UP_IRQHandler[WEAK]
EXPORTTIM8_TRG_COM_IRQHandler[WEAK]
EXPORTTIM8_CC_IRQHandler[WEAK]
EXPORTADC3_IRQHandler[WEAK]
EXPORTFSMC_IRQHandler[WEAK]
EXPORTSDIO_IRQHandler[WEAK]
EXPORTTIM5_IRQHandler[WEAK]
EXPORTSPI3_IRQHandler[WEAK]
EXPORTUART4_IRQHandler[WEAK]
EXPORTUART5_IRQHandler[WEAK]
EXPORTTIM6_IRQHandler[WEAK]
EXPORTTIM7_IRQHandler[WEAK]
EXPORTDMA2_Channel1_IRQHandler[WEAK]
EXPORTDMA2_Channel2_IRQHandler[WEAK]
EXPORTDMA2_Channel3_IRQHandler[WEAK]
EXPORTDMA2_Channel4_5_IRQHandler [WEAK]


WWDG_IRQHandler
PVD_IRQHandler
TAMPER_IRQHandler
RTC_IRQHandler
FLASH_IRQHandler
RCC_IRQHandler
EXTI0_IRQHandler
EXTI1_IRQHandler
EXTI2_IRQHandler
EXTI3_IRQHandler
EXTI4_IRQHandler
DMA1_Channel1_IRQHandler
DMA1_Channel2_IRQHandler
DMA1_Channel3_IRQHandler
DMA1_Channel4_IRQHandler
DMA1_Channel5_IRQHandler
DMA1_Channel6_IRQHandler
DMA1_Channel7_IRQHandler
ADC1_2_IRQHandler
USB_HP_CAN1_TX_IRQHandler
USB_LP_CAN1_RX0_IRQHandler
CAN1_RX1_IRQHandler
CAN1_SCE_IRQHandler
EXTI9_5_IRQHandler
TIM1_BRK_IRQHandler
TIM1_UP_IRQHandler
TIM1_TRG_COM_IRQHandler
TIM1_CC_IRQHandler
TIM2_IRQHandler
TIM3_IRQHandler
TIM4_IRQHandler
I2C1_EV_IRQHandler
I2C1_ER_IRQHandler
I2C2_EV_IRQHandler
I2C2_ER_IRQHandler
SPI1_IRQHandler
SPI2_IRQHandler
USART1_IRQHandler
USART2_IRQHandler
USART3_IRQHandler
EXTI15_10_IRQHandler
RTCAlarm_IRQHandler
USBWakeUp_IRQHandler
TIM8_BRK_IRQHandler
TIM8_UP_IRQHandler
TIM8_TRG_COM_IRQHandler
TIM8_CC_IRQHandler
ADC3_IRQHandler
FSMC_IRQHandler
SDIO_IRQHandler
TIM5_IRQHandler
SPI3_IRQHandler
UART4_IRQHandler
UART5_IRQHandler
TIM6_IRQHandler
TIM7_IRQHandler
DMA2_Channel1_IRQHandler
DMA2_Channel2_IRQHandler
DMA2_Channel3_IRQHandler
DMA2_Channel4_5_IRQHandler
B.


ENDP


ALIGN


; *******************************************************************************
; User Stack and Heap initialization
; *******************************************************************************
IF:DEF:__MICROLIB

EXPORT__initial_sp
EXPORT__heap_base
EXPORT__heap_limit

ELSE

IMPORT__use_two_region_memory
EXPORT__user_initial_stackheap

__user_initial_stackheap


LDRR0, =Heap_Mem
LDRR1, =(Stack_Mem + Stack_Size)
LDRR2, = (Heap_Mem +Heap_Size)
LDRR3, = Stack_Mem
BXLR


ALIGN


ENDIF


END


; ******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE*****

    推荐阅读