<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁 > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > STM32啟動(dòng)文件詳解及SystemInit函數(shù)分析

          STM32啟動(dòng)文件詳解及SystemInit函數(shù)分析

          作者: 時(shí)間:2016-11-27 來源:網(wǎng)絡(luò) 收藏
          1 ;先在RAM中分配系統(tǒng)使用的棧,RAM的起始地址為0x2000_0000
          2 ;然后在RAM中分配變量使用的堆
          3 ;然后在CODE區(qū)(flash)分配中斷向量表,flash的起始地址為0x0800_0000,該中斷向量表就從這個(gè)起始地址開始分配
          4 ;分配完成后,再定義和實(shí)現(xiàn)相應(yīng)的中斷函數(shù),
          5 ;所有的中斷函數(shù)全部帶有[weak]特性,即弱定義,如果編譯器發(fā)現(xiàn)在別處文件中定義了同名函數(shù),在鏈接時(shí)用別處的地址進(jìn)行鏈接。
          6 ;中斷函數(shù)僅僅實(shí)現(xiàn)了Reset_Handler,其他要么是死循環(huán),要么僅僅定義了函數(shù)名稱
          7
          8 ;STM32被設(shè)置為從內(nèi)部FLASH啟動(dòng)時(shí)(這也是最常見的一種情況),當(dāng)STM32遇到復(fù)位信號(hào)后,
          9 ;從0x0800_0000處取出棧頂?shù)刂反娣庞贛SP寄存器,從0x0800_0004處取出復(fù)位中斷服務(wù)入口地址放入PC寄存器,
          10 ;繼而執(zhí)行復(fù)位中斷服務(wù)程序Reset_Handler,
          11 ;Reset_Handler僅僅執(zhí)行了兩個(gè)函數(shù)調(diào)用,一個(gè)是SystemInit,另一個(gè)__main,
          12 ;SystemInit定義在system_stm32f10x.c中,主要初始化了STM的時(shí)鐘系統(tǒng):HSI,HSE,LSI,LSE,PLL,SYSCLK,USBCLK,APECLK等等.
          13 ;__main函數(shù)由編譯器生成,負(fù)責(zé)初始化棧、堆等,并在最后跳轉(zhuǎn)到用戶自定義的main()函數(shù),來到C的世界。
          14
          15
          16 Stack_SizeEQU0x00000400;//定義堆棧大小
          17AREASTACK, NOINIT, READWRITE, ALIGN=3;//定義一個(gè)數(shù)據(jù)段 按8字節(jié)對(duì)齊;AREA 偽指令用于定義一個(gè)代碼段或數(shù)據(jù)段 NOINIT:指定此數(shù)據(jù)段僅僅保留了內(nèi)存單元,而沒有將各初始值寫入內(nèi)存單元,或者將各個(gè)內(nèi)存單元值初始化為0
          18 Stack_MemSPACEStack_Size;//保留Stack_Size大小的堆棧空間 分 配連續(xù) Stack_Size 字節(jié)的存儲(chǔ)單元并初始化為 0
          19 __initial_sp;//標(biāo)號(hào),代表堆棧頂部地址,后面有用
          20
          21 ; Heap Configuration
          22 ;Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
          23 ;
          24 Heap_SizeEQU0x00000200;//定義堆空間大小
          25AREAHEAP, NOINIT, READWRITE, ALIGN=3;//定義一個(gè)數(shù)據(jù)段,8字節(jié)對(duì)齊
          26 __heap_base;//標(biāo)號(hào),代表堆末底部地址,后面有用
          27 Heap_MemSPACEHeap_Size;//保留Heap_Size的堆空間
          28 __heap_limit;//標(biāo)號(hào),代表堆界限地址,后面有用
          29;PRESERVE8 指令指定當(dāng)前文件保持堆棧八字節(jié)對(duì)齊。 它設(shè)置 PRES8 編譯屬性以通知鏈接器。
          30;鏈接器檢查要求堆棧八字節(jié)對(duì)齊的任何代碼是否僅由保持堆棧八字節(jié)對(duì)齊的代碼直接或間接地調(diào)用。
          31PRESERVE8 ;//指示編譯器8字節(jié)對(duì)齊
          32THUMB;//指示編譯器以后的指令為THUMB指令
          33
          34 ;中斷向量表定義
          35 ; Vector Table Mapped to Address 0 at Reset
          36AREARESET, DATA, READONLY;//定義只讀數(shù)據(jù)段,其實(shí)放在CODE區(qū),位于0地址
          37EXPORT__Vectors;EXPORT:在程序中聲明一個(gè)全局的標(biāo)號(hào)__Vectors,該標(biāo)號(hào)可在其他的文件中引用
          38EXPORT__Vectors_End
          39EXPORT__Vectors_Size
          40 __VectorsDCD__initial_sp; Top of Stack;給__initial_sp分配4字節(jié)32位的地址0x0
          41DCDReset_Handler; Reset Handler ; 給標(biāo)號(hào)Reset Handler分配地址為0x00000004
          42DCDNMI_Handler; NMI Handler ; 給標(biāo)號(hào)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; 這種形式就是保留地址,不給任何標(biāo)號(hào)分配
          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這一對(duì)偽指令把程序段分為若干個(gè)過程,使程序的結(jié)構(gòu)加清晰
          123 Reset_HandlerPROC;過程的開始
          124EXPORTReset_Handler[WEAK];[WEAK] 弱定義,意思是如果在別處也定義該標(biāo)號(hào)(函數(shù)),在鏈接時(shí)用別處的地址。
          125;如果沒有其它定方定義,編譯器也不報(bào)錯(cuò),以此處地址進(jìn)行鏈接。
          126;EXPORT提示編譯器該標(biāo)號(hào)可以為外部文件引用。
          127IMPORT__main;通知編譯器要使用的標(biāo)號(hào)在其他文件
          128IMPORTSystemInit
          129LDRR0, =SystemInit
          130BLXR0;BX是ARM指令集和THUMB指令集之間程序的跳轉(zhuǎn)
          131LDRR0, =__main ;使用“=”表示LDR目前是偽指令不是標(biāo)準(zhǔn)指令。這里是把__main的地址給RO。
          132BXR0;BX是ARM指令集和THUMB指令集之間程序的跳轉(zhuǎn)
          133ENDP;過程的結(jié)束
          134
          135 ; Dummy Exception Handlers (infinite loops which can be modified)
          136 NMI_HandlerPROC
          137EXPORTNMI_Handler[WEAK]
          138B.;原地跳轉(zhuǎn)(即無限循環(huán)),
          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 ;填充字節(jié)使地址對(duì)齊
          301 ;*******************************************************************************
          302 ; User Stack and Heap initialization
          303 ;*******************************************************************************
          304 ;堆和棧的初始化
          305IF:DEF:__MICROLIB ;“DEF”的用法——:DEF:X 就是說X定義了則為真,否則為假
          306;如果定義了MICORLIB,
          307EXPORT__initial_sp;則將棧頂?shù)刂罚?br />308EXPORT__heap_base;堆起始地址賦予全局屬性,
          309EXPORT__heap_limit;堆末端界限地址賦予全局屬性,使外部程序可調(diào)用
          310
          311ELSE;如果沒定義__MICROLIB,則使用默認(rèn)的C運(yùn)行時(shí)庫
          312
          313IMPORT__use_two_region_memory;;通知編譯器要使用的標(biāo)號(hào)在其他文件__use_two_region_memory
          314EXPORT__user_initial_stackheap ;聲明全局標(biāo)號(hào)__user_initial_stackheap,這樣外程序也可調(diào)用此標(biāo)號(hào)
          315;則進(jìn)行堆棧和堆的賦值,在__main函數(shù)執(zhí)行過程中調(diào)用
          316
          317;如果使用默認(rèn)的C庫,程序啟動(dòng)過程中就不會(huì)執(zhí)行該標(biāo)號(hào)下的代碼
          318 __user_initial_stackheap;標(biāo)號(hào)__user_initial_stackheap,表示用戶堆棧初始化程序入口
          319;//則進(jìn)行堆棧和堆的賦值,在__main函數(shù)執(zhí)行過程中調(diào)用。
          320LDRR0, =Heap_Mem;保存堆始地址
          321LDRR1, =(Stack_Mem + Stack_Size) ;保存棧的大小
          322LDRR2, = (Heap_Mem +Heap_Size);保存堆的大小
          323LDRR3, = Stack_Mem;保存棧頂指針
          324BXLR
          325ALIGN;填充字節(jié)使地址對(duì)齊
          326
          327ENDIF
          328
          329END


          評(píng)論


          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();