STM32启动过程解析-2.02固件库启动文件分析
扫描二维码
随时随地手机看文章
相对于ARM上一代的主流ARM7/ARM9内核架构,新一代Cortex内核架构的启动方式有了比较大的变化。ARM7/ARM9内核的控制器在复位后,CPU会从存储空间的绝对地址0x000000取出第一条指令执行复位中断服务程序的方式启动,即固定了复位后的起始地址为0x000000(PC = 0x000000)同时中断向量表的位置并不是固定的。而Cortex-M3内核则正好相反,有3种情况:
1、 通过boot引脚设置可以将中断向量表定位于SRAM区,即起始地址为0x2000000,同时复位后PC指针位于0x2000000处;
2、 通过boot引脚设置可以将中断向量表定位于FLASH区,即起始地址为0x8000000,同时复位后PC指针位于0x8000000处;
3、 通过boot引脚设置可以将中断向量表定位于内置Bootloader区,本文不对这种情况做论述;
而Cortex-M3内核规定,起始地址必须存放堆顶指针,而第二个地址则必须存放复位中断入口向量地址,这样在Cortex-M3内核复位后,会自动从起始地址的下一个32位空间取出复位中断入口向量,跳转执行复位中断服务程序。对比ARM7/ARM9内核,Cortex-M3内核则是固定了中断向量表的位置而起始地址是可变化的。
有了上述准备只是后,下面以STM32的2.02固件库提供的启动文件“stm32f10x_vector.s”为模板,对STM32的启动过程做一个简要而全面的解析。
程序清单一:
文件“stm32f10x_vector.s”,其中注释为行号
DATA_IN_ExtSRAMEQU0;1Stack_SizeEQU0x00000400;2AREASTACK,NOINIT,READWRITE,ALIGN=3;3Stack_MemSPACEStack_Size;4__initial_sp;5Heap_SizeEQU0x00000400;6AREAHEAP,NOINIT,READWRITE,ALIGN=3;7__heap_base;8Heap_MemSPACEHeap_Size;9__heap_limit;10THUMB;11PRESERVE8;12IMPORTNMIException;13IMPORTHardFaultException;14IMPORTMemManageException;15IMPORTBusFaultException;16IMPORTUsageFaultException;17IMPORTSVCHandler;18IMPORTDebugMonitor;19IMPORTPendSVC;20IMPORTSysTickHandler;21IMPORTWWDG_IRQHandler;22IMPORTPVD_IRQHandler;23IMPORTTAMPER_IRQHandler;24IMPORTRTC_IRQHandler;25IMPORTFLASH_IRQHandler;26IMPORTRCC_IRQHandler;27IMPORTEXTI0_IRQHandler;28IMPORTEXTI1_IRQHandler;29IMPORTEXTI2_IRQHandler;30IMPORTEXTI3_IRQHandler;31IMPORTEXTI4_IRQHandler;32IMPORTDMA1_Channel1_IRQHandler;33IMPORTDMA1_Channel2_IRQHandler;34IMPORTDMA1_Channel3_IRQHandler;35IMPORTDMA1_Channel4_IRQHandler;36IMPORTDMA1_Channel5_IRQHandler;37IMPORTDMA1_Channel6_IRQHandler;38IMPORTDMA1_Channel7_IRQHandler;39IMPORTADC1_2_IRQHandler;40IMPORTUSB_HP_CAN_TX_IRQHandler;41IMPORTUSB_LP_CAN_RX0_IRQHandler;42IMPORTCAN_RX1_IRQHandler;43IMPORTCAN_SCE_IRQHandler;44IMPORTEXTI9_5_IRQHandler;45IMPORTTIM1_BRK_IRQHandler;46IMPORTTIM1_UP_IRQHandler;47IMPORTTIM1_TRG_COM_IRQHandler;48IMPORTTIM1_CC_IRQHandler;49IMPORTTIM2_IRQHandler;50IMPORTTIM3_IRQHandler;51IMPORTTIM4_IRQHandler;52IMPORTI2C1_EV_IRQHandler;53IMPORTI2C1_ER_IRQHandler;54IMPORTI2C2_EV_IRQHandler;55IMPORTI2C2_ER_IRQHandler;56IMPORTSPI1_IRQHandler;57IMPORTSPI2_IRQHandler;58IMPORTUSART1_IRQHandler;59IMPORTUSART2_IRQHandler;60IMPORTUSART3_IRQHandler;61IMPORTEXTI15_10_IRQHandler;62IMPORTRTCAlarm_IRQHandler;63IMPORTUSBWakeUp_IRQHandler;64IMPORTTIM8_BRK_IRQHandler;65IMPORTTIM8_UP_IRQHandler;66IMPORTTIM8_TRG_COM_IRQHandler;67IMPORTTIM8_CC_IRQHandler;68IMPORTADC3_IRQHandler;69IMPORTFSMC_IRQHandler;70IMPORTSDIO_IRQHandler;71IMPORTTIM5_IRQHandler;72IMPORTSPI3_IRQHandler;73IMPORTUART4_IRQHandler;74IMPORTUART5_IRQHandler;75IMPORTTIM6_IRQHandler;76IMPORTTIM7_IRQHandler;77IMPORTDMA2_Channel1_IRQHandler;78IMPORTDMA2_Channel2_IRQHandler;79IMPORTDMA2_Channel3_IRQHandler;80IMPORTDMA2_Channel4_5_IRQHandler;81AREARESET,DATA,READONLY;82EXPORT__Vectors;83__Vectors;84DCD__initial_sp;85DCDReset_Handler;86DCDNMIException;87DCDHardFaultException;88DCDMemManageException;89DCDBusFaultException;90DCDUsageFaultException;91DCD0;92DCD0;93DCD0;94DCD0;95DCDSVCHandler;96DCDDebugMonitor;97DCD0;98DCDPendSVC;99DCDSysTickHandler;100DCDWWDG_IRQHandler;101DCDPVD_IRQHandler;102DCDTAMPER_IRQHandler;103DCDRTC_IRQHandler;104DCDFLASH_IRQHandler;105DCDRCC_IRQHandler;106DCDEXTI0_IRQHandler;107DCDEXTI1_IRQHandler;108DCDEXTI2_IRQHandler;109DCDEXTI3_IRQHandler;110DCDEXTI4_IRQHandler;111DCDDMA1_Channel1_IRQHandler;112DCDDMA1_Channel2_IRQHandler;113DCDDMA1_Channel3_IRQHandler;114DCDDMA1_Channel4_IRQHandler;115DCDDMA1_Channel5_IRQHandler;116DCDDMA1_Channel6_IRQHandler;117DCDDMA1_Channel7_IRQHandler;118DCDADC1_2_IRQHandler;119DCDUSB_HP_CAN_TX_IRQHandler;120DCDUSB_LP_CAN_RX0_IRQHandler;121DCDCAN_RX1_IRQHandler;122DCDCAN_SCE_IRQHandler;123DCDEXTI9_5_IRQHandler;124DCDTIM1_BRK_IRQHandler;125DCDTIM1_UP_IRQHandler;126DCDTIM1_TRG_COM_IRQHandler;127DCDTIM1_CC_IRQHandler;128DCDTIM2_IRQHandler;129DCDTIM3_IRQHandler;130DCDTIM4_IRQHandler;131DCDI2C1_EV_IRQHandler;132DCDI2C1_ER_IRQHandler;133DCDI2C2_EV_IRQHandler;134DCDI2C2_ER_IRQHandler;135DCDSPI1_IRQHandler;136DCDSPI2_IRQHandler;137DCDUSART1_IRQHandler;138DCDUSART2_IRQHandler;139DCDUSART3_IRQHandler;140DCDEXTI15_10_IRQHandler;141DCDRTCAlarm_IRQHandler;142DCDUSBWakeUp_IRQHandler;143DCDTIM8_BRK_IRQHandler;144DCDTIM8_UP_IRQHandler;145DCDTIM8_TRG_COM_IRQHandler;146DCDTIM8_CC_IRQHandler;147DCDADC3_IRQHandler;148DCDFSMC_IRQHandler;149DCDSDIO_IRQHandler;150DCDTIM5_IRQHandler;151DCDSPI3_IRQHandler;152DCDUART4_IRQHandler;153DCDUART5_IRQHandler;154DCDTIM6_IRQHandler;155DCDTIM7_IRQHandler;156DCDDMA2_Channel1_IRQHandler;157DCDDMA2_Channel2_IRQHandler;158DCDDMA2_Channel3_IRQHandler;159DCDDMA2_Channel4_5_IRQHandler;160AREA|.text|,CODE,READONLY;161Reset_HandlerPROC;162EXPORTReset_Handler;163IFDATA_IN_ExtSRAM==1;164LDRR0,=0x00000114;165LDRR1,=0x40021014;166STRR0,[R1];167LDRR0,=0x000001E0;168LDRR1,=0x40021018;169STRR0,[R1];170LDRR0,=0x44BB44BB;171LDRR1,=0x40011400;172STRR0,[R1];173LDRR0,=0xBBBBBBBB;174LDRR1,=0x40011404;175STRR0,[R1];176LDRR0,=0xB44444BB;177LDRR1,=0x40011800;178STRR0,[R1];179LDRR0,=0xBBBBBBBB;180LDRR1,=0x40011804;181STRR0,[R1];182LDRR0,=0x44BBBBBB;183LDRR1,=0x40011C00;184STRR0,[R1];185LDRR0,=0xBBBB4444;186LDRR1,=0x40011C04;187STRR0,[R1];188LDRR0,=0x44BBBBBB;189LDRR1,=0x40012000;190STRR0,[R1];191LDRR0,=0x44444B44;192LDRR1,=0x40012004;193STRR0,[R1];194LDRR0,=0x00001011;195LDRR1,=0xA0000010;196STRR0,[R1];197LDRR0,=0x00000200;198LDRR1,=0xA0000014;199STRR0,[R1];200ENDIF;201IMPORT__main;202LDRR0,=__main;203BXR0;204ENDP;205ALIGN;206IF:DEF:__MICROLIB;207EXPORT__initial_sp;208EXPORT__heap_base;209EXPORT__heap_limit;210ELSE;211IMPORT__use_two_region_memory;212EXPORT__user_initial_stackheap;213__user_initial_stackheap;214LDRR0,=Heap_Mem;215LDRR1,=(Stack_Mem+Stack_Size);216LDRR2,=(Heap_Mem+Heap_Size);217LDRR3,=Stack_Mem;218BXLR;219ALIGN;220ENDIF;221END;222ENDIF;223END;224