前情提要
上一篇文章记录了一下如何创建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文章
1266浏览量
39864
原文标题:无刷电机小车开发记录02——BSP导入RT-Thread Studio
文章出处:【微信号:RTThread,微信公众号:RTThread物联网操作系统】欢迎添加关注!文章转载请注明出处。
发布评论请先 登录
相关推荐
评论