移植FreeRTOS到STM32F103全过程

  1. 熟悉freeRTOS的firmware结构
解压源码到..\FreeRTOSv8.2.2,首先一定要浏览一下各个文件夹下的readme.txt文件。
进到这个目录:FreeRTOSv8.2.2\FreeRTOS\Source


看看这个readme文件:
Each real time kernel port consists of three files that contain the core kernel
components and are common to every port, and one or more files that are
specific to a particular microcontroller and or compiler.

+ The FreeRTOS/Source directory contains the three files that are common to
every port - list.c, queue.c and tasks.c.  The kernel is contained within these
three files.  croutine.c implements the optional co-routine functionality - which
is normally only used on very memory limited systems.

+ The FreeRTOS/Source/Portable directory contains the files that are specific to
a particular microcontroller and or compiler.

+ The FreeRTOS/Source/include directory contains the real time kernel header
files.

See the readme file in the FreeRTOS/Source/Portable directory for more
information.

看懂上面说的了吗?
说的是,源码包括:
1. 通用的内核文件:主要是三个:list.c, queue.c and tasks.c. 而croutine.c表示是写作式的任务,仅用在内存实在是有限的mcu上面。
2. 针对不同架构平台的接口。
3. 头文件

进入FreeRTOSv8.2.2\FreeRTOS\Source\portable,继续看该文件夹下的readme.txt
Each real time kernel port consists of three files that contain the core kernel
components and are common to every port, and one or more files that are
specific to a particular microcontroller and/or compiler.


+ The FreeRTOS/Source/Portable/MemMang directory contains the three sample
memory allocators as described on the http://www.FreeRTOS.org WEB site.

+ The other directories each contain files specific to a particular
microcontroller or compiler.



For example, if you are interested in the GCC port for the ATMega323
microcontroller then the port specific files are contained in
FreeRTOS/Source/Portable/GCC/ATMega323 directory.  If this is the only
port you are interested in then all the other directories can be
ignored.
看懂了吗?
总结:
1. 在该文件夹FreeRTOS/Source/Portable/MemMang 下面,包含内存分配的样例
2. 其他的文件夹包含具体的文件针对不同的平台和(或者)编译器

猜测:
移植的时候,必须包括如下:
(1)通用的内核文件:list.c, queue.c and tasks.c
(2)针对不同硬件平台的文件
(3)内存分配的文件
(4)头文件
......


2. 移植代码
(1)先建立一个工程文件不包括OS的,可以运行,比如最简单的跑马灯例程。
(2)在模板里面建立文件夹: FreeRTOS, 然后再FreeRTOS下建立新文件夹include,用来保存头文件




(3)从源文件 \FreeRTOSv8.2.2\FreeRTOS\Source 中找到 croutine.c, timers.c, list.c, queue.c, tasks.c 这5个文件,加入到FreeRTOS文件夹中;
(4)从源文件 \FreeRTOSv8.2.2\FreeRTOS\Source\portable\RVDS\ARM_CM3中找到port.c,加入到FreeRTOS文件夹中;
(5)从源文件 \FreeRTOSv8.2.2\FreeRTOS\Source\portable\MemMang找到heap_2.c,加入到FreeRTOS文件夹中;
这样*.c就添加完成了。


其中:port.c 是针对具体的硬件平台加进来的;
         heap_2.c 是其中一种内存分配管理机制,你可以换成其他形式。
        其他的.C文件是和内核相关的通用文件。

下面添加*.h头文件到include文件夹中
(6)将文件夹 \FreeRTOSv8.2.2\FreeRTOS\Source\include 中的所有.h文件添加到我们建立的include文件夹中;
(7)将文件夹 \FreeRTOSv8.2.2\FreeRTOS\Source\portable\RVDS\ARM_CM3下的portmacro.h文件添加到include文件夹中;
(8)我用的编译器是Keil,是stm32f103系列,在源码的Demo程序中,找到这个芯片的配置文件,加入到include文件夹中;
        将文件夹 \FreeRTOSv8.2.2\FreeRTOS\Demo\CORTEX_STM32F103_Keil 下FreeRTOSConfig.h,加入到include文件夹中;
这样就完成包含头文件的移植。


注意:红色标记的文件哪里来的呢??


(9)在工程中建立FreeRTOS和FreeRTOS\include文件夹,将我们在上面添加的代码添加到工程中,这个就不需要我说了吧。


(10)修改编译环境
    菜单栏找到 Project->options for target->C/C++->Include Paths 中加入上述的 include 文件夹,当然FreeRTOS文件夹最好也添上,防止遗漏。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值