文档库

最新最全的文档下载
当前位置:文档库 > STM32F407启动代码分析

STM32F407启动代码分析

;定义栈段,不初始化(只分配空间不做初始化或者初始化为零)

Stack_Size EQU 0x00000400 ;#define Stack_Size ox00000400,EQU---arm汇编的预定义

AREA STACK, NOINIT, READWRITE, ALIGN=3 ;段的开始,段名STACK,段属性NOINIT, ALIIGN

Stack_Mem SPACE Stack_Size;分配栈存储空间大小为ox00000400(1K),SPACE 分配连续存储单元,

__initial_sp;栈空间顶地址

; Heap Configuration

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

;

;开辟一段大小为Heap_base的内存空间作为堆

Heap_Size EQU 0x00000200;#define Heap_Size ox00000200

AREA HEAP, NOINIT, READWRITE, ALIGN=3;HEAP段,NOINIT只分配空间不做初始化或初始化为零;可读可写,按八字节对齐

__heap_base ;堆起始地址

Heap_Mem SPACE Heap_Size;分配堆空间大小为0x00000200

__heap_limit ;堆终止地址

PRESERVE8;告诉编译器以八字节对齐

THUMB;告诉编译器使用THUMB指令集

;定义复位段(中断向量表),并初始化

; Vector Table Mapped to Address 0 at Reset

AREA RESET, DA TA, READONL Y;定义RESET段,数据段,之都

EXPORT __Vectors;声明全局变量_Vectors,该标号可在其他文件中使用,中断向量表入口地址

EXPORT __Vectors_End;向量表终止地址

EXPORT __Vectors_Size;向量表空间大小

;DCD用于分配一段字内存单元(分配的内存以字对齐)

__Vectors DCD __initial_sp ; Top of Stack 内存块起始地址标号为_Vectors,栈顶地址

DCD Reset_Handler ; Reset Handler接下来到AREA |.text|, CODE, READONL Y都是建立中断向量表

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 ; EXTI Line0

DCD EXTI1_IRQHandler ; EXTI Line1

DCD EXTI2_IRQHandler ; EXTI Line2

DCD EXTI3_IRQHandler ; EXTI Line3

DCD EXTI4_IRQHandler ; EXTI Line4

DCD DMA1_Stream0_IRQHandler ; DMA1 Stream 0

DCD DMA1_Stream1_IRQHandler ; DMA1 Stream 1

DCD DMA1_Stream2_IRQHandler ; DMA1 Stream 2

DCD DMA1_Stream3_IRQHandler ; DMA1 Stream 3

DCD DMA1_Stream4_IRQHandler ; DMA1 Stream 4

DCD DMA1_Stream5_IRQHandler ; DMA1 Stream 5

DCD DMA1_Stream6_IRQHandler ; DMA1 Stream 6

DCD ADC_IRQHandler ; ADC1, ADC2 and ADC3s

DCD CAN1_TX_IRQHandler ; CAN1 TX

DCD CAN1_RX0_IRQHandler ; CAN1 RX0

DCD CAN1_RX1_IRQHandler ; CAN1 RX1

DCD CAN1_SCE_IRQHandler ; CAN1 SCE

DCD EXTI9_5_IRQHandler ; External Line[9:5]s

DCD TIM1_BRK_TIM9_IRQHandler ; TIM1 Break and TIM9

DCD TIM1_UP_TIM10_IRQHandler ; TIM1 Update and TIM10

DCD TIM1_TRG_COM_TIM11_IRQHandler ; TIM1 Trigger and Commutation and TIM11

DCD TIM1_CC_IRQHandler ; TIM1 Capture Compare

DCD TIM2_IRQHandler ; TIM2

DCD TIM3_IRQHandler ; TIM3

DCD TIM4_IRQHandler ; TIM4

DCD I2C1_EV_IRQHandler ; I2C1 Event

DCD I2C1_ER_IRQHandler ; I2C1 Error

DCD I2C2_EV_IRQHandler ; I2C2 Event

DCD I2C2_ER_IRQHandler ; I2C2 Error

DCD SPI1_IRQHandler ; SPI1

DCD SPI2_IRQHandler ; SPI2

DCD USART1_IRQHandler ; USART1

DCD USART2_IRQHandler ; USART2

DCD USART3_IRQHandler ; USART3

DCD EXTI15_10_IRQHandler ; External Line[15:10]s

DCD RTC_Alarm_IRQHandler ; RTC Alarm (A and B) through EXTI Line

DCD OTG_FS_WKUP_IRQHandler ; USB OTG FS Wakeup through EXTI line

DCD TIM8_BRK_TIM12_IRQHandler ; TIM8 Break and TIM12

DCD TIM8_UP_TIM13_IRQHandler ; TIM8 Update and TIM13

DCD TIM8_TRG_COM_TIM14_IRQHandler ; TIM8 Trigger and Commutation and TIM14

DCD TIM8_CC_IRQHandler ; TIM8 Capture Compare

DCD DMA1_Stream7_IRQHandler ; DMA1 Stream7

DCD FSMC_IRQHandler ; FSMC

DCD SDIO_IRQHandler ; SDIO

DCD TIM5_IRQHandler ; TIM5

DCD SPI3_IRQHandler ; SPI3

DCD UART4_IRQHandler ; UART4

DCD UART5_IRQHandler ; UART5

DCD TIM6_DAC_IRQHandler ; TIM6 and DAC1&2 underrun errors

DCD TIM7_IRQHandler ; TIM7

DCD DMA2_Stream0_IRQHandler ; DMA2 Stream 0

DCD DMA2_Stream1_IRQHandler ; DMA2 Stream 1

DCD DMA2_Stream2_IRQHandler ; DMA2 Stream 2

DCD DMA2_Stream3_IRQHandler ; DMA2 Stream 3

DCD DMA2_Stream4_IRQHandler ; DMA2 Stream 4

DCD ETH_IRQHandler ; Ethernet

DCD ETH_WKUP_IRQHandler ; Ethernet Wakeup through EXTI line

DCD CAN2_TX_IRQHandler ; CAN2 TX

DCD CAN2_RX0_IRQHandler ; CAN2 RX0

DCD CAN2_RX1_IRQHandler ; CAN2 RX1

DCD CAN2_SCE_IRQHandler ; CAN2 SCE

DCD OTG_FS_IRQHandler ; USB OTG FS

DCD DMA2_Stream5_IRQHandler ; DMA2 Stream 5

DCD DMA2_Stream6_IRQHandler ; DMA2 Stream 6

DCD DMA2_Stream7_IRQHandler ; DMA2 Stream 7

DCD USART6_IRQHandler ; USART6

DCD I2C3_EV_IRQHandler ; I2C3 event

DCD I2C3_ER_IRQHandler ; I2C3 error

DCD OTG_HS_EP1_OUT_IRQHandle; USB OTG HS End Point 1 Out

DCD OTG_HS_EP1_IN_IRQHandler ; USB OTG HS End Point 1 In

DCD OTG_HS_WKUP_IRQHandler ; USB OTG HS Wakeup through EXTI

DCD OTG_HS_IRQHandler ; USB OTG HS

DCD DCMI_IRQHandler ; DCMI

DCD CRYP_IRQHandler ; CRYP crypto

DCD HASH_RNG_IRQHandler ; Hash and Rng

DCD FPU_IRQHandler ; FPU

__Vectors_End ;中断向量表结束地址

__Vectors_Size EQU __Vectors_End - __Vectors ;#define __Vectors_Size __Vectors_End - __Vectors

;定义代码段(异常处理函数),并进行初始化

AREA |.text|, CODE, READONLY; |.text|习惯性命名,表示由C编译程序产生的代码段,或用于以某种方式与C库关联的代码段

; Reset handler 复位处理函数

Reset_Handler PROC

EXPORT Reset_Handler [WEAK]

IMPORT SystemInit ;引入外部定义的SystemInit函数

IMPORT __main;引入外部定义的_main函数

;FPU settings 单精度浮点单元设置

LDR R0, =0xE000ED88 ; Enable CP10,CP11 R0=0xE000ED88

LDR R1,[R0] ;R1=[R0],将0xE000ED88地址下内容加载到R1内,即R1=0xE000ED88地址下的值

ORR R1,R1,#(0xF << 20);R1=R1|(0xF << 20)即将R1的[20:23]置为1

STR R1,[R0];[R0]=R1,将R1寄存器的内容写到R0寄存器内的数据所代表的地址下

LDR R0, =SystemInit ;R0=SystemInit

BLX R0 ;跳转到SystemInit地址处,执行SystemInit函数,并由ARM 切换到THUMB状态,并将PC当前内容保存到R14中

LDR R0, =__main;R0=_main,即将_main函数地址赋给R0

BX R0; 跳转到_main地址处执行,并且根据R0的最低位切换处理器状态

ENDP

;从Reset_Handler PROC到ENDP表示复位处理子程序

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

NMI_Handler PROC

EXPORT NMI_Handler [WEAK]

B .

ENDP

HardFault_Handler\

PROC

EXPORT HardFault_Handler [WEAK]

B .

ENDP

MemManage_Handler\

PROC

EXPORT MemManage_Handler [WEAK]

B .

ENDP

BusFault_Handler\

PROC

EXPORT BusFault_Handler [WEAK]

B .

ENDP

UsageFault_Handler\

PROC

EXPORT UsageFault_Handler [WEAK]

B .

ENDP

SVC_Handler PROC

EXPORT SVC_Handler [WEAK]

B .

ENDP

DebugMon_Handler\

PROC

EXPORT DebugMon_Handler [WEAK]

B .

ENDP

PendSV_Handler PROC

EXPORT PendSV_Handler [WEAK]

B .

ENDP

SysTick_Handler PROC

EXPORT SysTick_Handler [WEAK]

B .

ENDP

Default_Handler PROC ;这个异常处理函数会处理所有外部中断

EXPORT WWDG_IRQHandler [WEAK] EXPORT PVD_IRQHandler [WEAK] EXPORT TAMP_STAMP_IRQHandler [WEAK] EXPORT RTC_WKUP_IRQHandler [WEAK] EXPORT FLASH_IRQHandler [WEAK] EXPORT RCC_IRQHandler [WEAK] EXPORT EXTI0_IRQHandler [WEAK] EXPORT EXTI1_IRQHandler [WEAK] EXPORT EXTI2_IRQHandler [WEAK] EXPORT EXTI3_IRQHandler [WEAK] EXPORT EXTI4_IRQHandler [WEAK] EXPORT DMA1_Stream0_IRQHandler [WEAK] EXPORT DMA1_Stream1_IRQHandler [WEAK] EXPORT DMA1_Stream2_IRQHandler [WEAK] EXPORT DMA1_Stream3_IRQHandler [WEAK] EXPORT DMA1_Stream4_IRQHandler [WEAK] EXPORT DMA1_Stream5_IRQHandler [WEAK] EXPORT DMA1_Stream6_IRQHandler [WEAK] EXPORT ADC_IRQHandler [WEAK] EXPORT CAN1_TX_IRQHandler [WEAK] EXPORT CAN1_RX0_IRQHandler [WEAK] EXPORT CAN1_RX1_IRQHandler [WEAK] EXPORT CAN1_SCE_IRQHandler [WEAK] EXPORT EXTI9_5_IRQHandler [WEAK] EXPORT TIM1_BRK_TIM9_IRQHandler [WEAK] EXPORT TIM1_UP_TIM10_IRQHandler [WEAK] EXPORT TIM1_TRG_COM_TIM11_IRQHandler [WEAK] EXPORT TIM1_CC_IRQHandler [WEAK] EXPORT TIM2_IRQHandler [WEAK] EXPORT TIM3_IRQHandler [WEAK] EXPORT TIM4_IRQHandler [WEAK] EXPORT I2C1_EV_IRQHandler [WEAK] EXPORT I2C1_ER_IRQHandler [WEAK] EXPORT I2C2_EV_IRQHandler [WEAK] EXPORT I2C2_ER_IRQHandler [WEAK] EXPORT SPI1_IRQHandler [WEAK] EXPORT SPI2_IRQHandler [WEAK] EXPORT USART1_IRQHandler [WEAK] EXPORT USART2_IRQHandler [WEAK] EXPORT USART3_IRQHandler [WEAK] EXPORT EXTI15_10_IRQHandler [WEAK] EXPORT RTC_Alarm_IRQHandler [WEAK] EXPORT OTG_FS_WKUP_IRQHandler [WEAK]

EXPORT TIM8_BRK_TIM12_IRQHandler [WEAK]

EXPORT TIM8_UP_TIM13_IRQHandler [WEAK]

EXPORT TIM8_TRG_COM_TIM14_IRQHandler [WEAK]

EXPORT TIM8_CC_IRQHandler [WEAK]

EXPORT DMA1_Stream7_IRQHandler [WEAK]

EXPORT FSMC_IRQHandler [WEAK]

EXPORT SDIO_IRQHandler [WEAK]

EXPORT TIM5_IRQHandler [WEAK]

EXPORT SPI3_IRQHandler [WEAK]

EXPORT UART4_IRQHandler [WEAK]

EXPORT UART5_IRQHandler [WEAK]

EXPORT TIM6_DAC_IRQHandler [WEAK]

EXPORT TIM7_IRQHandler [WEAK]

EXPORT DMA2_Stream0_IRQHandler [WEAK]

EXPORT DMA2_Stream1_IRQHandler [WEAK]

EXPORT DMA2_Stream2_IRQHandler [WEAK]

EXPORT DMA2_Stream3_IRQHandler [WEAK]

EXPORT DMA2_Stream4_IRQHandler [WEAK]

EXPORT ETH_IRQHandler [WEAK]

EXPORT ETH_WKUP_IRQHandler [WEAK]

EXPORT CAN2_TX_IRQHandler [WEAK]

EXPORT CAN2_RX0_IRQHandler [WEAK]

EXPORT CAN2_RX1_IRQHandler [WEAK]

EXPORT CAN2_SCE_IRQHandler [WEAK]

EXPORT OTG_FS_IRQHandler [WEAK]

EXPORT DMA2_Stream5_IRQHandler [WEAK]

EXPORT DMA2_Stream6_IRQHandler [WEAK]

EXPORT DMA2_Stream7_IRQHandler [WEAK]

EXPORT USART6_IRQHandler [WEAK]

EXPORT I2C3_EV_IRQHandler [WEAK]

EXPORT I2C3_ER_IRQHandler [WEAK]

EXPORT OTG_HS_EP1_OUT_IRQHandler [WEAK]

EXPORT OTG_HS_EP1_IN_IRQHandler [WEAK]

EXPORT OTG_HS_WKUP_IRQHandler [WEAK]

EXPORT OTG_HS_IRQHandler [WEAK]

EXPORT DCMI_IRQHandler [WEAK]

EXPORT CRYP_IRQHandler [WEAK]

EXPORT HASH_RNG_IRQHandler [WEAK]

EXPORT FPU_IRQHandler [WEAK]

;下面的全部异常处理函数标号都对应同一个地址,这个地址也是Default_Handler的地址WWDG_IRQHandler

PVD_IRQHandler

TAMP_STAMP_IRQHandler

RTC_WKUP_IRQHandler

FLASH_IRQHandler

RCC_IRQHandler

EXTI0_IRQHandler

EXTI1_IRQHandler

EXTI2_IRQHandler

EXTI3_IRQHandler

EXTI4_IRQHandler

DMA1_Stream0_IRQHandler

DMA1_Stream1_IRQHandler

DMA1_Stream2_IRQHandler

DMA1_Stream3_IRQHandler

DMA1_Stream4_IRQHandler

DMA1_Stream5_IRQHandler

DMA1_Stream6_IRQHandler

ADC_IRQHandler

CAN1_TX_IRQHandler

CAN1_RX0_IRQHandler

CAN1_RX1_IRQHandler

CAN1_SCE_IRQHandler

EXTI9_5_IRQHandler

TIM1_BRK_TIM9_IRQHandler

TIM1_UP_TIM10_IRQHandler

TIM1_TRG_COM_TIM11_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

RTC_Alarm_IRQHandler

OTG_FS_WKUP_IRQHandler

TIM8_BRK_TIM12_IRQHandler

TIM8_UP_TIM13_IRQHandler

TIM8_TRG_COM_TIM14_IRQHandler TIM8_CC_IRQHandler

DMA1_Stream7_IRQHandler

FSMC_IRQHandler

SDIO_IRQHandler

TIM5_IRQHandler

SPI3_IRQHandler

UART4_IRQHandler

UART5_IRQHandler

TIM6_DAC_IRQHandler

TIM7_IRQHandler

DMA2_Stream0_IRQHandler

DMA2_Stream1_IRQHandler

DMA2_Stream2_IRQHandler

DMA2_Stream3_IRQHandler

DMA2_Stream4_IRQHandler

ETH_IRQHandler

ETH_WKUP_IRQHandler

CAN2_TX_IRQHandler

CAN2_RX0_IRQHandler

CAN2_RX1_IRQHandler

CAN2_SCE_IRQHandler

OTG_FS_IRQHandler

DMA2_Stream5_IRQHandler

DMA2_Stream6_IRQHandler

DMA2_Stream7_IRQHandler

USART6_IRQHandler

I2C3_EV_IRQHandler

I2C3_ER_IRQHandler

OTG_HS_EP1_OUT_IRQHandler

OTG_HS_EP1_IN_IRQHandler

OTG_HS_WKUP_IRQHandler

OTG_HS_IRQHandler

DCMI_IRQHandler

CRYP_IRQHandler

HASH_RNG_IRQHandler

FPU_IRQHandler

B .;死循环,

ENDP

ALIGN

;****************************************************************************** *

; User Stack and Heap initialization

;初始化堆栈段,之前只是定义了堆栈段,但是并没有对其进行初始化

;****************************************************************************** *

IF :DEF:__MICROLIB;_MICROLIB对应MDK中的Use MircoLIB,若勾选则IF为真,执行下述语句

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 2011 STMicroelectronics *****END OF FILE*****