#PS:要转载请注明出处,本人版权所有
#PS:这个只是 《 我自己 》理解,如果和你的
#原则相冲突,请谅解,勿喷
对于keil的启动代码(针对STM32F042),添加 备注 和 自己的理解
;
******************** (C) COPYRIGHT 2014 STMicroelectronics ********************
;
* File Name: startup_stm32f042.s
;
* Author: MCD Application Team,modified by Sky,
;
* Version: V1.5.0
;
* Date: 05-December-2014,modified on,01-Nov-2016
;
* Description: STM32F042 Devices vector table for
;
*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
;
*- Branches to __main in the C library (which eventually
;
*calls main()).
;
*After Reset the CortexM0 processor is in Thread mode,
;
*priority is Privileged, and the Stack is set to Main.
;
* <<< Use Configuration Wizard in Context Menu >>>
;
*******************************************************************************
;
@attention
;
;
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.
;
;
*******************************************************************************;
;
;
notes:stack,heap,data seg,code seg address of mem is set by compiler
;
;
;
;
Amount of memory (in bytes) allocated for Stack
;
Tailor this value to your application needs
;
Stack Configuration
;
Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
;
\;
;
EQU 定义宏
;
;
栈大小,1k
Stack_SizeEQU0x00000400
;
;
AREA 定义段,注意:一个程序是由多个段构成,如CODE,STACK,DATA,
;
;
ALIGN=3,8字节对齐
AREASTACK, NOINIT, READWRITE, ALIGN=3
Stack_MemSPACEStack_Size
;
;
__initial_sp一个标号,由汇编器进行计算,代表上面SPACE分配内存的最后一个地址,栈为向下增长型
__initial_sp;
Heap Configuration
;
Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
;
;
;
堆512bytes
Heap_SizeEQU0x00000200AREAHEAP, NOINIT, READWRITE, ALIGN=3
__heap_base
Heap_MemSPACEHeap_Size
__heap_limit
;
;
PRESERVE8,指定当前文件堆栈8bytes对齐
PRESERVE8
;
;
THUMB,后面的指令要兼容THUMB指令
THUMB;
Vector Table Mapped to Address 0 at Reset
;
;
定义一个叫做RESET的数据段
AREARESET, DATA, READONLY
;
;
EXPORT声明标号为外部文件可用
EXPORT__Vectors
EXPORT__Vectors_End
EXPORT__Vectors_Size
;
;
DCD是按4字节分配存储单元
__VectorsDCD__initial_sp;
Top of Stack
DCDReset_Handler;
Reset Handler
DCDNMI_Handler;
NMI Handler
DCDHardFault_Handler;
Hard Fault Handler
DCD0;
Reserved
DCD0;
Reserved
DCD0;
Reserved
DCD0;
Reserved
DCD0;
Reserved
DCD0;
Reserved
DCD0;
Reserved
DCDSVC_Handler;
SVCall Handler
DCD0;
Reserved
DCD0;
Reserved
DCDPendSV_Handler;
PendSV Handler
DCDSysTick_Handler;
SysTick Handler;
External Interrupts
DCDWWDG_IRQHandler;
Window Watchdog
DCDPVD_VDDIO2_IRQHandler;
PVD and VDDIO2 through EXTI Line detect
DCDRTC_IRQHandler;
RTC through EXTI Line
DCDFLASH_IRQHandler;
FLASH
DCDRCC_CRS_IRQHandler;
RCC and CRS
DCDEXTI0_1_IRQHandler;
EXTI Line 0 and 1
DCDEXTI2_3_IRQHandler;
EXTI Line 2 and 3
DCDEXTI4_15_IRQHandler;
EXTI Line 4 to 15
DCDTSC_IRQHandler;
TS
DCDDMA1_Channel1_IRQHandler;
DMA1 Channel 1
DCDDMA1_Channel2_3_IRQHandler;
DMA1 Channel 2 and Channel 3
DCDDMA1_Channel4_5_IRQHandler;
DMA1 Channel 4, Channel 5
DCDADC1_IRQHandler;
ADC1
DCDTIM1_BRK_UP_TRG_COM_IRQHandler ;
TIM1 Break, Update, Trigger and Commutation
DCDTIM1_CC_IRQHandler;
TIM1 Capture Compare
DCDTIM2_IRQHandler;
TIM2
DCDTIM3_IRQHandler;
TIM3
DCD0;
Reserved
DCD0;
Reserved
DCDTIM14_IRQHandler;
TIM14
DCD0;
Reserved
DCDTIM16_IRQHandler;
TIM16
DCDTIM17_IRQHandler;
TIM17
DCDI2C1_IRQHandler;
I2C1
DCD0;
Reserved
DCDSPI1_IRQHandler;
SPI1
DCDSPI2_IRQHandler;
SPI2
DCDUSART1_IRQHandler;
USART1
DCDUSART2_IRQHandler;
USART2
DCD0;
Reserved
DCDCEC_CAN_IRQHandler;
CEC and CAN
DCDUSB_IRQHandler;
USB__Vectors_End__Vectors_SizeEQU__Vectors_End - __Vectors;
;
定义一个.text的代码段
AREA|.text|, CODE, READONLY;
STM32F03x devices feature 4Kbytes of static SRAM. STM32F04x devices feature
;
6 Kbytes of static SRAM. STM32F05x devices feature 8Kbytes of static SRAM.
;
STM32F07xS devices feature 16 Kbytes of static SRAM. STM32F09x devices feature
;
32 Kbytes of static SRAM.;
Reset handler routine
;
;
PROC定义子程序
Reset_HandlerPROC
;
;
WEAK:弱定义
EXPORTReset_Handler[WEAK]
IMPORT__main
IMPORTSystemInit;
;
给R0赋值,sp的值
LDRR0, =__initial_sp;
set stack pointer
;
;
R0给MSP寄存器
MSRMSP, R0;
;
Check if boot space corresponds to test memory LDR R0,=0x00000004
LDR R1, [R0]
;
;
R1=0x08000004 OR R1=0x20000004 OR R1=0x1FXX XXXX
;
;
when R1=R1=0x1FXX XXXX,we can know that Reset_Handler'sAddress is not right,
;
;
it maybe in reserved or systemmemory or optionbyte,we must remap address for start
;
;
Logical shift right by register LSRSLSRS R1, R1, #24
;
R2=0x0000001F
LDR R2,=0x1F
CMP R1, R2BNE ApplicationStart;
;
SYSCFG clock enable
;
RCC_APB2ENR,0x40021018
LDR R0,=0x40021018
LDR R1,=0x00000001
STR R1, [R0];
;
Set CFGR1 register with flash memory remap at address 0
;
SYS_CFGR1,0x40010000
LDR R0,=0x40010000
LDR R1,=0x00000000
STR R1, [R0]
ApplicationStart
LDRR0, =SystemInit
BLXR0
LDRR0, =__main
BXR0
ENDP;
Dummy Exception Handlers (infinite loops which can be modified)NMI_HandlerPROC
EXPORTNMI_Handler[WEAK]
;
;
B .无限循环
B.
ENDP
HardFault_Handler\
PROC
EXPORTHardFault_Handler[WEAK]
B.
ENDP
SVC_HandlerPROC
EXPORTSVC_Handler[WEAK]
B.
ENDP
PendSV_HandlerPROC
EXPORTPendSV_Handler[WEAK]
B.
ENDP
SysTick_Handler PROC
EXPORTSysTick_Handler[WEAK]
B.
ENDPDefault_Handler PROCEXPORTWWDG_IRQHandler[WEAK]
EXPORTPVD_VDDIO2_IRQHandler[WEAK]
EXPORTRTC_IRQHandler[WEAK]
EXPORTFLASH_IRQHandler[WEAK]
EXPORTRCC_CRS_IRQHandler[WEAK]
EXPORTEXTI0_1_IRQHandler[WEAK]
EXPORTEXTI2_3_IRQHandler[WEAK]
EXPORTEXTI4_15_IRQHandler[WEAK]
EXPORTTSC_IRQHandler[WEAK]
EXPORTDMA1_Channel1_IRQHandler[WEAK]
EXPORTDMA1_Channel2_3_IRQHandler[WEAK]
EXPORTDMA1_Channel4_5_IRQHandler[WEAK]
EXPORTADC1_IRQHandler[WEAK]
EXPORTTIM1_BRK_UP_TRG_COM_IRQHandler [WEAK]
EXPORTTIM1_CC_IRQHandler[WEAK]
EXPORTTIM2_IRQHandler[WEAK]
EXPORTTIM3_IRQHandler[WEAK]
EXPORTTIM14_IRQHandler[WEAK]
EXPORTTIM16_IRQHandler[WEAK]
EXPORTTIM17_IRQHandler[WEAK]
EXPORTI2C1_IRQHandler[WEAK]
EXPORTSPI1_IRQHandler[WEAK]
EXPORTSPI2_IRQHandler[WEAK]
EXPORTUSART1_IRQHandler[WEAK]
EXPORTUSART2_IRQHandler[WEAK]
EXPORTCEC_CAN_IRQHandler[WEAK]
EXPORTUSB_IRQHandler[WEAK]WWDG_IRQHandler
PVD_VDDIO2_IRQHandler
RTC_IRQHandler
FLASH_IRQHandler
RCC_CRS_IRQHandler
EXTI0_1_IRQHandler
EXTI2_3_IRQHandler
EXTI4_15_IRQHandler
TSC_IRQHandler
DMA1_Channel1_IRQHandler
DMA1_Channel2_3_IRQHandler
DMA1_Channel4_5_IRQHandler
ADC1_IRQHandler
TIM1_BRK_UP_TRG_COM_IRQHandler
TIM1_CC_IRQHandler
TIM2_IRQHandler
TIM3_IRQHandler
TIM14_IRQHandler
TIM16_IRQHandler
TIM17_IRQHandler
I2C1_IRQHandler
SPI1_IRQHandler
SPI2_IRQHandler
USART1_IRQHandler
USART2_IRQHandler
CEC_CAN_IRQHandler
USB_IRQHandlerB.ENDPALIGN;
*******************************************************************************
;
User Stack and Heap initialization
;
*******************************************************************************
IF:DEF:__MICROLIBEXPORT__initial_sp
EXPORT__heap_base
EXPORT__heap_limitELSEIMPORT__use_two_region_memory
EXPORT__user_initial_stackheap__user_initial_stackheapLDRR0, =Heap_Mem
LDRR1, =(Stack_Mem + Stack_Size)
LDRR2, = (Heap_Mem +Heap_Size)
LDRR3, = Stack_Mem
BXLRALIGNENDIFEND;
************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE*****
#PS:请尊重原创,不喜勿喷
#PS:要转载请注明出处,本人版权所有.
【嵌入式|STM32 启动代码分析】有问题请留言,看到后我会第一时间回复