STM32F429--启动文件简单分析

本文详细解析STM32F429的启动文件,涵盖初始化堆栈SP、设置PC指向Reset_Handler、构建中断向量表、配置系统时钟以及进入C世界的过程。启动文件还涉及汇编指令和中断服务函数的弱定义。
摘要由CSDN通过智能技术生成

下面的内容是stm32f429的启动文件拷贝过来的,并对其部分进行了说明

;******************** © COPYRIGHT 2016 STMicroelectronics ********************
;* File Name : startup_stm32f429_439xx.s
;* Author : MCD Application Team
;* @version : V1.8.0
;* @date : 09-November-2016
;* Description : STM32F429xx/439xx 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 system clock and the external SRAM/SDRAM mounted
;* on STM324x9I-EVAL boards 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 CortexM4 processor is in Thread mode,
;* priority is Privileged, and the Stack is set to Main.
上述讲的就是启动文件的作用
1- 初始化堆栈指针SP
2- 初始化PC指针,指向复位程序
3- 初始化中断向量表
4- 配置系统时钟
5- 调用C库函数_main,最终进入C世界

;* <<< Use Configuration Wizard in Context Menu >>>
;*******************************************************************************
;
; Licensed under MCD-ST Liberty SW License Agreement V2, (the “License”);
; You may not use this file except in compliance with the License.
; You may obtain a copy of the License at:
;
; http://www.st.com/software_license_agreement_liberty_v2
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an “AS IS” BASIS,
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
; See the License for the specific language governing permissions and
; limitations under the License.
;
;*******************************************************************************

; 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_Size EQU 0x00000400
说明:
1KB的栈(Stack)空间大小 0x00000400 = 41616 = 1024 =1 KB
栈:用于局部变量、函数调用、函数形参的开销
EQU:宏定义的伪指令,相当于等于的意思,类似于C中的define
AREA:告诉汇编器汇编一个新的代码段或者数据段
SPACE:用于分配一定大小的内存空间,单位为字节
__initial_sp 紧挨着SPACE语句放置,表示栈的结束地址,即栈顶地址
栈是由高向低生长的。

要怎么找到指令说明呢?
打开我们的Keil–>Help–>uVision Help -->搜索–>输入搜索关键词word
–>Assembler User Guide:word
AREA STACK, NOINIT, READWRITE, ALIGN=3
Stack_Mem SPACE Stack_Size
__initial_sp
说明:
先开辟一段栈空间,大小为1KB,不初始化它,可读可写,按2的3次方8字节对齐。
__initial_sp 表示栈的结束地址

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

Heap_Size EQU 0x00000200

            AREA    HEAP, NOINIT, READWRITE, ALIGN=3

__heap_base
Heap_Mem SPACE Heap_Size
__heap_limit

            PRESERVE8
            THUMB

说明:
HEAP–堆
用于动态内存的分配,malloc函数
用的比较少
PRESERVE8:指定当前文件的堆栈按照8字节对齐
THUMB:表示后面指令为THUMB指令。THUMB是ARM以前的指令集,16bit,
现在的Cortex-M系列的都使用THUMB-2指令集,THUMB-2是32位的,兼容
16位和32位的指令,是THUMB的超集。

EXPORT:声明一个标号具有全局属性,【可被外部的文件使用】。
如果是IAR编译器,则使用的是GLOBAL这个指令。

DCD:分配一个或者多个以字为单位的内存,以四字节对齐,
并要求初始化这些内存。在向量表中,DCD分配了一堆内存,
并且以ESR的入口地址初始化它们。

; Vector Table Mapped to Address 0 at Reset
AREA RESET, DATA, READONLY
EXPORT __Vectors
EXPORT __Vectors_End
EXPORT __Vectors_Size

下面用__Vectors关键字分配了一连串的内存。
向量表:
1-向量表实际上是一个32位的整型数组,一个元素对应一个异常(ESR),
数组元素存的就是ESR的入口地址。异常==中断
2- 向量表在复位后从FLASH的0地址开始,具体的初始化值查询参考手册的中断章节。
从代码上看,向量表中存放的都是中断服务函数的【函数名】,我们知道C语言中的
函数名就是一个地址。后续写中断函数,名称要参考下面的XXX_Handler

__Vectors DCD __initial_sp ; Top of Stack
DCD Reset_Handler ; Reset Handler
DCD NMI_Handler ; NMI Handler
DCD HardFault_Handler ; Hard Fault Handler
DCD MemManage_Handler ; MPU Fault Handler
DCD BusFault_Handler ; Bus Fault Handler
DCD UsageFault_Handler ; Usage Fault Handler
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD SVC_Handler ; SVCall Handler
DCD DebugMon_Handler ; Debug Monitor Handler
DCD 0 ; Reserved
DCD PendSV_Handler ; PendSV Handler
DCD SysTick_Handler ; SysTick Handler

            ; External Interrupts
            DCD     WWDG_IRQHandler                   ; Window WatchDog                                        
            DCD     PVD_IRQHandler                    ; PVD through EXTI Line detection                        
            DCD     TAMP_STAMP_IRQHandler             ; Tamper and TimeStamps through the EXTI line            
            DCD     RTC_WKUP_IRQHandler               ; RTC Wakeup through the EXTI line                       
            DCD     FLASH_IRQHandler                  ; FLASH                                           
            DCD     RCC_IRQHandler                    ; RCC                                             
            DCD     EXTI0_IRQHandler                  ;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值