前期准备:
1.FreeRTOS源码:Release V10.4.3 LTS Patch 3 · FreeRTOS/FreeRTOS-Kernel · GitHub
2.智能天气时钟项目的工程文件------基于梅花七月香的智能天气时钟项目https://www.bilibili.com/video/BV1tfL1zeEQN?spm_id_from=333.788.videopod.sections&vd_source=de0a013f6a98442a5ebaae19e86461fd&p=46
文件移植:
1.在工程文件中创建:freertos文件,在其中再创建include和portable文件
------freertos
------------------include
------------------portable
2.将源码中include所有.h文件复制到工程文件的include中

3.将源码主文件中的所有.C文件复制到工程文件的freertos目录下


4.将源文件protable中Common文件下的mpu_wrappers.c
MenMang文件下的heap_1.c,heap_2.c,heap_3.c,heap_4.c,heap_5.c
RVDS文件下的ARM_CM4F内容port.c和portmaco.h
都移植到工程文件中的portable中

KEIL中加入文件:
1.加所有.C文件加入freertos文件中,同时引入头文件-include


2.运行一遍---按照错误提示修改 第一遍运行大概14个错误

缺少FreeRTOSConfig.h 宏定义的头文件
..\third_lib\freertos\include\FreeRTOS.h(57): error: #5: cannot open source input file "FreeRTOSConfig.h": No such file or directory
#include "FreeRTOSConfig.h"
在源码文件中收不到的---直接网上搜索--FreeRTOSConfig.h ---找打官方介绍(支持中文)
https://www.freertos.org/zh-cn-cmn-s/Documentation/02-Kernel/03-Supported-devices/02-Customization

在include文件中创建一个FreeRTOSConfig.h文件(大小写要一致),将官网这部分复制到新创建的文件中

存在两个问题:蓝色部分是可以不需要,其次红色部分[ ]不符合C语言的写作规范
使用正则表达式替换蓝色部分--记得查找模式选择正则表达式,使用空去替代
(有关正则表达式内容:https://www.runoob.com/regexp/regexp-syntax.html)
[ ]直接使用普通模式,也是同空去替代


这部分剩余 括号内容也取掉

参数配置:修改两处
/* Interrupt nesting behaviour configuration. */
#define configKERNEL_INTERRUPT_PRIORITY dependent of processor
#define configMAX_SYSCALL_INTERRUPT_PRIORITY dependent on processor and application
#define configMAX_API_CALL_INTERRUPT_PRIORITY dependent on processor and application
修改成如下
/* Interrupt nesting behaviour configuration. */
#define configKERNEL_INTERRUPT_PRIORITY (15<<4) //配置优先级数量--15个(设置优先级是Group4-有15个)
#define configMAX_SYSCALL_INTERRUPT_PRIORITY 5<<4 //行业常用数量--系统管理的优先级数量
#define configMAX_API_CALL_INTERRUPT_PRIORITY dependent on processor and application
重新编译:
..\third_lib\freertos\include\FreeRTOSConfig.h(6): error: #5: cannot open source input file "something.h": No such file or directory
#include "something.h"
解决方法:把 #include "something.h"注释掉
重新编译:vAssertCalled这个函数没有被定义
..\third_lib\freertos\include\FreeRTOSConfig.h(72): error: #40: expected an identifier
#define configASSERT( ( x ) ) if( ( x ) == 0 ) vAssertCalled( __FILE__, __LINE__ )
在mian.C中末尾定义
void vAssertCalled( const char *file , int line)
{
}
然后然后FreeRTOSConfig.h中extern外部声明一下
/* Define to trap errors during development. */
extern void vAssertCalled( const char *file , int line);
//就放在使用的前面
#define configASSERT( ( x ) ) if( ( x ) == 0 ) vAssertCalled( __FILE__, __LINE__ )
//这里还有一个问题--只需要一个括号就行
#define configASSERT( x ) if( ( x ) == 0 ) vAssertCalled( __FILE__, __LINE__ )
优化:
用不到ARMV8的结构,STM32F4使用的是V7架构,这部分删掉
/* ARMv8-M secure side port related definitions. */
#define secureconfigMAX_SECURE_CONTEXTS 5
重新编译:前面只加入include的头文件地址,portmacro.h这个在点port文件中,重新加入该文件的地址
..\third_lib\freertos\include\portable.h(51): error: #5: cannot open source input file "portmacro.h": No such file or directory
#include "portmacro.h"
重新编译:解决方法:把mpu_wrappers.c删掉,使用不到
..\third_lib\freertos\portable\mpu_wrappers.c(2409): warning: #223-D: function "portRESET_PRIVILEGE" declared implicitly
portRESET_PRIVILEGE();
重新编译:内存管理的文件我们都加进来的,里面存在重复定义问题---选择heap4.C,其余的删掉
.\Objects\stm32f407.axf: Error: L6200E: Symbol pvPortMalloc multiply defined (by heap_2.o and heap_1.o)
重新编译:静态内存分配没有关---在FreeRTOSConfig.h中搜索--static
.\Objects\stm32f407.axf: Error: L6218E: Undefined symbol vApplicationGetIdleTaskMemory (referred from tasks.o).
/* Memory allocation related definitions. */
#define configSUPPORT_STATIC_ALLOCATION 1
将原本的1改成0---将静态内容分配关掉
/* Memory allocation related definitions. */
#define configSUPPORT_STATIC_ALLOCATION 0
重新编译:也是内容管理问题--
在heap4.C中搜索--ucHeap
.\Objects\stm32f407.axf: Error: L6218E: Undefined symbol ucHeap (referred from heap_4.o).
搜索到的第一个存在一个宏定义
/* Allocate the memory for the heap. */
#if ( configAPPLICATION_ALLOCATED_HEAP == 1 )
/* The application writer has already defined the array used for the RTOS
* heap - probably so it can be placed in a special segment or address. */
extern uint8_t ucHeap[ configTOTAL_HEAP_SIZE ];
去到FreeRTOSConfig.h中把这个宏定义关掉
#define configAPPLICATION_ALLOCATED_HEAP 0
现在编译--就没有错误了
704

被折叠的 条评论
为什么被折叠?



