【STM32 keil mdk启动代码发分析】
STM32 keil mdk启动代码发分析 收藏 学习STM32,看了一堆乱七八糟的文档,准备写程序了,先分析了下STM32的启动代码,看着这堆鬼鬼的汇编代码,挺吓人的,看看帮助,查查网路,还是不那么难懂。
view plain copy to clipboard print ?
- ;
//Stack Configuration
- ;
// Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
- ;
//
- Stack_SizeEQU0x00000200;
//定义堆栈大小
- AREASTACK, NOINIT, READWRITE, ALIGN=3;
//定义一个数据段 按8字节对齐
- Stack_MemSPACEStack_Size;
//保留Stack_Size大小的堆栈空间
- __initial_sp;
//标号,代表堆栈顶部地址,后面有用
- ;
//Heap Configuration
- ;
//Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
- ;
//
- Heap_SizeEQU0x00000020;
//定义堆空间大小
- AREAHEAP, NOINIT, READWRITE, ALIGN=3;
//定义一个数据段,8字节对齐
- __heap_base
- Heap_MemSPACEHeap_Size;
//保留Heap_Size的堆空间
- __heap_limit;
//标号,代表堆末尾地址,后面有用
- PRESERVE8;
//指示编译器8字节对齐
- THUMB;
//指示编译器为THUMB指令
- ;
Vector Table Mapped to Address 0 at Reset
- AREARESET, DATA, READONLY;
//定义只读数据段,其实放在CODE区,位于0地址
- EXTERNNMIException
- EXTERNHardFaultException
- EXTERNMemManageException
- EXTERNBusFaultException
- EXTERNUsageFaultException
- EXTERNSVCHandler
- EXTERNDebugMonitor
- EXTERNPendSVC
- EXTERNSysTickHandler;
//声明这些符号在外部定义,同C
- ;
//在××it.c中实现这些函数 ,中断就能自动调用了
- EXPORT__Vectors
- __VectorsDCD__initial_sp;
Top of Stack//Cotex-M要求此处为堆栈顶部地址
- DCDReset_Handler;
Reset Handler
- DCDNMIException;
NMI Handler
- DCDHardFaultException;
Hard Fault Handler
- DCDMemManageException;
MPU Fault Handler
- DCDBusFaultException;
Bus Fault Handler
- DCDUsageFaultException;
Usage Fault Handler
- DCD0;
Reserved
- DCD0;
Reserved
- DCD0;
Reserved
- DCD0;
Reserved
- DCDSVCHandler;
SVCall Handler
- DCDDebugMonitor;
Debug Monitor Handler
- DCD0;
Reserved
- DCDPendSVC;
PendSV Handler
- DCDSysTickHandler;
SysTick Handler//一大堆的异常处理函数地址
- ;
External Interrupts
- EXTERNWWDG_IRQHandler
- EXTERNPVD_IRQHandler
- EXTERNTAMPER_IRQHandler
- EXTERNRTC_IRQHandler
- EXTERNFLASH_IRQHandler
- EXTERNRCC_IRQHandler
- EXTERNEXTI0_IRQHandler
- EXTERNEXTI1_IRQHandler
- EXTERNEXTI2_IRQHandler
- EXTERNEXTI3_IRQHandler
- EXTERNEXTI4_IRQHandler
- EXTERNDMAChannel1_IRQHandler
- EXTERNDMAChannel2_IRQHandler
- EXTERNDMAChannel3_IRQHandler
- EXTERNDMAChannel4_IRQHandler
- EXTERNDMAChannel5_IRQHandler
- EXTERNDMAChannel6_IRQHandler
- EXTERNDMAChannel7_IRQHandler
- EXTERNADC_IRQHandler
- EXTERNUSB_HP_CAN_TX_IRQHandler
- EXTERNUSB_LP_CAN_RX0_IRQHandler
- EXTERNCAN_RX1_IRQHandler
- EXTERNCAN_SCE_IRQHandler
- EXTERNEXTI9_5_IRQHandler
- EXTERNTIM1_BRK_IRQHandler
- EXTERNTIM1_UP_IRQHandler
- EXTERNTIM1_TRG_COM_IRQHandler
- EXTERNTIM1_CC_IRQHandler
- EXTERNTIM2_IRQHandler
- EXTERNTIM3_IRQHandler
- EXTERNTIM4_IRQHandler
- EXTERNI2C1_EV_IRQHandler
- EXTERNI2C1_ER_IRQHandler
- EXTERNI2C2_EV_IRQHandler
- EXTERNI2C2_ER_IRQHandler
- EXTERNSPI1_IRQHandler
- EXTERNSPI2_IRQHandler
- EXTERNUSART1_IRQHandler
- EXTERNUSART2_IRQHandler
- EXTERNUSART3_IRQHandler
- EXTERNEXTI15_10_IRQHandler
- EXTERNRTCAlarm_IRQHandler
- EXTERNUSBWakeUp_IRQHandler;
//同上,
- 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
- DCDDMAChannel1_IRQHandler;
DMA Channel 1
- DCDDMAChannel2_IRQHandler;
DMA Channel 2
- DCDDMAChannel3_IRQHandler;
DMA Channel 3
- DCDDMAChannel4_IRQHandler;
DMA Channel 4
- DCDDMAChannel5_IRQHandler;
DMA Channel 5
- DCDDMAChannel6_IRQHandler;
DMA Channel 6
- DCDDMAChannel7_IRQHandler;
DMA Channel 7
- DCDADC_IRQHandler;
ADC
- DCDUSB_HP_CAN_TX_IRQHandler;
USB High Priority or CAN TX
- DCDUSB_LP_CAN_RX0_IRQHandler ;
USB LowPriority or CAN RX0
- DCDCAN_RX1_IRQHandler;
CAN RX1
- DCDCAN_SCE_IRQHandler;
CAN 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;
//同上
- AREA|.text|, CODE, READONLY;
//定义代码段
- ;
Reset Handler
- Reset_HandlerPROC;
//Rset_Handler的实现
- EXPORTReset_Handler[WEAK];
//在外部没有定义该符号时导出该符号,见HELP中[WEAK]
- IMPORT__main;
//导入符号,__main为 运行时库提供的函数;完成堆栈,堆的初始话
- LDRR0, =__main;
//等工作,会调用下面定义的__user_initial_stackheap;
- BXR0;
//跳到__main,进入C的世界
- ENDP
- ALIGN
- ;
User Initial Stack & Heap
- IF:DEF:__MICROLIB;
//如果使用micro lib,micro lib 描述见armlib.chm
- EXPORT__initial_sp
- EXPORT__heap_base
- EXPORT__heap_limit;
//只导出几个定义
- ELSE;
//如果使用默认C运行时库
- IMPORT__use_two_region_memory
- EXPORT__user_initial_stackheap
- __user_initial_stackheap;
//则进行堆栈和堆的赋值,在__main函数执行过程中调用。
- LDRR0, =Heap_Mem
- LDRR1, =(Stack_Mem + Stack_Size)
- LDRR2, = (Heap_Mem +Heap_Size)
- LDRR3, = Stack_Mem
- BXLR
- ALIGN
- ENDIF
- END;
//OK ,完了
推荐阅读