FreeRTOS移植 --- base on gd32f30x + gcc

前述已经搭建好 WIN10+VSCODE+GCC+JLINK的开发环境,开发板为GD32307C,对应mcu型号为GD32F30x系列。

今天将FreeRTOS移植过来,这里记录一下移植过程。

1. FreeRTOS源码下载

官网下载地址:gFreeRTOS - Free RTOS Source Code Downloads, the official FreeRTOS zip file release downloadHow to download the FreeRTOS real time kernel, to get the Free RTOS source code zip file. FreeRTOS is a portable, open source, mini Real Time kernel. A free RTOS for small embedded systemshttps://www.freertos.org/a00104.html

 下载后,解压缩代码,我们只取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验证

后续进行。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值