前情提要
上一篇文章記錄了一下如何創建GD32E503的BSP。但由于時間關系只實現了MDK版本的工程模板,后面如果需要提交BSP時再去補全IAR版本的。但對于我個人而言,IAR只在讀書時玩藍牙開發的時候用過,而MDK雖然用的比較多但最近幾年也很少用了。感覺還是VSCode等編輯器用起來更舒服一些,而對于RTT系統的開發,我個人還是更傾向于使用官方的RTThreadStudioIDE進行開發。于是今天想想辦法怎么移到RTTStudio上去。
面臨的問題
-
上篇文章已經發現,目前官方的固件庫竟然沒有GCC版本的啟動文件,所以要想辦法弄個啟動文件
-
RTTStudio自帶的GCC編譯器版本太老,不支持編譯M33內核,所以要升級GCC
-
計劃用開源的DAP調試器進行調試,但同樣RTTStudio自帶的pyocd調試工具版本太老,需要升級
添加GCC版本的啟動文件
拷貝啟動文件模板
從GD32F4xx固件包內把GCC文件夾拷貝到新添加的GDE50x固件包的對應位置,并把匯編文件名稱修改為gd32e50x的,注意,GD32E50x分了高密度版(hd)和互聯版(cl),我這里暫且只修改了一份我用到的高密度版本的。cl版本的也類似修改即可。
修改啟動文件
眾所周知,匯編的啟動文件要干的事情就是做一些芯片啟動的前期初始化工作,搭建C代碼的運行環境。所以這里也并不需要對照匯編指令,把每條語句的功能都搞明白,只需大致了解一下即可。一眼望去,感覺這個匯編文件主要做了三大事情。
第一,定義中斷向量;
第二,定義啟動入口;
第三,聲明中斷函數。
而啟動入口相關的不用修改,都是先調用SystemInit函數做一些時鐘等基礎初始化,然后再調用entry或者main函數執行后續的代碼。
所以這里主要修改的就是中斷向量的定義和中斷函數的聲明,按照armcc版本的進行修改即可:
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
導入RTTStudioIDE
導入工程
有了GCC版本的啟動文件,那不妨先用RTTStudio導入一下工程,然后再根據錯誤想辦法解決。點擊“文件”菜單內的“導入”圖標,打開導入對話框:
選擇“RT-Thread Bsp到工作空間中”,然后點擊下一步按鈕:
根據自己的實際情況填寫內容,然后點擊“完成按鈕”進行導入:
如下是我導入后的項目資源列表,會把所需的內容都拷貝到工程內部:
編譯根據錯誤解決問題
不妨先編譯一下工程,發現報了一些錯誤,這是必然的,因為還有很多操作沒做呢。那首當其沖的錯誤就是如下的GCC不支持m33內核的問題。
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官網,下載最新版本的gcc-arm-none-eabi:
GCC下載地址: https://developer.arm.com/downloads/-/gnu-rm
把解壓后的GCC文件夾拷貝到RTTStudio的GCC工具路徑內,為了減小點路徑長度,可以把文件夾名字重命名為”10.3”:
點擊“構建配置”工具圖標,打開配置對話框,在“設置”欄的“Toolchains”圖頁內就可以配置GCC相關信息了。GCC應該是向下兼容的,這里不妨選擇”global”進行全局設置:
點擊“瀏覽”按鈕,選擇剛加入的GCC工具路徑,要選擇到里面的bin級目錄:
添加“cmsis_gcc.h”頭文件
點擊“應用并關閉”按鈕,完成修改,再次編譯,發現之前不支持M33內核的錯誤不見了。不過錯誤反而變多了,也很正常,因為之前就沒進行到GCC編譯這一步,很多錯誤自然出現不了,不用著急,先看第一個錯誤:
1D:RT-ThreadStudioworkspaceFOC_MiniCarlibrariesGD32E50x_Firmware_LibraryCMSIS/cmsis_compiler.h:54:12:fatalerror:cmsis_gcc.h:Nosuchfileordirectory 254|#include"cmsis_gcc.h"
報的是固件庫缺少“cmsis_gcc.h”文件。也對,官方固件并沒有做GCC的支持,怎么會有這個頭文件呢。那繼續從其它固件那里拷貝一份到當前工程內即可,當然為了之前做的BSP的完整性,也可以同時往其對應位置拷貝一份:
再次編譯,嘔吼!錯誤更多了,依然不急,先看第一個錯誤:
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內核確實屬于armv8架構,但官方固件庫內卻找不到此頭文件,倒是在其它的BSP內搜到了此頭文件,于是隨便拷貝一個到工程內即可,比如我是從瑞薩的一個BSP內拷貝的。當然,這里也可以關掉mpu的配置宏,不用mpu。
于是再次進行編譯,就會發現編譯通過了:
更新pyocd
那不妨下載一下試試,不出意外自然會出現意外,果真不能正常下載。原因就是最開始提到的自帶的pyocd版本太老了,不支持GD32E503RC的器件。需要更新pyocd:
打開CMD命令窗口,運行如下命令,安裝新的pyocd:
等待安裝完畢,就可以在python的安裝路徑下找到新的”pyocd.exe”
在終端輸入“pyocd -V”命令,可查看到新安裝pyocd的版本。還可以輸入“pyocd list —targets”命令查看目前pyocd支持的器件。
最后會發現,默認并不支持兆易創新的器件,所以,還需要自己添加支持包:
安裝完后,再查看安裝包和支持的器件,就能找到GD32了:
最后再修改一些RTTStudio的工程配置,選擇先安裝的pyocd.exe和pyocd-gdbserver.exe:
然后再嘗試一些燒寫,就可以正常下載甚至調試程序了:
相關鏈接
本系列首篇文章鏈接:
https://club.rt-thread.org/ask/article/5c0c4ba7eb4ab1ad.html
———————End———————
點擊閱讀原文進入官網
?
?
-
RT-Thread
+關注
關注
31文章
1304瀏覽量
40300
原文標題:無刷電機小車開發記錄02——BSP導入RT-Thread Studio
文章出處:【微信號:RTThread,微信公眾號:RTThread物聯網操作系統】歡迎添加關注!文章轉載請注明出處。
發布評論請先 登錄
相關推薦
評論