导言

不用模板,直接将源码移植到我最喜欢的7块钱电子垃圾32c6t6,内核采用freertos10.4.3,采用经典库函数源码ll库(已停更,可以在一些稀奇古怪的地方搞到源码)。

移植

  • 来到freertos官网下载源码[ https://www.freertos.org/zh-cn-cmn-s/ ]这边我已经下载了2020年的版本了,就不重复下载了
  • 找到一个标准库项目创建文件夹

创建目录RTOS

rtos文件下创建两个子目录src和port

将Source/include文件夹拷贝到RTOS下

将Source/portable下的MemMang和RVDS文件夹拷贝到RTOS/port下。

创建工程文件夹

新建FreeRTOS/src和FreeRTOS/port组

FreeRTOS/src组中把RTOS/src文件夹中的源文件全部添加

FreeRTOS/port组添加RTOS\port\MemMang中的heap4.c和FreeRTOS\port\RVDS\ARM_CM3中的port.c

拷贝FreeRTOSv9.0.0\FreeRTOS\Demo\CORTEX_STM32F103_Keil下的FreeRTOSConfig.h文件到工程

  • 在FreeRTOSConfig.h中添加
1
2
#define xPortPendSVHandler 	PendSV_Handler
#define vPortSVCHandler SVC_Handler
  • 修改stm32f10x_it.c中的systick中断服务函数。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/**
* @brief This function handles SysTick Handler.
* @param None
* @retval None
*/
extern void xPortSysTickHandler(void);
void SysTick_Handler(void)
{
#if (INCLUDE_xTaskGetSchedulerState == 1 )
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED)
{
#endif /* INCLUDE_xTaskGetSchedulerState */
xPortSysTickHandler();
#if (INCLUDE_xTaskGetSchedulerState == 1 )
}
#endif /* INCLUDE_xTaskGetSchedulerState */
}
  • 备注掉stm32f10x_it.c的SVC_Handler(void)函数以及PendSV_Handler(void)函数(由于port.c重复定义)
  • 修改FreeRTOS.h头文件中的以下定义
1
2
3
#ifndef INCLUDE_xTaskGetCurrentTaskHandle
#define INCLUDE_xTaskGetCurrentTaskHandle 1
#endif
  • 编译就不会报错了
  • 运行没有问题

本文参考[ https://blog.csdn.net/qq_36973838/article/details/121754908 ]