startup_stm32f10x_hd.s是一个启动文件里面,是使用语言写的基本程序,当STM32上电启动的时候,会看这里的语言把这个程序,运行起来建立起来C,所以我们使用文件的原因启动文件。改文件使用的原因是Cortex-M3内核支持的指令,参考《Cortex-M3权威指南中文》内指令集章节
startup_stm32f10x_hd.s文件是ST官方提供的,该文件可以从KEIL5安装目录中找到,也可以从ST库里面找到,找到该文件后吧启动文件添加到工程里面。不同型号的芯片以及不同编译环境使用的汇编文件是不一样的,但功能相同。
对于启动文件部分,我们主要总结功能,主要功能如下:
- 突发火花SP
- 初始化程序执行PC
- 设置堆、栈的大小
- 设置中断表的入口地址
- 配置外部 SRAM 成为数据
- 调用 SystemInit() 函数 STM32 的系统目录配置
- 设置C库分支的入口“__main”(最后调用main函数)
Reset_Hander
; Reset handler ; 汇编里面注释用的是";",相当于 C 语言的 “//” 注释符 2 Reset_Handler PROC ;PROC 是子程序定义伪指令。这里相当于 C 语言定义了一个函数为 Reset_Handler 3 EXPORT Reset_Handler [WEAK] ;EXPORT 表示 Reset_Handler 这个子程序可供其他模块调用,相当于C的函数声明;[WEAK]表示弱定义 4 IMPORT __main ;IMPORT 说明 __main 这个标号在其他文件,在链接时候需去其他文件中寻找。相当于c中引入函数声明 5 IMPORT SystemInit 6 LDR R0, =SystemInit ;把 SystemInit 的地址加载到寄存器 R0 中 7 BLX R0 ;程序跳转到 R0 中地址执行程序,即执行 SystemInit 函数内容 8 LDR R0, =__main ;把 __main 的地址加载到寄存器 R0 9 BX R0 ;程序跳转到 R0 中地址执行程序,即执行 __main 函数,执行完毕后即可进入 main 函数10 ENDP
下面是startup_stm32f10x_hd.s源代码
;******************** (C) COPYRIGHT 2011 STMicroelectronics ******************** 2 ;* File Name : startup_stm32f10x_hd.s 3 ;* Author : MCD Application Team 4 ;* Version : V3.5.0 5 ;* Date : 11-March-2011 6 ;* Description : STM32F10x High Density Devices vector table for MDK-ARM 7 ;* toolchain. 8 ;* This module performs: 9 ;* - Set the initial SP 10 ;* - Set the initial PC == Reset_Handler 11 ;* - Set the vector table entries with the exceptions ISR address 12 ;* - Configure the clock system and also configure the external 13 ;* SRAM mounted on STM3210E-EVAL board to be used as data 14 ;* memory (optional, to be enabled by user) 15 ;* - Branches to __main in the C library (which eventually 16 ;* calls main()). 17 ;* After Reset the CortexM3 processor is in Thread mode, 18 ;* priority is Privileged, and the Stack is set to Main. 19 ;* <<< Use Configuration Wizard in Context Menu >>> 20 ;******************************************************************************* 21 ; THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 22 ; WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 23 ; AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 24 ; INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 25 ; CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 26 ; INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 27 ;******************************************************************************* 28 29 ; Amount of memory (in bytes) allocated for Stack 30 ; Tailor this value to your application needs 31 ;
Stack Configuration 32 ; Stack Size (in Bytes) <0x0-0xFFFFFFFF:8> 33 ; 34 35 Stack_Size EQU 0x00000400 36 37 AREA STACK, NOINIT, READWRITE, ALIGN=3 38 Stack_Mem SPACE Stack_Size 39 __initial_sp 40 41 ;
Heap Configuration 42 ; Heap Size (in Bytes) <0x0-0xFFFFFFFF:8> 43 ; 44 45 Heap_Size EQU 0x00000200 46 47 AREA HEAP, NOINIT, READWRITE, ALIGN=3 48 __heap_base 49 Heap_Mem SPACE Heap_Size 50 __heap_limit 51 52 PRESERVE8 53 THUMB 54 55 56 ; Vector Table Mapped to Address 0 at Reset 57 AREA RESET, DATA, READONLY 58 EXPORT __Vectors 59 EXPORT __Vectors_End 60 EXPORT __Vectors_Size 61 62 __Vectors DCD __initial_sp ; Top of Stack 63 DCD Reset_Handler ; Reset Handler 64 DCD NMI_Handler ; NMI Handler 65 DCD HardFault_Handler ; Hard Fault Handler 66 DCD MemManage_Handler ; MPU Fault Handler 67 DCD BusFault_Handler ; Bus Fault Handler 68 DCD UsageFault_Handler ; Usage Fault Handler 69 DCD 0 ; Reserved 70 DCD 0 ; Reserved 71 DCD 0 ; Reserved 72 DCD 0 ; Reserved 73 DCD SVC_Handler ; SVCall Handler 74 DCD DebugMon_Handler ; Debug Monitor Handler 75 DCD 0 ; Reserved 76 DCD PendSV_Handler ; PendSV Handler 77 DCD SysTick_Handler ; SysTick Handler 78 79 ; External Interrupts 80 DCD WWDG_IRQHandler ; Window Watchdog 81 DCD PVD_IRQHandler ; PVD through EXTI Line detect 82 DCD TAMPER_IRQHandler ; Tamper 83 DCD RTC_IRQHandler ; RTC 84 DCD FLASH_IRQHandler ; Flash 85 DCD RCC_IRQHandler ; RCC 86 DCD EXTI0_IRQHandler ; EXTI Line 0 87 DCD EXTI1_IRQHandler ; EXTI Line 1 88 DCD EXTI2_IRQHandler ; EXTI Line 2 89 DCD EXTI3_IRQHandler ; EXTI Line 3 90 DCD EXTI4_IRQHandler ; EXTI Line 4 91 DCD DMA1_Channel1_IRQHandler ; DMA1 Channel 1 92 DCD DMA1_Channel2_IRQHandler ; DMA1 Channel 2 93 DCD DMA1_Channel3_IRQHandler ; DMA1 Channel 3 94 DCD DMA1_Channel4_IRQHandler ; DMA1 Channel 4 95 DCD DMA1_Channel5_IRQHandler ; DMA1 Channel 5 96 DCD DMA1_Channel6_IRQHandler ; DMA1 Channel 6 97 DCD DMA1_Channel7_IRQHandler ; DMA1 Channel 7 98 DCD ADC1_2_IRQHandler ; ADC1 & ADC2 99 DCD USB_HP_CAN1_TX_IRQHandler ; USB High Priority or CAN1 TX100 DCD USB_LP_CAN1_RX0_IRQHandler ; USB Low Priority or CAN1 RX0101 DCD CAN1_RX1_IRQHandler ; CAN1 RX1102 DCD CAN1_SCE_IRQHandler ; CAN1 SCE103 DCD EXTI9_5_IRQHandler ; EXTI Line 9..5104 DCD TIM1_BRK_IRQHandler ; TIM1 Break105 DCD TIM1_UP_IRQHandler ; TIM1 Update106 DCD TIM1_TRG_COM_IRQHandler ; TIM1 Trigger and Commutation107 DCD TIM1_CC_IRQHandler ; TIM1 Capture Compare108 DCD TIM2_IRQHandler ; TIM2109 DCD TIM3_IRQHandler ; TIM3110 DCD TIM4_IRQHandler ; TIM4111 DCD I2C1_EV_IRQHandler ; I2C1 Event112 DCD I2C1_ER_IRQHandler ; I2C1 Error113 DCD I2C2_EV_IRQHandler ; I2C2 Event114 DCD I2C2_ER_IRQHandler ; I2C2 Error115 DCD SPI1_IRQHandler ; SPI1116 DCD SPI2_IRQHandler ; SPI2117 DCD USART1_IRQHandler ; USART1118 DCD USART2_IRQHandler ; USART2119 DCD USART3_IRQHandler ; USART3120 DCD EXTI15_10_IRQHandler ; EXTI Line 15..10121 DCD RTCAlarm_IRQHandler ; RTC Alarm through EXTI Line122 DCD USBWakeUp_IRQHandler ; USB Wakeup from suspend123 DCD TIM8_BRK_IRQHandler ; TIM8 Break124 DCD TIM8_UP_IRQHandler ; TIM8 Update125 DCD TIM8_TRG_COM_IRQHandler ; TIM8 Trigger and Commutation126 DCD TIM8_CC_IRQHandler ; TIM8 Capture Compare127 DCD ADC3_IRQHandler ; ADC3128 DCD FSMC_IRQHandler ; FSMC129
startup_stm32f10x_hd.s是一个启动文件里面,是使用语言写的基本程序,当STM32上电启动的时候,会看这里的语言把这个程序,运行起来建立起来C,所以我们使用文件的原因启动文件。改文件使用的原因是Cortex-M3内核支持的指令,参考《Cortex-M3权威指南中文》内指令集章节
startup_stm32f10x_hd.s文件是ST官方提供的,该文件可以从KEIL5安装目录中找到,也可以从ST库里面找到,找到该文件后吧启动文件添加到工程里面。不同型号的芯片以及不同编译环境使用的汇编文件是不一样的,但功能相同。
对于启动文件部分,我们主要总结功能,主要功能如下:
- 突发火花SP
- 初始化程序执行PC
- 设置堆、栈的大小
- 设置中断表的入口地址
- 配置外部 SRAM 成为数据
- 调用 SystemInit() 函数 STM32 的系统目录配置
- 设置C库分支的入口“__main”(最后调用main函数)
Reset_Hander
; Reset handler ; 汇编里面注释用的是";",相当于 C 语言的 “//” 注释符 2 Reset_Handler PROC ;PROC 是子程序定义伪指令。这里相当于 C 语言定义了一个函数为 Reset_Handler 3 EXPORT Reset_Handler [WEAK] ;EXPORT 表示 Reset_Handler 这个子程序可供其他模块调用,相当于C的函数声明;[WEAK]表示弱定义 4 IMPORT __main ;IMPORT 说明 __main 这个标号在其他文件,在链接时候需去其他文件中寻找。相当于c中引入函数声明 5 IMPORT SystemInit 6 LDR R0, =SystemInit ;把 SystemInit 的地址加载到寄存器 R0 中 7 BLX R0 ;程序跳转到 R0 中地址执行程序,即执行 SystemInit 函数内容 8 LDR R0, =__main ;把 __main 的地址加载到寄存器 R0 9 BX R0 ;程序跳转到 R0 中地址执行程序,即执行 __main 函数,执行完毕后即可进入 main 函数10 ENDP
下面是startup_stm32f10x_hd.s源代码
;******************** (C) COPYRIGHT 2011 STMicroelectronics ******************** 2 ;* File Name : startup_stm32f10x_hd.s 3 ;* Author : MCD Application Team 4 ;* Version : V3.5.0 5 ;* Date : 11-March-2011 6 ;* Description : STM32F10x High Density Devices vector table for MDK-ARM 7 ;* toolchain. 8 ;* This module performs: 9 ;* - Set the initial SP 10 ;* - Set the initial PC == Reset_Handler 11 ;* - Set the vector table entries with the exceptions ISR address 12 ;* - Configure the clock system and also configure the external 13 ;* SRAM mounted on STM3210E-EVAL board to be used as data 14 ;* memory (optional, to be enabled by user) 15 ;* - Branches to __main in the C library (which eventually 16 ;* calls main()). 17 ;* After Reset the CortexM3 processor is in Thread mode, 18 ;* priority is Privileged, and the Stack is set to Main. 19 ;* <<< Use Configuration Wizard in Context Menu >>> 20 ;******************************************************************************* 21 ; THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS 22 ; WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. 23 ; AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 24 ; INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE 25 ; CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING 26 ; INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. 27 ;******************************************************************************* 28 29 ; Amount of memory (in bytes) allocated for Stack 30 ; Tailor this value to your application needs 31 ;
Stack Configuration 32 ; Stack Size (in Bytes) <0x0-0xFFFFFFFF:8> 33 ; 34 35 Stack_Size EQU 0x00000400 36 37 AREA STACK, NOINIT, READWRITE, ALIGN=3 38 Stack_Mem SPACE Stack_Size 39 __initial_sp 40 41 ;
Heap Configuration 42 ; Heap Size (in Bytes) <0x0-0xFFFFFFFF:8> 43 ; 44 45 Heap_Size EQU 0x00000200 46 47 AREA HEAP, NOINIT, READWRITE, ALIGN=3 48 __heap_base 49 Heap_Mem SPACE Heap_Size 50 __heap_limit 51 52 PRESERVE8 53 THUMB 54 55 56 ; Vector Table Mapped to Address 0 at Reset 57 AREA RESET, DATA, READONLY 58 EXPORT __Vectors 59 EXPORT __Vectors_End 60 EXPORT __Vectors_Size 61 62 __Vectors DCD __initial_sp ; Top of Stack 63 DCD Reset_Handler ; Reset Handler 64 DCD NMI_Handler ; NMI Handler 65 DCD HardFault_Handler ; Hard Fault Handler 66 DCD MemManage_Handler ; MPU Fault Handler 67 DCD BusFault_Handler ; Bus Fault Handler 68 DCD UsageFault_Handler ; Usage Fault Handler 69 DCD 0 ; Reserved 70 DCD 0 ; Reserved 71 DCD 0 ; Reserved 72 DCD 0 ; Reserved 73 DCD SVC_Handler ; SVCall Handler 74 DCD DebugMon_Handler ; Debug Monitor Handler 75 DCD 0 ; Reserved 76 DCD PendSV_Handler ; PendSV Handler 77 DCD SysTick_Handler ; SysTick Handler 78 79 ; External Interrupts 80 DCD WWDG_IRQHandler ; Window Watchdog 81 DCD PVD_IRQHandler ; PVD through EXTI Line detect 82 DCD TAMPER_IRQHandler ; Tamper 83 DCD RTC_IRQHandler ; RTC 84 DCD FLASH_IRQHandler ; Flash 85 DCD RCC_IRQHandler ; RCC 86 DCD EXTI0_IRQHandler ; EXTI Line 0 87 DCD EXTI1_IRQHandler ; EXTI Line 1 88 DCD EXTI2_IRQHandler ; EXTI Line 2 89 DCD EXTI3_IRQHandler ; EXTI Line 3 90 DCD EXTI4_IRQHandler ; EXTI Line 4 91 DCD DMA1_Channel1_IRQHandler ; DMA1 Channel 1 92 DCD DMA1_Channel2_IRQHandler ; DMA1 Channel 2 93 DCD DMA1_Channel3_IRQHandler ; DMA1 Channel 3 94 DCD DMA1_Channel4_IRQHandler ; DMA1 Channel 4 95 DCD DMA1_Channel5_IRQHandler ; DMA1 Channel 5 96 DCD DMA1_Channel6_IRQHandler ; DMA1 Channel 6 97 DCD DMA1_Channel7_IRQHandler ; DMA1 Channel 7 98 DCD ADC1_2_IRQHandler ; ADC1 & ADC2 99 DCD USB_HP_CAN1_TX_IRQHandler ; USB High Priority or CAN1 TX100 DCD USB_LP_CAN1_RX0_IRQHandler ; USB Low Priority or CAN1 RX0101 DCD CAN1_RX1_IRQHandler ; CAN1 RX1102 DCD CAN1_SCE_IRQHandler ; CAN1 SCE103 DCD EXTI9_5_IRQHandler ; EXTI Line 9..5104 DCD TIM1_BRK_IRQHandler ; TIM1 Break105 DCD TIM1_UP_IRQHandler ; TIM1 Update106 DCD TIM1_TRG_COM_IRQHandler ; TIM1 Trigger and Commutation107 DCD TIM1_CC_IRQHandler ; TIM1 Capture Compare108 DCD TIM2_IRQHandler ; TIM2109 DCD TIM3_IRQHandler ; TIM3110 DCD TIM4_IRQHandler ; TIM4111 DCD I2C1_EV_IRQHandler ; I2C1 Event112 DCD I2C1_ER_IRQHandler ; I2C1 Error113 DCD I2C2_EV_IRQHandler ; I2C2 Event114 DCD I2C2_ER_IRQHandler ; I2C2 Error115 DCD SPI1_IRQHandler ; SPI1116 DCD SPI2_IRQHandler ; SPI2117 DCD USART1_IRQHandler ; USART1118 DCD USART2_IRQHandler ; USART2119 DCD USART3_IRQHandler ; USART3120 DCD EXTI15_10_IRQHandler ; EXTI Line 15..10121 DCD RTCAlarm_IRQHandler ; RTC Alarm through EXTI Line122 DCD USBWakeUp_IRQHandler ; USB Wakeup from suspend123 DCD TIM8_BRK_IRQHandler ; TIM8 Break124 DCD TIM8_UP_IRQHandler ; TIM8 Update125 DCD TIM8_TRG_COM_IRQHandler ; TIM8 Trigger and Commutation126 DCD TIM8_CC_IRQHandler ; TIM8 Capture Compare127 DCD ADC3_IRQHandler ; ADC3128 DCD FSMC_IRQHandler ; FSMC129
举报