前情提要
上一篇文章記錄了一下如何創(chuàng)建GD32E503的BSP。但由于時(shí)間關(guān)系只實(shí)現(xiàn)了MDK版本的工程模板,后面如果需要提交BSP時(shí)再去補(bǔ)全I(xiàn)AR版本的。但對(duì)于我個(gè)人而言,IAR只在讀書時(shí)玩藍(lán)牙開發(fā)的時(shí)候用過(guò),而MDK雖然用的比較多但最近幾年也很少用了。感覺(jué)還是VSCode等編輯器用起來(lái)更舒服一些,而對(duì)于RTT系統(tǒng)的開發(fā),我個(gè)人還是更傾向于使用官方的RTThreadStudioIDE進(jìn)行開發(fā)。于是今天想想辦法怎么移到RTTStudio上去。
面臨的問(wèn)題
-
上篇文章已經(jīng)發(fā)現(xiàn),目前官方的固件庫(kù)竟然沒(méi)有GCC版本的啟動(dòng)文件,所以要想辦法弄個(gè)啟動(dòng)文件
-
RTTStudio自帶的GCC編譯器版本太老,不支持編譯M33內(nèi)核,所以要升級(jí)GCC
-
計(jì)劃用開源的DAP調(diào)試器進(jìn)行調(diào)試,但同樣RTTStudio自帶的pyocd調(diào)試工具版本太老,需要升級(jí)
添加GCC版本的啟動(dòng)文件
拷貝啟動(dòng)文件模板
從GD32F4xx固件包內(nèi)把GCC文件夾拷貝到新添加的GDE50x固件包的對(duì)應(yīng)位置,并把匯編文件名稱修改為gd32e50x的,注意,GD32E50x分了高密度版(hd)和互聯(lián)版(cl),我這里暫且只修改了一份我用到的高密度版本的。cl版本的也類似修改即可。
修改啟動(dòng)文件
眾所周知,匯編的啟動(dòng)文件要干的事情就是做一些芯片啟動(dòng)的前期初始化工作,搭建C代碼的運(yùn)行環(huán)境。所以這里也并不需要對(duì)照匯編指令,把每條語(yǔ)句的功能都搞明白,只需大致了解一下即可。一眼望去,感覺(jué)這個(gè)匯編文件主要做了三大事情。
第一,定義中斷向量;
第二,定義啟動(dòng)入口;
第三,聲明中斷函數(shù)。
而啟動(dòng)入口相關(guān)的不用修改,都是先調(diào)用SystemInit函數(shù)做一些時(shí)鐘等基礎(chǔ)初始化,然后再調(diào)用entry或者main函數(shù)執(zhí)行后續(xù)的代碼。
所以這里主要修改的就是中斷向量的定義和中斷函數(shù)的聲明,按照armcc版本的進(jìn)行修改即可:
1;*Copyright(c)2006-2021,RT-ThreadDevelopmentTeam 2;* 3;*SPDX-License-Identifier:Apache-2.0 4;* 5;*ChangeLogs: 6;*DateAuthorNotes 7;*2018-05-22tanekfirstimplementation 8;*/ 9.syntaxunified 10.cpucortex-m33 11.fpusoftvfp 12.thumb 13.globalg_pfnVectors 14.globalDefault_Handler 15.section.isr_vector,"a",%progbits 16.typeg_pfnVectors,%object 17g_pfnVectors: 18.word_estack//TopofStack 19.wordReset_Handler//ResetHandler 20.wordNMI_Handler//NMIHandler 21.wordHardFault_Handler//HardFaultHandler 22.wordMemManage_Handler//MPUFaultHandler 23.wordBusFault_Handler//BusFaultHandler 24.wordUsageFault_Handler//UsageFaultHandler 25.word0//Reserved 26.word0//Reserved 27.word0//Reserved 28.word0//Reserved 29.wordSVC_Handler//SVCallHandler 30.wordDebugMon_Handler//DebugMonitorHandler 31.word0//Reserved 32.wordPendSV_Handler//PendSVHandler 33.wordSysTick_Handler//SysTickHandler 34//externalinterruptshandler 35.wordWWDGT_IRQHandler//16:WindowWatchdogTimer 36.wordLVD_IRQHandler//17:LVDthroughEXTILinedetect 37.wordTAMPER_IRQHandler//18:TamperthroughEXTILinedetect 38.wordRTC_IRQHandler//19:RTCthroughEXTILine 39.wordFMC_IRQHandler//20:FMC 40.wordRCU_CTC_IRQHandler//21:RCUandCTC 41.wordEXTI0_IRQHandler//22:EXTILine0 42.wordEXTI1_IRQHandler//23:EXTILine1 43.wordEXTI2_IRQHandler//24:EXTILine2 44.wordEXTI3_IRQHandler//25:EXTILine3 45.wordEXTI4_IRQHandler//26:EXTILine4 46.wordDMA0_Channel0_IRQHandler//27:DMA0Channel0 47.wordDMA0_Channel1_IRQHandler//28:DMA0Channel1 48.wordDMA0_Channel2_IRQHandler//29:DMA0Channel2 49.wordDMA0_Channel3_IRQHandler//30:DMA0Channel3 50.wordDMA0_Channel4_IRQHandler//31:DMA0Channel4 51.wordDMA0_Channel5_IRQHandler//32:DMA0Channel5 52.wordDMA0_Channel6_IRQHandler//33:DMA0Channel6 53.wordADC0_1_IRQHandler//34:ADC0andADC1 54.wordUSBD_HP_CAN0_TX_IRQHandler//35:USBDHPorCAN0TX 55.wordUSBD_LP_CAN0_RX0_IRQHandler//36:USBDLPorCAN0RX0 56.wordCAN0_RX1_IRQHandler//37:CAN0RX1 57.wordCAN0_EWMC_IRQHandler//38:CAN0EWMC 58.wordEXTI5_9_IRQHandler//39:EXTI5toEXTI9 59.wordTIMER0_BRK_TIMER8_IRQHandler//40:TIMER0BreakandTIMER8 60.wordTIMER0_UP_TIMER9_IRQHandler//41:TIMER0UpdateandTIMER9 61.wordTIMER0_TRG_CMT_TIMER10_IRQHandler//42:TIMER0TriggerandCommutationandTIMER10 62.wordTIMER0_Channel_IRQHandler//43:TIMER0ChannelCaptureCompare 63.wordTIMER1_IRQHandler//44:TIMER1 64.wordTIMER2_IRQHandler//45:TIMER2 65.wordTIMER3_IRQHandler//46:TIMER3 66.wordI2C0_EV_IRQHandler//47:I2C0Event 67.wordI2C0_ER_IRQHandler//48:I2C0Error 68.wordI2C1_EV_IRQHandler//49:I2C1Event 69.wordI2C1_ER_IRQHandler//50:I2C1Error 70.wordSPI0_IRQHandler//51:SPI0 71.wordSPI1_I2S1ADD_IRQHandler//52:SPI1orI2S1ADD 72.wordUSART0_IRQHandler//53:USART0 73.wordUSART1_IRQHandler//54:USART1 74.wordUSART2_IRQHandler//55:USART2 75.wordEXTI10_15_IRQHandler//56:EXTI10toEXTI15 76.wordRTC_Alarm_IRQHandler//57:RTCAlarm 77.wordUSBD_WKUP_IRQHandler//58:USBDWakeup 78.wordTIMER7_BRK_TIMER11_IRQHandler//59:TIMER7BreakandTIMER11 79.wordTIMER7_UP_TIMER12_IRQHandler//60:TIMER7UpdateandTIMER12 80.wordTIMER7_TRG_CMT_TIMER13_IRQHandler//61:TIMER7TriggerandCommutationandTIMER13 81.wordTIMER7_Channel_IRQHandler//62:TIMER7ChannelCompare 82.wordADC2_IRQHandler//63:ADC2 83.wordEXMC_IRQHandler//64:EXMC 84.wordSDIO_IRQHandler//65:SDIO 85.wordTIMER4_IRQHandler//66:TIMER4 86.wordSPI2_I2S2ADD_IRQHandler//67:SPI2orI2S2ADD 87.wordUART3_IRQHandler//68:UART3 88.wordUART4_IRQHandler//69:UART4 89.wordTIMER5_DAC_IRQHandler//70:TIMER5andDAC0DAC1Underrunerror 90.wordTIMER6_IRQHandler//71:TIMER6 91.wordDMA1_Channel0_IRQHandler//72:DMA1Channel0 92.wordDMA1_Channel1_IRQHandler//73:DMA1Channel1 93.wordDMA1_Channel2_IRQHandler//74:DMA1Channel2 94.wordDMA1_Channel3_4_IRQHandler//75:DMA1Channel3andChannel4 95.word0//76:Reserved 96.word0//77:Reserved 97.word0//78:Reserved 98.wordCAN1_TX_IRQHandler//79:CAN1TX 99.wordCAN1_RX0_IRQHandler//80:CAN1RX0 100.wordCAN1_RX1_IRQHandler//81:CAN1RX1 101.wordCAN1_EWMC_IRQHandler//82:CAN1EWMC 102.word0//83:Reserved 103.word0//84:Reserved 104.wordSHRTIMER_IRQ2_IRQHandler//85:SHRTIMERIRQ2 105.wordSHRTIMER_IRQ3_IRQHandler//86:SHRTIMERIRQ3 106.wordSHRTIMER_IRQ4_IRQHandler//87:SHRTIMERIRQ4 107.wordSHRTIMER_IRQ5_IRQHandler//88:SHRTIMERIRQ5 108.wordSHRTIMER_IRQ6_IRQHandler//89:SHRTIMERIRQ6 109.word0//90:Reserved 110.word0//91:Reserved 111.wordSHRTIMER_IRQ0_IRQHandler//92:SHRTIMERIRQ0 112.wordSHRTIMER_IRQ1_IRQHandler//93:SHRTIMERIRQ1 113.word0//94:Reserved 114.word0//95:Reserved 115.word0//96:Reserved 116.word0//97:Reserved 117.wordI2C2_EV_IRQHandler//98:I2C2Event 118.wordI2C2_ER_IRQHandler//99:I2C2Error 119.wordUSART5_IRQHandler//100:USART5 120.wordI2C2_WKUP_IRQHandler//101:I2C2Wakeup 121.wordUSART5_WKUP_IRQHandler//102:USART5Wakeup 122.word0//103:Reserved 123.sizeg_pfnVectors,.-g_pfnVectors 124.section.text.Reset_Handler 125.weakReset_Handler 126.typeReset_Handler,%function 127Reset_Handler: 128ldrr1,=_sidata 129ldrr2,=_sdata 130ldrr3,=_edata 131subsr3,r2 132blefill_bss_start 133loop_copy_data: 134subsr3,#4 135ldrr0,[r1,r3] 136strr0,[r2,r3] 137bgtloop_copy_data 138fill_bss_start: 139ldrr1,=__bss_start 140ldrr2,=__bss_end 141movsr0,0 142subsr2,r1 143blestartup_enter 144loop_fill_bss: 145subsr2,#4 146strr0,[r1,r2] 147bgtloop_fill_bss 148startup_enter: 149blSystemInit 150blentry 151/*ExceptionHandlers*/ 152.weakNMI_Handler 153.typeNMI_Handler,%function 154NMI_Handler: 155b. 156.sizeNMI_Handler,.-NMI_Handler 157.weakMemManage_Handler 158.typeMemManage_Handler,%function 159MemManage_Handler: 160b. 161.sizeMemManage_Handler,.-MemManage_Handler 162.weakBusFault_Handler 163.typeBusFault_Handler,%function 164BusFault_Handler: 165b. 166.sizeBusFault_Handler,.-BusFault_Handler 167.weakUsageFault_Handler 168.typeUsageFault_Handler,%function 169UsageFault_Handler: 170b. 171.sizeUsageFault_Handler,.-UsageFault_Handler 172.weakSVC_Handler 173.typeSVC_Handler,%function 174SVC_Handler: 175b. 176.sizeSVC_Handler,.-SVC_Handler 177.weakDebugMon_Handler 178.typeDebugMon_Handler,%function 179DebugMon_Handler: 180b. 181.sizeDebugMon_Handler,.-DebugMon_Handler 182.weakPendSV_Handler 183.typePendSV_Handler,%function 184PendSV_Handler: 185b. 186.sizePendSV_Handler,.-PendSV_Handler 187.weakSysTick_Handler 188.typeSysTick_Handler,%function 189SysTick_Handler: 190b. 191.sizeSysTick_Handler,.-SysTick_Handler 192/*IQRHandler*/ 193.section.text.Default_Handler,"ax",%progbits 194.typeDefault_Handler,%function 195Default_Handler: 196b. 197.sizeDefault_Handler,.-Default_Handler 198.macroIRQhandler 199.weakhandler 200.sethandler,Default_Handler 201.endm 202IRQWWDGT_IRQHandler 203IRQLVD_IRQHandler 204IRQTAMPER_IRQHandler 205IRQRTC_IRQHandler 206IRQFMC_IRQHandler 207IRQRCU_CTC_IRQHandler 208IRQEXTI0_IRQHandler 209IRQEXTI1_IRQHandler 210IRQEXTI2_IRQHandler 211IRQEXTI3_IRQHandler 212IRQEXTI4_IRQHandler 213IRQDMA0_Channel0_IRQHandler 214IRQDMA0_Channel1_IRQHandler 215IRQDMA0_Channel2_IRQHandler 216IRQDMA0_Channel3_IRQHandler 217IRQDMA0_Channel4_IRQHandler 218IRQDMA0_Channel5_IRQHandler 219IRQDMA0_Channel6_IRQHandler 220IRQADC0_1_IRQHandler 221IRQUSBD_HP_CAN0_TX_IRQHandler 222IRQUSBD_LP_CAN0_RX0_IRQHandler 223IRQCAN0_RX1_IRQHandler 224IRQCAN0_EWMC_IRQHandler 225IRQEXTI5_9_IRQHandler 226IRQTIMER0_BRK_TIMER8_IRQHandler 227IRQTIMER0_UP_TIMER9_IRQHandler 228IRQTIMER0_TRG_CMT_TIMER10_IRQHandler 229IRQTIMER0_Channel_IRQHandler 230IRQTIMER1_IRQHandler 231IRQTIMER2_IRQHandler 232IRQTIMER3_IRQHandler 233IRQI2C0_EV_IRQHandler 234IRQI2C0_ER_IRQHandler 235IRQI2C1_EV_IRQHandler 236IRQI2C1_ER_IRQHandler 237IRQSPI0_IRQHandler 238IRQSPI1_I2S1ADD_IRQHandler 239IRQUSART0_IRQHandler 240IRQUSART1_IRQHandler 241IRQUSART2_IRQHandler 242IRQEXTI10_15_IRQHandler 243IRQRTC_Alarm_IRQHandler 244IRQUSBD_WKUP_IRQHandler 245IRQTIMER7_BRK_TIMER11_IRQHandler 246IRQTIMER7_UP_TIMER12_IRQHandler 247IRQTIMER7_TRG_CMT_TIMER13_IRQHandler 248IRQTIMER7_Channel_IRQHandler 249IRQADC2_IRQHandler 250IRQEXMC_IRQHandler 251IRQSDIO_IRQHandler 252IRQTIMER4_IRQHandler 253IRQSPI2_I2S2ADD_IRQHandler 254IRQUART3_IRQHandler 255IRQUART4_IRQHandler 256IRQTIMER5_DAC_IRQHandler 257IRQTIMER6_IRQHandler 258IRQDMA1_Channel0_IRQHandler 259IRQDMA1_Channel1_IRQHandler 260IRQDMA1_Channel2_IRQHandler 261IRQDMA1_Channel3_4_IRQHandler 262IRQCAN1_TX_IRQHandler 263IRQCAN1_RX0_IRQHandler 264IRQCAN1_RX1_IRQHandler 265IRQCAN1_EWMC_IRQHandler 266IRQSHRTIMER_IRQ2_IRQHandler 267IRQSHRTIMER_IRQ3_IRQHandler 268IRQSHRTIMER_IRQ4_IRQHandler 269IRQSHRTIMER_IRQ5_IRQHandler 270IRQSHRTIMER_IRQ6_IRQHandler 271IRQSHRTIMER_IRQ0_IRQHandler 272IRQSHRTIMER_IRQ1_IRQHandler 273IRQI2C2_EV_IRQHandler 274IRQI2C2_ER_IRQHandler 275IRQUSART5_IRQHandler 276IRQI2C2_WKUP_IRQHandler 277IRQUSART5_WKUP_IRQHandler
導(dǎo)入RTTStudioIDE
導(dǎo)入工程
有了GCC版本的啟動(dòng)文件,那不妨先用RTTStudio導(dǎo)入一下工程,然后再根據(jù)錯(cuò)誤想辦法解決。點(diǎn)擊“文件”菜單內(nèi)的“導(dǎo)入”圖標(biāo),打開導(dǎo)入對(duì)話框:
選擇“RT-Thread Bsp到工作空間中”,然后點(diǎn)擊下一步按鈕:
根據(jù)自己的實(shí)際情況填寫內(nèi)容,然后點(diǎn)擊“完成按鈕”進(jìn)行導(dǎo)入:
如下是我導(dǎo)入后的項(xiàng)目資源列表,會(huì)把所需的內(nèi)容都拷貝到工程內(nèi)部:
編譯根據(jù)錯(cuò)誤解決問(wèn)題
不妨先編譯一下工程,發(fā)現(xiàn)報(bào)了一些錯(cuò)誤,這是必然的,因?yàn)檫€有很多操作沒(méi)做呢。那首當(dāng)其沖的錯(cuò)誤就是如下的GCC不支持m33內(nèi)核的問(wèn)題。
1arm-none-eabi-gcc:error:unrecognizedargumentinoption'-mcpu=cortex-m33+nodsp' 2arm-none-eabi-gcc:note:validargumentsto'-mcpu='are:arm1020earm1020tarm1022earm1026ej-sarm10earm10tdmiarm1136j-sarm1136jf-sarm1156t2-sarm1156t2f-sarm1176jz-sarm1176jzf-sarm2arm250arm3arm6arm60arm600arm610arm620arm7arm70arm700arm700iarm710arm7100arm710carm710tarm720arm720tarm740tarm7500arm7500fearm7darm7diarm7dmarm7dmiarm7marm7tdmiarm7tdmi-sarm8arm810arm9arm920arm920tarm922tarm926ej-sarm940tarm946e-sarm966e-sarm968e-sarm9earm9tdmicortex-a12cortex-a15cortex-a15.cortex-a7cortex-a17cortex-a17.cortex-a7cortex-a5cortex-a53cortex-a57cortex-a57.cortex-a53cortex-a7cortex-a72cortex-a72.cortex-a53cortex-a8cortex-a9cortex-m0cortex-m0.small-multiplycortex-m0pluscortex-m0plus.small-multiplycortex-m1cortex-m1.small-multiplycortex-m3cortex-m4cortex-m7cortex-r4cortex-r4fcortex-r5cortex-r7cortex-r8ep9312exynos-m1fa526fa606tefa626fa626tefa726tefmp626generic-armv7-aiwmmxtiwmmxt2marvell-pj4mpcorempcorenovfpnativestrongarmstrongarm110strongarm1100strongarm1110xgene1xscale 3make:***[rt-thread/src/subdir.mkrt-thread/src/clock.o]Error1
更新GCC
去arm官網(wǎng),下載最新版本的gcc-arm-none-eabi:
GCC下載地址: https://developer.arm.com/downloads/-/gnu-rm
把解壓后的GCC文件夾拷貝到RTTStudio的GCC工具路徑內(nèi),為了減小點(diǎn)路徑長(zhǎng)度,可以把文件夾名字重命名為”10.3”:
點(diǎn)擊“構(gòu)建配置”工具圖標(biāo),打開配置對(duì)話框,在“設(shè)置”欄的“Toolchains”圖頁(yè)內(nèi)就可以配置GCC相關(guān)信息了。GCC應(yīng)該是向下兼容的,這里不妨選擇”global”進(jìn)行全局設(shè)置:
點(diǎn)擊“瀏覽”按鈕,選擇剛加入的GCC工具路徑,要選擇到里面的bin級(jí)目錄:
添加“cmsis_gcc.h”頭文件
點(diǎn)擊“應(yīng)用并關(guān)閉”按鈕,完成修改,再次編譯,發(fā)現(xiàn)之前不支持M33內(nèi)核的錯(cuò)誤不見(jiàn)了。不過(guò)錯(cuò)誤反而變多了,也很正常,因?yàn)橹熬蜎](méi)進(jìn)行到GCC編譯這一步,很多錯(cuò)誤自然出現(xiàn)不了,不用著急,先看第一個(gè)錯(cuò)誤:
1D:RT-ThreadStudioworkspaceFOC_MiniCarlibrariesGD32E50x_Firmware_LibraryCMSIS/cmsis_compiler.h:54:12:fatalerror:cmsis_gcc.h:Nosuchfileordirectory 254|#include"cmsis_gcc.h"
報(bào)的是固件庫(kù)缺少“cmsis_gcc.h”文件。也對(duì),官方固件并沒(méi)有做GCC的支持,怎么會(huì)有這個(gè)頭文件呢。那繼續(xù)從其它固件那里拷貝一份到當(dāng)前工程內(nèi)即可,當(dāng)然為了之前做的BSP的完整性,也可以同時(shí)往其對(duì)應(yīng)位置拷貝一份:
再次編譯,嘔吼!錯(cuò)誤更多了,依然不急,先看第一個(gè)錯(cuò)誤:
1D:RT-ThreadStudioworkspaceFOC_MiniCarlibrariesGD32E50x_Firmware_LibraryCMSIS/core_cm33.h:2668:10:fatalerror:mpu_armv8.h:Nosuchfileordirectory 22668|#include"mpu_armv8.h"
提示找不到”mpu_armv8.h”頭文件。這里比較奇怪,m33內(nèi)核確實(shí)屬于armv8架構(gòu),但官方固件庫(kù)內(nèi)卻找不到此頭文件,倒是在其它的BSP內(nèi)搜到了此頭文件,于是隨便拷貝一個(gè)到工程內(nèi)即可,比如我是從瑞薩的一個(gè)BSP內(nèi)拷貝的。當(dāng)然,這里也可以關(guān)掉mpu的配置宏,不用mpu。
于是再次進(jìn)行編譯,就會(huì)發(fā)現(xiàn)編譯通過(guò)了:
更新pyocd
那不妨下載一下試試,不出意外自然會(huì)出現(xiàn)意外,果真不能正常下載。原因就是最開始提到的自帶的pyocd版本太老了,不支持GD32E503RC的器件。需要更新pyocd:
打開CMD命令窗口,運(yùn)行如下命令,安裝新的pyocd:
等待安裝完畢,就可以在python的安裝路徑下找到新的”pyocd.exe”
在終端輸入“pyocd -V”命令,可查看到新安裝pyocd的版本。還可以輸入“pyocd list —targets”命令查看目前pyocd支持的器件。
最后會(huì)發(fā)現(xiàn),默認(rèn)并不支持兆易創(chuàng)新的器件,所以,還需要自己添加支持包:
安裝完后,再查看安裝包和支持的器件,就能找到GD32了:
最后再修改一些RTTStudio的工程配置,選擇先安裝的pyocd.exe和pyocd-gdbserver.exe:
然后再嘗試一些燒寫,就可以正常下載甚至調(diào)試程序了:
相關(guān)鏈接
本系列首篇文章鏈接:
https://club.rt-thread.org/ask/article/5c0c4ba7eb4ab1ad.html
———————End———————
點(diǎn)擊閱讀原文進(jìn)入官網(wǎng)
?
?
原文標(biāo)題:無(wú)刷電機(jī)小車開發(fā)記錄02——BSP導(dǎo)入RT-Thread Studio
文章出處:【微信公眾號(hào):RTThread物聯(lián)網(wǎng)操作系統(tǒng)】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。
-
RT-Thread
+關(guān)注
關(guān)注
31文章
1301瀏覽量
40265
原文標(biāo)題:無(wú)刷電機(jī)小車開發(fā)記錄02——BSP導(dǎo)入RT-Thread Studio
文章出處:【微信號(hào):RTThread,微信公眾號(hào):RTThread物聯(lián)網(wǎng)操作系統(tǒng)】歡迎添加關(guān)注!文章轉(zhuǎn)載請(qǐng)注明出處。
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論