前述已经搭建好 WIN10+VSCODE+GCC+JLINK的开发环境,开发板为GD32307C,对应mcu型号为GD32F30x系列。
今天将FreeRTOS移植过来,这里记录一下移植过程。
1. FreeRTOS源码下载
下载后,解压缩代码,我们只取FreeRTOS文件夹下的代码,其他文件的作用后续可以再学习一下,我们这里用不到。
FreeRTOS的代码目录如下:
Demo:一些演示工程。
License:许可。
Source:源码目录。我们所需要的文件都在这里面。
保留FreeRTOS下的红框部分文件:
因为GD32F30x是cortex-M4架构,GCC目录下我们只需要留ARM_CM4F文件夹即可。MemMang文件夹下我们选择一种内存管理方式即可,我这边选择的是heap4。
FreeRTOS的源码至此整理完毕,将FreeRTOS目录整个拷贝到之前的工程下,目录结构如下。
2. 编译调试
进入vscode,打开项目,编译:
会出现如下报错:
In file included from ./FreeRTOS/Source/croutine.c:29:
./FreeRTOS/Source/include/FreeRTOS.h:59:10: fatal error: FreeRTOSConfig.h: No such file or directory
59 | #include "FreeRTOSConfig.h"
| ^~~~~~~~~~~~~~~~~~
保险起见,这里我们从GD32307C demo板的官方示例代码中拷贝一份过来(也可以从FreeRTOS的Demo下找一份CM4的模板过来再修改)。
GD32307C_EVAL_Demo_Suites.rar --- 从GD官网下载
将FreeRTOSConfig.h拷贝到如下路径:
继续编译,会提示以下错误:
ben.du@P6-Ben-Du1 MINGW64 /f/Robot/GitLab_Local/project/rvc_station (master)
$ make
buid croutine.c
buid event_groups.c
buid list.c
C:\Users\ben.du\AppData\Local\Temp\ccA77GDd.s: Assembler messages:
C:\Users\ben.du\AppData\Local\Temp\ccA77GDd.s:526: Error: selected FPU does not support instruction -- `vstmdbeq r0!,{s16-s31}'
C:\Users\ben.du\AppData\Local\Temp\ccA77GDd.s:548: Error: selected FPU does not support instruction -- `vldmiaeq r0!,{s16-s31}'
Makefile:147: recipe for target 'build/Obj/port.o' failed
make: *** [build/Obj/port.o] Error 1
经确认,前述的FreeRTOSConfig.h打开了浮点功能(CM4支持),需要在makefile中增加硬浮点对应的编译选项,修改Makefile文件中的FPU选项:
#内核选择,FPU, FLOAT-ABI可为空
CPU := -mcpu=cortex-m4
FPU := -mfloat-abi=hard -mfpu=fpv4-sp-d16
FLOAT-ABI :=
继续编译,会报如下错误:
buid systick.c
c:/program files (x86)/gnu arm embedded toolchain/10 2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: ./build/Obj/gd32f30x_it.o: in function `SVC_Handler':
F:\Robot\GitLab_Local\project\rvc_station/./Template/gd32f30x_it.c:112: multiple definition of `SVC_Handler'; ./build/Obj/port.o:F:\Robot\GitLab_Local\project\rvc_station/./FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c:249: first defined here
c:/program files (x86)/gnu arm embedded toolchain/10 2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: ./build/Obj/gd32f30x_it.o: in function `PendSV_Handler':
F:\Robot\GitLab_Local\project\rvc_station/./Template/gd32f30x_it.c:132: multiple definition of `PendSV_Handler'; ./build/Obj/port.o:F:\Robot\GitLab_Local\project\rvc_station/./FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c:443: first defined here
c:/program files (x86)/gnu arm embedded toolchain/10 2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld.exe: ./build/Obj/gd32f30x_it.o: in function `SysTick_Handler':
F:\Robot\GitLab_Local\project\rvc_station/./Template/gd32f30x_it.c:141: multiple definition of `SysTick_Handler'; ./build/Obj/port.o:F:\Robot\GitLab_Local\project\rvc_station/./FreeRTOS/Source/portable/GCC/ARM_CM4F/port.c:497: first defined here
原因是因为下面这三个中断服务函数我的工程startup中已经实现,因此出现了重定义,只需要注释掉gd32f30x_it.c中的这几个函数原型即可。
SVC_Handler/PendSV_Handler/SysTick_Handler
继续编译,编译通过。
3. FreeRTOS验证
后续进行。