• 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,打开项目,编译:

     会出现如下报错:

    1. In file included from ./FreeRTOS/Source/croutine.c:29:
    2. ./FreeRTOS/Source/include/FreeRTOS.h:59:10: fatal error: FreeRTOSConfig.h: No such file or directory
    3. 59 | #include "FreeRTOSConfig.h"
    4. | ^~~~~~~~~~~~~~~~~~

    保险起见,这里我们从GD32307C demo板的官方示例代码中拷贝一份过来(也可以从FreeRTOS的Demo下找一份CM4的模板过来再修改)。

    GD32307C_EVAL_Demo_Suites.rar --- 从GD官网下载

     将FreeRTOSConfig.h拷贝到如下路径:

     继续编译,会提示以下错误:

    1. ben.du@P6-Ben-Du1 MINGW64 /f/Robot/GitLab_Local/project/rvc_station (master)
    2. $ make
    3. buid croutine.c
    4. buid event_groups.c
    5. buid list.c
    6. C:\Users\ben.du\AppData\Local\Temp\ccA77GDd.s: Assembler messages:
    7. C:\Users\ben.du\AppData\Local\Temp\ccA77GDd.s:526: Error: selected FPU does not support instruction -- `vstmdbeq r0!,{s16-s31}'
    8. C:\Users\ben.du\AppData\Local\Temp\ccA77GDd.s:548: Error: selected FPU does not support instruction -- `vldmiaeq r0!,{s16-s31}'
    9. Makefile:147: recipe for target 'build/Obj/port.o' failed
    10. make: *** [build/Obj/port.o] Error 1

    经确认,前述的FreeRTOSConfig.h打开了浮点功能(CM4支持),需要在makefile中增加硬浮点对应的编译选项,修改Makefile文件中的FPU选项:

    1. #内核选择,FPU, FLOAT-ABI可为空
    2. CPU := -mcpu=cortex-m4
    3. FPU := -mfloat-abi=hard -mfpu=fpv4-sp-d16
    4. FLOAT-ABI :=

    继续编译,会报如下错误:

    1. buid systick.c
    2. 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':
    3. 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
    4. 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':
    5. 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
    6. 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':
    7. 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验证

    后续进行。

  • 相关阅读:
    Flink中常用的去重方案
    盒式交换机堆叠配置
    决策树算法:原理与python实现案例
    数字IC基础协议篇(1)——I2C协议
    Go 理解零值
    史蒂夫·乔布斯诞辰67周年,他的这些思想仍值得我们学习
    uni-app的下拉搜索选择组合框
    3D Object Detection Essay Reading 2024.04.05
    多线程 - 定时器
    Linux账号管理(用户和用户组)
  • 原文地址:https://blog.csdn.net/man9953211/article/details/127421425