一、文件准备1.1 准备 FreeRTOS 源码,并裁剪必要文件1.2 将源文件进入工程,并添加配置文件1.3 添加头文件路径1.4 编译并解决错误1.4.1 Error[2]:Failed to open #include file 'FreeRTOSConfig.h'1.4.2 Fatal Error[Lc002]:could not open file "...MIMX8ML8xxxxx_cm7_ram.icf“ 文件二、实现FreeRTOS接口2.1 三个异常2.1.1 异常处理函数作用2.1.2 接口移植方法2.2 滴答定时器初始化2.2.1 滴答定时器作用2.2.2 接口移植方法引用
一、文件准备
1.1 准备 FreeRTOS 源码,并裁剪必要文件
1.2 将源文件进入工程,并添加配置文件

1.3 添加头文件路径

原文: There are two options for running FreeRTOS on ARM Cortex-M7 microcontrollers. The best option depends on the revision of the ARM Cortex-M7 core in use. The revision is specified by an 'r' number, and a 'p' number, so will look something like 'r0p1'. Check the documentation for the microcontroller in use to find the revision of the Cortex-M7 core used in that microcontroller. If in doubt, use the FreeRTOS port provided specifically for r0p1 revisions, as that can be used with all core revisions. The first option is to use the ARM Cortex-M4F port, and the second option is to use the Cortex-M7 r0p1 port - the latter containing a minor errata workaround. If the revision of the ARM Cortex-M7 core is not r0p1 then either option can be used, but it is recommended to use the FreeRTOS ARM Cortex-M4F port located in the /FreeRTOS/Source/portable/RVDS/ARM_CM4F directory. If the revision of the ARM Cortex-M7 core is r0p1 then use the FreeRTOS ARM Cortex-M7 r0p1 port located in the /FreeRTOS/Source/portable/RVDS/ARM_CM7/r0p1 directory. 意思是说对于r0p1版本的bug,有一个专门的移植文件(有一个微小的修正),当然,这个文件可以用于所有M7内核,含已经解决此bug的高版本内核。
1.4 编译并解决错误
1.4.1 Error[2]:Failed to open #include file 'FreeRTOSConfig.h'
IAR移植 portasm.s 文件中需包含
#include <FreeRTOSConfig.h>
,而汇编文件的头文件目录不包括该路径,将FreeRTOSConfig.h包含进入

1.4.2 Fatal Error[Lc002]:could not open file "...MIMX8ML8xxxxx_cm7_ram.icf“ 文件
Linker 中用了绝对路径,改用相对路径(
$PROJ_DIR$/MIMX8ML8xxxxx_cm7_ram.icf
)可以找到该文件

1.4.3 Error[Li006]: duplicate definitions for "SysTick_Handler"
裸机中 delay 使用 systick 作为定时器,移植 FreeRTOS 后,systick 中断作为系统心跳,因此两者冲突,注释掉delay.c 文件中的
SysTick_Handler
。
二、实现FreeRTOS接口
2.1 三个异常
2.1.1 异常处理函数作用
- SVC_Handler,Service exception handler,打断除复位、NMI和 hard fault等异常以外的异常和中断。
- PendSV_Handler,pendable Service handler,优先级低于SVC_Handler且可调,但同样用于软件触发异常。FreeRTOS 任务之间的切换(任务调度器)即靠这个异常去实现。
- SysTick_Handler,system tick handler,为FreeRTOS提供了一个计时器,定时器的中断间隔就是FreeRTOS的最小时间片,而且在滴答定时器中断中还可以触发 PendSV 异常来进行任务调度器的执行。
2.1.2 接口移植方法
实现操作系统xPortPendSVHandler、vPortSVCHandler 和 xPortSysTickHandler 三个异常处理函数。有些移植通过修改启动文件中 PendSV_Handler、SVC_Handler、SysTick_Handler 三个中断号的名字。更简单是在 FreeRTOSConfig.h 宏定义重定向 这几个异常处理函数
而实际上异常处理函数的实现在 portasm.s 汇编文件里
2.2 滴答定时器初始化
2.2.1 滴答定时器作用
- FreeRTOS需要一个定时器为其提供时钟计数功能,每个cortex内核的MCU都有滴答定时器,它是属于内核的一部分,是cortex内核专门为操作系统内核提供专用,所以这个滴答定时器就不用不白用了。滴答定时器可以产生异常,异常说白了就是比中断优先级高的特殊中断
One local system timer (SysTick) integrated into the Cortex-M7 CPU
2.2.2 接口移植方法
- 修改 configCPU_CLOCK_HZ是MCU的内核频率,configTICK_RATE_HZ则是滴答定时器的频率

- 初始化滴答定时器
在 port.c文件中 vPortSetupTimerInterrup 函数配置滴答定时器并启动定时器
note:
- 关于为什么加载值需要减一,简单说是因为计数值到0时,计数器即停止1。

引用
