1 ;先在RAM平分配体系运用的栈,RAM的开端地址为0x2000_0000
2 ;然后在RAM平分配变量运用的堆
3 ;然后在CODE区(flash)分配中止向量表,flash的开端地址为0x0800_0000,该中止向量表就从这个开端地址开端分配
4 ;分配完成后,再界说和完成相应的中止函数,
5 ;一切的中止函数悉数带有[weak]特性,即弱界说,假如编译器发现在别处文件中界说了同名函数,在链接时用别处的地址进行链接。
6 ;中止函数只是完成了Reset_Handler,其他要么是死循环,要么只是界说了函数称号
7
8 ;STM32被设置为从内部FLASH发动时(这也是最常见的一种状况),当STM32遇到复位信号后,
9 ;从0x0800_0000处取出栈顶地址存放于MSP寄存器,从0x0800_0004处取出复位中止服务进口地址放入PC寄存器,
10 ;继而履行复位中止服务程序Reset_Handler,
11 ;Reset_Handler只是履行了两个函数调用,一个是SystemInit,另一个__main,
12 ;SystemInit界说在system_stm32f10x.c中,首要初始化了STM的时钟体系:HSI,HSE,LSI,LSE,PLL,SYSCLK,USBCLK,APECLK等等.
13 ;__main函数由编译器生成,担任初始化栈、堆等,并在最终跳转到用户自界说的main()函数,来到C的国际。
14
15
16 Stack_SizeEQU0x00000400;//界说仓库巨细
17AREASTACK, NOINIT, READWRITE, ALIGN=3;//界说一个数据段 按8字节对齐;AREA 伪指令用于界说一个代码段或数据段 NOINIT:指定此数据段只是保存了内存单元,而没有将各初始值写入内存单元,或许将各个内存单元值初始化为0
18 Stack_MemSPACEStack_Size;//保存Stack_Size巨细的仓库空间 分 配接连 Stack_Size 字节的存储单元并初始化为 0
19 __initial_sp;//标号,代表仓库顶部地址,后边有用
20
21 ; Heap Configuration
22 ;Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
23 ;
24 Heap_SizeEQU0x00000200;//界说堆空间巨细
25AREAHEAP, NOINIT, READWRITE, ALIGN=3;//界说一个数据段,8字节对齐
26 __heap_base;//标号,代表堆末底部地址,后边有用
27 Heap_MemSPACEHeap_Size;//保存Heap_Size的堆空间
28 __heap_limit;//标号,代表堆边界地址,后边有用
29;PRESERVE8 指令指定当时文件坚持仓库八字节对齐。 它设置 PRES8 编译特点以告诉链接器。
30;链接器查看要求仓库八字节对齐的任何代码是否仅由坚持仓库八字节对齐的代码直接或间接地调用。
31PRESERVE8 ;//指示编译器8字节对齐
32THUMB;//指示编译器今后的指令为THUMB指令
33
34 ;中止向量表界说
35 ; Vector Table Mapped to Address 0 at Reset
36AREARESET, DATA, READONLY;//界说只读数据段,其实放在CODE区,坐落0地址
37EXPORT__Vectors;EXPORT:在程序中声明一个大局的标号__Vectors,该标号可在其他的文件中引证
38EXPORT__Vectors_End
39EXPORT__Vectors_Size
40 __VectorsDCD__initial_sp; Top of Stack;给__initial_sp分配4字节32位的地址0x0
41DCDReset_Handler; Reset Handler ; 给标号Reset Handler分配地址为0x00000004
42DCDNMI_Handler; NMI Handler ; 给标号NMI Handler分配地址0x00000008
43DCDHardFault_Handler; Hard Fault Handler
44DCDMemManage_Handler; MPU Fault Handler
45DCDBusFault_Handler; Bus Fault Handler
46DCDUsageFault_Handler; Usage Fault Handler
47DCD0; Reserved; 这种方式便是保存地址,不给任何标号分配
48DCD0; Reserved
49DCD0; Reserved
50DCD0; Reserved
51DCDSVC_Handler; SVCall Handler
52DCDDebugMon_Handler; Debug Monitor Handler
53DCD0; Reserved
54DCDPendSV_Handler; PendSV Handler
55DCDSysTick_Handler; SysTick Handler
56; External Interrupts
57DCDWWDG_IRQHandler; Window Watchdog
58DCDPVD_IRQHandler; PVD through EXTI Line detect
59DCDTAMPER_IRQHandler; Tamper
60DCDRTC_IRQHandler; RTC
61DCDFLASH_IRQHandler; Flash
62DCDRCC_IRQHandler; RCC
63DCDEXTI0_IRQHandler; EXTI Line 0
64DCDEXTI1_IRQHandler; EXTI Line 1
65DCDEXTI2_IRQHandler; EXTI Line 2
66DCDEXTI3_IRQHandler; EXTI Line 3
67DCDEXTI4_IRQHandler; EXTI Line 4
68DCDDMA1_Channel1_IRQHandler; DMA1 Channel 1
69DCDDMA1_Channel2_IRQHandler; DMA1 Channel 2
70DCDDMA1_Channel3_IRQHandler; DMA1 Channel 3
71DCDDMA1_Channel4_IRQHandler; DMA1 Channel 4
72DCDDMA1_Channel5_IRQHandler; DMA1 Channel 5
73DCDDMA1_Channel6_IRQHandler; DMA1 Channel 6
74DCDDMA1_Channel7_IRQHandler; DMA1 Channel 7
75DCDADC1_2_IRQHandler; ADC1 & ADC2
76DCDUSB_HP_CAN1_TX_IRQHandler; USB High Priority or CAN1 TX
77DCDUSB_LP_CAN1_RX0_IRQHandler ; USB LowPriority or CAN1 RX0
78DCDCAN1_RX1_IRQHandler; CAN1 RX1
79DCDCAN1_SCE_IRQHandler; CAN1 SCE
80DCDEXTI9_5_IRQHandler; EXTI Line 9..5
81DCDTIM1_BRK_IRQHandler; TIM1 Break
82DCDTIM1_UP_IRQHandler; TIM1 Update
83DCDTIM1_TRG_COM_IRQHandler; TIM1 Trigger and Commutation
84DCDTIM1_CC_IRQHandler; TIM1 Capture Compare
85DCDTIM2_IRQHandler; TIM2
86DCDTIM3_IRQHandler; TIM3
87DCDTIM4_IRQHandler; TIM4
88DCDI2C1_EV_IRQHandler; I2C1 Event
89DCDI2C1_ER_IRQHandler; I2C1 Error
90DCDI2C2_EV_IRQHandler; I2C2 Event
91DCDI2C2_ER_IRQHandler; I2C2 Error
92DCDSPI1_IRQHandler; SPI1
93DCDSPI2_IRQHandler; SPI2
94DCDUSART1_IRQHandler; USART1
95DCDUSART2_IRQHandler; USART2
96DCDUSART3_IRQHandler; USART3
97DCDEXTI15_10_IRQHandler; EXTI Line 15..10
98DCDRTCAlarm_IRQHandler; RTC Alarm through EXTI Line
99DCDUSBWakeUp_IRQHandler; USB Wakeup from suspend
100DCDTIM8_BRK_IRQHandler; TIM8 Break
101DCDTIM8_UP_IRQHandler; TIM8 Update
102DCDTIM8_TRG_COM_IRQHandler; TIM8 Trigger and Commutation
103DCDTIM8_CC_IRQHandler; TIM8 Capture Compare
104DCDADC3_IRQHandler; ADC3
105DCDFSMC_IRQHandler; FSMC
106DCDSDIO_IRQHandler; SDIO
107DCDTIM5_IRQHandler; TIM5
108DCDSPI3_IRQHandler; SPI3
109DCDUART4_IRQHandler; UART4
110DCDUART5_IRQHandler; UART5
111DCDTIM6_IRQHandler; TIM6
112DCDTIM7_IRQHandler; TIM7
113DCDDMA2_Channel1_IRQHandler; DMA2 Channel1
114DCDDMA2_Channel2_IRQHandler; DMA2 Channel2
115DCDDMA2_Channel3_IRQHandler; DMA2 Channel3
116DCDDMA2_Channel4_5_IRQHandler ; DMA2 Channel4 & Channel5
117 __Vectors_End
118 __Vectors_SizeEQU__Vectors_End – __Vectors
119AREA|.text|, CODE, READONLY ;代码段界说
120
121 ; Reset Handler
122 ;运用PROC、ENDP这一对伪指令把程序段分为若干个进程,使程序的结构加明晰
123 Reset_HandlerPROC;进程的开端
124EXPORTReset_Handler[WEAK];[WEAK] 弱界说,意思是假如在别处也界说该标号(函数),在链接时用别处的地址。
125;假如没有其它定方界说,编译器也不报错,以此处地址进行链接。
126;EXPORT提示编译器该标号可认为外部文件引证。
127IMPORT__main;告诉编译器要运用的标号在其他文件
128IMPORTSystemInit
129LDRR0, =SystemInit
130BLXR0;BX是ARM指令集和THUMB指令集之间程序的跳转
131LDRR0, =__main ;运用“=”表明LDR现在是伪指令不是规范指令。这里是把__main的地址给RO。
132BXR0;BX是ARM指令集和THUMB指令集之间程序的跳转
133ENDP;进程的完毕
134
135 ; Dummy Exception Handlers (infinite loops which can be modified)
136 NMI_HandlerPROC
137EXPORTNMI_Handler[WEAK]
138B.;原地跳转(即无限循环),
139ENDP
140 HardFault_Handler
141PROC
142EXPORTHardFault_Handler[WEAK]
143B.
144ENDP
145 MemManage_Handler
146PROC
147EXPORTMemManage_Handler[WEAK]
148B.
149ENDP
150 BusFault_Handler
151PROC
152EXPORTBusFault_Handler[WEAK]
153B.
154ENDP
155 UsageFault_Handler
156PROC
157EXPORTUsageFault_Handler[WEAK]
158B.
159ENDP
160 SVC_HandlerPROC
161EXPORTSVC_Handler[WEAK]
162B.
163ENDP
164 DebugMon_Handler
165PROC
166EXPORTDebugMon_Handler[WEAK]
167B.
168ENDP
169 PendSV_HandlerPROC
170EXPORTPendSV_Handler[WEAK]
171B.
172ENDP
173 SysTick_Handler PROC
174EXPORTSysTick_Handler[WEAK]
175B.
176ENDP
177 Default_Handler PROC
178EXPORTWWDG_IRQHandler[WEAK]
179EXPORTPVD_IRQHandler[WEAK]
180EXPORTTAMPER_IRQHandler[WEAK]
181EXPORTRTC_IRQHandler[WEAK]
182EXPORTFLASH_IRQHandler[WEAK]
183EXPORTRCC_IRQHandler[WEAK]
184EXPORTEXTI0_IRQHandler[WEAK]
185EXPORTEXTI1_IRQHandler[WEAK]
186EXPORTEXTI2_IRQHandler[WEAK]
187EXPORTEXTI3_IRQHandler[WEAK]
188EXPORTEXTI4_IRQHandler[WEAK]
189EXPORTDMA1_Channel1_IRQHandler[WEAK]
190EXPORTDMA1_Channel2_IRQHandler[WEAK]
191EXPORTDMA1_Channel3_IRQHandler[WEAK]
192EXPORTDMA1_Channel4_IRQHandler[WEAK]
193EXPORTDMA1_Channel5_IRQHandler[WEAK]
194EXPORTDMA1_Channel6_IRQHandler[WEAK]
195EXPORTDMA1_Channel7_IRQHandler[WEAK]
196EXPORTADC1_2_IRQHandler[WEAK]
197EXPORTUSB_HP_CAN1_TX_IRQHandler[WEAK]
198EXPORTUSB_LP_CAN1_RX0_IRQHandler [WEAK]
199EXPORTCAN1_RX1_IRQHandler[WEAK]
200EXPORTCAN1_SCE_IRQHandler[WEAK]
201EXPORTEXTI9_5_IRQHandler[WEAK]
202EXPORTTIM1_BRK_IRQHandler[WEAK]
203EXPORTTIM1_UP_IRQHandler[WEAK]
204EXPORTTIM1_TRG_COM_IRQHandler[WEAK]
205EXPORTTIM1_CC_IRQHandler[WEAK]
206EXPORTTIM2_IRQHandler[WEAK]
207EXPORTTIM3_IRQHandler[WEAK]
208EXPORTTIM4_IRQHandler[WEAK]
209EXPORTI2C1_EV_IRQHandler[WEAK]
210EXPORTI2C1_ER_IRQHandler[WEAK]
211EXPORTI2C2_EV_IRQHandler[WEAK]
212EXPORTI2C2_ER_IRQHandler[WEAK]
213EXPORTSPI1_IRQHandler[WEAK]
214EXPORTSPI2_IRQHandler[WEAK]
215EXPORTUSART1_IRQHandler[WEAK]
216EXPORTUSART2_IRQHandler[WEAK]
217EXPORTUSART3_IRQHandler[WEAK]
218EXPORTEXTI15_10_IRQHandler[WEAK]
219EXPORTRTCAlarm_IRQHandler[WEAK]
220EXPORTUSBWakeUp_IRQHandler[WEAK]
221EXPORTTIM8_BRK_IRQHandler[WEAK]
222EXPORTTIM8_UP_IRQHandler[WEAK]
223EXPORTTIM8_TRG_COM_IRQHandler[WEAK]
224EXPORTTIM8_CC_IRQHandler[WEAK]
225EXPORTADC3_IRQHandler[WEAK]
226EXPORTFSMC_IRQHandler[WEAK]
227EXPORTSDIO_IRQHandler[WEAK]
228EXPORTTIM5_IRQHandler[WEAK]
229EXPORTSPI3_IRQHandler[WEAK]
230EXPORTUART4_IRQHandler[WEAK]
231EXPORTUART5_IRQHandler[WEAK]
232EXPORTTIM6_IRQHandler[WEAK]
233EXPORTTIM7_IRQHandler[WEAK]
234EXPORTDMA2_Channel1_IRQHandler[WEAK]
235EXPORTDMA2_Channel2_IRQHandler[WEAK]
236EXPORTDMA2_Channel3_IRQHandler[WEAK]
237EXPORTDMA2_Channel4_5_IRQHandler [WEAK]
238 WWDG_IRQHandler
239 PVD_IRQHandler
240 TAMPER_IRQHandler
241 RTC_IRQHandler
242 FLASH_IRQHandler
243 RCC_IRQHandler
244 EXTI0_IRQHandler
245 EXTI1_IRQHandler
246 EXTI2_IRQHandler
247 EXTI3_IRQHandler
248 EXTI4_IRQHandler
249 DMA1_Channel1_IRQHandler
250 DMA1_Channel2_IRQHandler
251 DMA1_Channel3_IRQHandler
252 DMA1_Channel4_IRQHandler
253 DMA1_Channel5_IRQHandler
254 DMA1_Channel6_IRQHandler
255 DMA1_Channel7_IRQHandler
256 ADC1_2_IRQHandler
257 USB_HP_CAN1_TX_IRQHandler
258 USB_LP_CAN1_RX0_IRQHandler
259 CAN1_RX1_IRQHandler
260 CAN1_SCE_IRQHandler
261 EXTI9_5_IRQHandler
262 TIM1_BRK_IRQHandler
263 TIM1_UP_IRQHandler
264 TIM1_TRG_COM_IRQHandler
265 TIM1_CC_IRQHandler
266 TIM2_IRQHandler
267 TIM3_IRQHandler
268 TIM4_IRQHandler
269 I2C1_EV_IRQHandler
270 I2C1_ER_IRQHandler
271 I2C2_EV_IRQHandler
272 I2C2_ER_IRQHandler
273 SPI1_IRQHandler
274 SPI2_IRQHandler
275 USART1_IRQHandler
276 USART2_IRQHandler
277 USART3_IRQHandler
278 EXTI15_10_IRQHandler
279 RTCAlarm_IRQHandler
280 USBWakeUp_IRQHandler
281 TIM8_BRK_IRQHandler
282 TIM8_UP_IRQHandler
283 TIM8_TRG_COM_IRQHandler
284 TIM8_CC_IRQHandler
285 ADC3_IRQHandler
286 FSMC_IRQHandler
287 SDIO_IRQHandler
288 TIM5_IRQHandler
289 SPI3_IRQHandler
290 UART4_IRQHandler
291 UART5_IRQHandler
292 TIM6_IRQHandler
293 TIM7_IRQHandler
294 DMA2_Channel1_IRQHandler
295 DMA2_Channel2_IRQHandler
296 DMA2_Channel3_IRQHandler
297 DMA2_Channel4_5_IRQHandler
298B.
299ENDP
300ALIGN ;填充字节使地址对齐
301 ;*******************************************************************************
302 ; User Stack and Heap initialization
303 ;*******************************************************************************
304 ;堆和栈的初始化
305IF:DEF:__MICROLIB ;“DEF”的用法——:DEF:X 便是说X界说了则为真,否则为假
306;假如界说了MICORLIB,
307EXPORT__initial_sp;则将栈顶地址,
308EXPORT__heap_base;堆开端地址赋予大局特点,
309EXPORT__heap_limit;堆结尾边界地址赋予大局特点,使外部程序可调用
310
311ELSE;假如没界说__MICROLIB,则运用默许的C运行时库
312
313IMPORT__use_two_region_memory;;告诉编译器要运用的标号在其他文件__use_two_region_memory
314EXPORT__user_initial_stackheap ;声明大局标号__user_initial_stackheap,这样外程序也可调用此标号
315;则进行仓库和堆的赋值,在__main函数履行进程中调用
316
317;假如运用默许的C库,程序发动进程中就不会履行该标号下的代码
318 __user_initial_stackheap;标号__user_initial_stackheap,表明用户仓库初始化程序进口
319;//则进行仓库和堆的赋值,在__main函数履行进程中调用。
320LDRR0, =Heap_Mem;保存堆始地址
321LDRR1, =(Stack_Mem + Stack_Size) ;保存栈的巨细
322LDRR2, = (Heap_Mem +Heap_Size);保存堆的巨细
323LDRR3, = Stack_Mem;保存栈顶指针
324BXLR
325ALIGN;填充字节使地址对齐
326
327ENDIF
328
329END
声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/qiche/xinnengyuan/257573.html