我是靠谱客的博主 缥缈眼神,最近开发中收集的这篇文章主要介绍stm32 启动文件解析,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

;******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
;* File Name
: stm32f10x_vector.s
;* Author
: MCD Application Team
;* Version
: V2.0.2
;* Date
: 07/11/2008
;* Description
: STM32F10x vector table for RVMDK 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 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.
;*******************************************************************************
; If you need to use external SRAM mounted on STM3210E-EVAL board as data memory,
; change the following define value to '1' (or choose ENABLE in Configuration Wizard window)
;//
<o>
External SRAM Configuration
<0=> DISABLE <1=> ENABLE 
//定义是否使用外部SRAM,为1则使用,为0则不使用,此语句若用c语言表示则等价于:
#define DATA_IN_ExtSRAM
DATA_IN_ExtSRAM
EQU
0
//定义栈空间大小为0x00000400字节,即1kB
Stack_Size
EQU
0x00000400
//伪指令AREA
AREA
STACK, NOINIT, READWRITE, ALIGN=3
//开辟一段大小为Stack_Size的内存空间作为栈
Stack_Mem
SPACE
Stack_Size
Heap_Size
EQU
0x00000400
AREA
HEAP, NOINIT, READWRITE, ALIGN=3
//标号__heap_base,表示堆空间起始地址
__heap_base
//开辟一段大小为Heap_Size的内存空间作为堆。
Heap_Mem
SPACE
Heap_Size
//标号__heap_limit,表示堆空间结束地址。
__heap_limit
//告诉编译器使用THUMB指令集
THUMB
//告诉编译器以8字节对齐

PRESERVE8
//IMPORT指令,指示后续符号是在外部文件定义的,而下文可能使用这些符号
; Import exceptions handlers
IMPORT
NMIException
IMPORT
HardFaultException
IMPORT
MemManageException
IMPORT
BusFaultException
IMPORT
UsageFaultException
IMPORT
SVCHandler
IMPORT
DebugMonitor
IMPORT
PendSVC
IMPORT
SysTickHandler
IMPORT
WWDG_IRQHandler
IMPORT
PVD_IRQHandler
IMPORT
TAMPER_IRQHandler
IMPORT
RTC_IRQHandler
IMPORT
FLASH_IRQHandler
IMPORT
RCC_IRQHandler
IMPORT
EXTI0_IRQHandler
IMPORT
EXTI1_IRQHandler
IMPORT
EXTI2_IRQHandler
IMPORT
EXTI3_IRQHandler
IMPORT
EXTI4_IRQHandler
IMPORT
DMA1_Channel1_IRQHandler
IMPORT
DMA1_Channel2_IRQHandler
IMPORT
DMA1_Channel3_IRQHandler
IMPORT
DMA1_Channel4_IRQHandler
IMPORT
DMA1_Channel5_IRQHandler
IMPORT
DMA1_Channel6_IRQHandler
IMPORT
DMA1_Channel7_IRQHandler
IMPORT
ADC1_2_IRQHandler
IMPORT
USB_HP_CAN_TX_IRQHandler
IMPORT
USB_LP_CAN_RX0_IRQHandler
IMPORT
CAN_RX1_IRQHandler
IMPORT
CAN_SCE_IRQHandler
IMPORT
EXTI9_5_IRQHandler
IMPORT
TIM1_BRK_IRQHandler
IMPORT
TIM1_UP_IRQHandler
IMPORT
TIM1_TRG_COM_IRQHandler
IMPORT
TIM1_CC_IRQHandler
IMPORT
TIM2_IRQHandler
IMPORT
TIM3_IRQHandler
IMPORT
TIM4_IRQHandler
IMPORT
I2C1_EV_IRQHandler
IMPORT
I2C1_ER_IRQHandler
IMPORT
I2C2_EV_IRQHandler
IMPORT
I2C2_ER_IRQHandler
IMPORT
SPI1_IRQHandler
IMPORT
SPI2_IRQHandler
IMPORT
USART1_IRQHandler
IMPORT
USART2_IRQHandler
IMPORT
USART3_IRQHandler
IMPORT
EXTI15_10_IRQHandler
IMPORT
RTCAlarm_IRQHandler
IMPORT
USBWakeUp_IRQHandler
IMPORT
TIM8_BRK_IRQHandler
IMPORT
TIM8_UP_IRQHandler
IMPORT
TIM8_TRG_COM_IRQHandler
IMPORT
TIM8_CC_IRQHandler
IMPORT
ADC3_IRQHandler
IMPORT
FSMC_IRQHandler
IMPORT
SDIO_IRQHandler
IMPORT
TIM5_IRQHandler
IMPORT
SPI3_IRQHandler
IMPORT
UART4_IRQHandler
IMPORT
UART5_IRQHandler
IMPORT
TIM6_IRQHandler
IMPORT
TIM7_IRQHandler
IMPORT
DMA2_Channel1_IRQHandler
IMPORT
DMA2_Channel2_IRQHandler
IMPORT
DMA2_Channel3_IRQHandler
IMPORT
DMA2_Channel4_5_IRQHandler
;*******************************************************************************
; Fill-up the Vector Table entries with the exceptions ISR address
;*******************************************************************************
//定义只读数据段,实际上是此处位于CODE区(假设stm32从flash启动,则此数据段的起始地址即为0x80000000)
AREA
RESET, DATA, READONLY
//将__Vectors声明为全局标号,这样外部文件就可以使用这些标号
EXPORT
__Vectors
//标号__Vectors表示中断向量表入口地址

__Vectors
DCD
__initial_sp
; Top of Stack
DCD
Reset_Handler
DCD
NMIException
DCD
HardFaultException
DCD
MemManageException
DCD
BusFaultException
DCD
UsageFaultException
DCD
0
; Reserved
DCD
0
; Reserved
DCD
0
; Reserved
DCD
0
; Reserved
DCD
SVCHandler
DCD
DebugMonitor
DCD
0
; Reserved
DCD
PendSVC
DCD
SysTickHandler
DCD
WWDG_IRQHandler
DCD
PVD_IRQHandler
DCD
TAMPER_IRQHandler
DCD
RTC_IRQHandler
DCD
FLASH_IRQHandler
DCD
RCC_IRQHandler
DCD
EXTI0_IRQHandler
DCD
EXTI1_IRQHandler
DCD
EXTI2_IRQHandler
DCD
EXTI3_IRQHandler
DCD
EXTI4_IRQHandler
DCD
DMA1_Channel1_IRQHandler
DCD
DMA1_Channel2_IRQHandler
DCD
DMA1_Channel3_IRQHandler
DCD
DMA1_Channel4_IRQHandler
DCD
DMA1_Channel5_IRQHandler
DCD
DMA1_Channel6_IRQHandler
DCD
DMA1_Channel7_IRQHandler
DCD
ADC1_2_IRQHandler
DCD
USB_HP_CAN_TX_IRQHandler
DCD
USB_LP_CAN_RX0_IRQHandler
DCD
CAN_RX1_IRQHandler
DCD
CAN_SCE_IRQHandler
DCD
EXTI9_5_IRQHandler
DCD
TIM1_BRK_IRQHandler
DCD
TIM1_UP_IRQHandler
DCD
TIM1_TRG_COM_IRQHandler
DCD
TIM1_CC_IRQHandler
DCD
TIM2_IRQHandler
DCD
TIM3_IRQHandler
DCD
TIM4_IRQHandler
DCD
I2C1_EV_IRQHandler
DCD
I2C1_ER_IRQHandler
DCD
I2C2_EV_IRQHandler
DCD
I2C2_ER_IRQHandler
DCD
SPI1_IRQHandler
DCD
SPI2_IRQHandler
DCD
USART1_IRQHandler
DCD
USART2_IRQHandler
DCD
USART3_IRQHandler
DCD
EXTI15_10_IRQHandler
DCD
RTCAlarm_IRQHandler
DCD
USBWakeUp_IRQHandler
DCD
TIM8_BRK_IRQHandler
DCD
TIM8_UP_IRQHandler
DCD
TIM8_TRG_COM_IRQHandler
DCD
TIM8_CC_IRQHandler
DCD
ADC3_IRQHandler
DCD
FSMC_IRQHandler
DCD
SDIO_IRQHandler
DCD
TIM5_IRQHandler
DCD
SPI3_IRQHandler
DCD
UART4_IRQHandler
DCD
UART5_IRQHandler
DCD
TIM6_IRQHandler
DCD
TIM7_IRQHandler
DCD
DMA2_Channel1_IRQHandler
DCD
DMA2_Channel2_IRQHandler
DCD
DMA2_Channel3_IRQHandler
DCD
DMA2_Channel4_5_IRQHandler
AREA
|.text|, CODE, READONLY
; Reset handler routine
//复位中断服务程序,PROC...ENDP结构表示程序的开始和结束
Reset_Handler
PROC
EXPORT
Reset_Handler
//IF~~~ENDIF为预编译结构,判断是否使用外部SRAM,在第一行中已定义为"不使用"

IF
DATA_IN_ExtSRAM == 1
; FSMC Bank1 NOR/SRAM3 is used for the STM3210E-EVAL, if another Bank is
; required, then adjust the Register Addresses
; Enable FSMC clock
LDR R0,= 0x00000114
LDR R1,= 0x40021014
STR R0,[R1]
; Enable GPIOD, GPIOE, GPIOF and GPIOG clocks
LDR R0,= 0x000001E0
LDR R1,= 0x40021018
STR R0,[R1]
; SRAM Data lines, NOE and NWE configuration
; SRAM Address lines configuration
; NOE and NWE configuration
; NE3 configuration
; NBL0, NBL1 configuration
LDR R0,= 0x44BB44BB
LDR R1,= 0x40011400
STR R0,[R1]
LDR R0,= 0xBBBBBBBB
LDR R1,= 0x40011404
STR R0,[R1]
LDR R0,= 0xB44444BB
LDR R1,= 0x40011800
STR R0,[R1]
LDR R0,= 0xBBBBBBBB
LDR R1,= 0x40011804
STR R0,[R1]
LDR R0,= 0x44BBBBBB
LDR R1,= 0x40011C00
STR R0,[R1]
LDR R0,= 0xBBBB4444
LDR R1,= 0x40011C04
STR R0,[R1]
LDR R0,= 0x44BBBBBB
LDR R1,= 0x40012000
STR R0,[R1]
LDR R0,= 0x44444B44
LDR R1,= 0x40012004
STR R0,[R1]
; FSMC Configuration
; Enable FSMC Bank1_SRAM Bank
LDR R0,= 0x00001011
LDR R1,= 0xA0000010
STR R0,[R1]
LDR R0,= 0x00000200
LDR R1,= 0xA0000014
STR R0,[R1]
ENDIF
IMPORT
__main
LDR
R0, =__main
BX
R0
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
LDR
R0, =
Heap_Mem
LDR
R1, =(Stack_Mem + Stack_Size)
LDR
R2, = (Heap_Mem +
Heap_Size)
LDR
R3, = Stack_Mem
BX
LR
ALIGN
ENDIF
END
;******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE*****
AREA指令:
伪指令,用于定义代码段或数据段,后跟属性标号。其中比较重要的一个标号为“READONLY”或者"READWRITE",其中“READONLY”表示该段为只读属性,联系到stm32的内部存储介质可知,具有只读属性的段保存于flash区,即0x8000000地址后。而"READWRITE"表示该段为“可读/写”属性,可知可读写段保存于sram区,即0x2000000地址后。中断向量表放置于flash取,而这也是整片启动代码中最先倍放进flash区的数据。因此可以得到一条重要的信息:0x8000000地址存放的是栈顶地址__initial_sp,0x8000004地址存放的是复位中断向量Reset_Handler(stm3使用32位总线,存储空间为4字节对齐)
DCD指令:
作用是开辟一段空间,其意义等价于c语言中的地址符“&”
__main标号并不表示c程序中的main函数的入口地址,__main标号表示C/C++ 标准实时库函数里的一个初始化子程序__main的入口地址。该程序的一个主要作用是初始化堆栈。
最后总结一下stm32的启动文件和启动过程:首先对栈和堆的大小进行定义,并在代码区的起始处建立中断向量表,其第一个表项是栈顶地址,第二个表项是复位中断服务入口地址。然后在复位中断服务程序中跳转C/C++标准实时库的__main函数,完成堆栈等的初始化后,跳转.c文件中的main函数开始执行c程序。

最后

以上就是缥缈眼神为你收集整理的stm32 启动文件解析的全部内容,希望文章能够帮你解决stm32 启动文件解析所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(84)

评论列表共有 0 条评论

立即
投稿
返回
顶部