×
单片机 > 单片机程序设计 > 详情

FreeRTOS的简介&移植FreeRTOS到STM32平台

发布时间:2020-06-08 发布时间:
|

I.说明

作者:WXP(翱翔云端的鸟)


联系方式:328452854@qq.com || 13100610853(联系请注明CSDN)


申明:个人原创,转载请先经过本人同意!


要说的话:个人水平有限,不足之处,还请指正!有疑问欢迎大家联系我交流探讨!



=============================================================================================================================


=============================================================================================================================


II.环境

软件环境:KEIL-MDK v-5.24a


硬件:STM32F103ZET6最小系统板


=============================================================================================================================


=============================================================================================================================



III.FreeRTOS简介

FreeRTOS作为一个RTOS(Real Time Operating System),Free,即免费。公司或者个人在自己的产品中使用了FreeRTOS而不必为各种授权问题而苦恼! 这也是相对其它嵌入式RTOS的优势。其次它十分精简短小,占用很小的空间(4-9K字节大小),同时它支持很多平台,官方的文档也相对比较齐全,上手比较容易,所以比较适合初次接触RTOS的工程师。


FreeRTOS的具体特点如下


1.免商业许可,可以在具体产品中免费试用FreeRTOS


2.支持众多半导体厂家的平台,应用范围广,资料齐全


3.相比较于其它OS,代码更精简,移植更容易


4.提供了一个用于低功耗的Tickless模式


5.任务数量不受限制


6.内部有软件定时器和堆栈检测功能


7.内核对象齐全,在任务同步通信中使用起来很方便


=============================================================================================================================


=============================================================================================================================


IV.移植FreeRTOS到STM32F103平台

1.准备FreeRTOS源码和一个裸机STM32-Demo程序(STM32F103ZET6),FreeRTOS源码可以在官网www.freertos.org下载,同时上面也可以下载到很多文档。


这里我给出我的百度云下载地址(FreeRTOS源码和STM32裸机Demo):http://pan.baidu.com/s/1nvuTOPN


2.查看FreeRTOS源码目录,分为Demo、License、Source 3个目录


Demo目录下存放的是FreeRTOS的相关历程 如下图:



LICENSE目录是FreeRTOS的许可,可以不看

Source就是真正的FreeRTOS的源码目录

目录视图如下:

可以看到Source目录文件也很少,两个目录和一些.c文件 。

include:FreeRTOS的头文件

protable:平台及编译环境所需要的移植文件

xxx.c FreeRTOS源文件

这里我们只需注意 protable目录下的部分文件,这部分文件是等下移植所需要用到的

Keil:MDK编译环境所需要的文件

MemMang:内存管理相关文件,移植必须

RVDS:MDK编译环境所需要的文件

3.在裸机Demo工程文件中新建一个FreeRTOS的文件夹,并将FreeRTOS的源码全部添加到这个文件夹当中

如图所示:


4.删除protable目录下除Keil MemMang和RVDS外的所有文件

5.在MDK中新添加两个分组 FreeRTOS_Source和FreeRTOS_Ports,并添加对应的文件

{ croutine.c 

FreeRTOS_Source { event_groups.c

{ list.c

{ queue.c

{ task.c

{ timers.c

FreeRTOS_Ports { port.c RVDS/ARM_CM3目录下

{heap_4.c MemMang目录下

{portmacro.h RVDS/ARM_CM3目录下 这里添加.h是为了比较容易查看

添加完成后如下图:

5.添加对应的文件路径 ..FreeRTOSinclude..FreeRTOSportableRVDSARM_CM3

如图所示

6.编译,提示缺少FreeRTOSConfig.h文件

7.这里我们有两种方法添加这个文件,一种是自己创建,这个会很麻烦对于不懂FreeRTOS的人来说很难。第二种就是直接去官方移植好的例程中找到这个文件

这里推荐第二种 FreeRTOSv9.0.0->FreeRTOS->Demo->CORTEX_STM32F103_Keil 中找到FreeRTOSConfig.h

然后复制到裸机工程的USER目录下 

如图

8.然后将FreeRTOSConfig.h文件添加到MDK USER组中(这里是为了容易查看和修改)

9.修改stm32f10x_it.c  

修改bsp_systick.c 

修改bsp.c如下

10.添加一个includes.h  用来管理所有的头文件 

#ifndef __INCLUDES_H__

#define __INCLUDES_H__

 

/***********************************************************************************

* STD

************************************************************************************/

#include

#include

#include

#include

#include "stm32f10x.h"

 

/************************************************************************************

* OS

*************************************************************************************/

#include "FreeRTOS.h"

#include "task.h"

#include "queue.h"

#include "croutine.h"

 

/************************************************************************************

* MACRO DEFINE

*************************************************************************************/

 

/************************************************************************************

* APP/BSP

*************************************************************************************/

#include "bsp.h"

 

#endif


11.修改FreeRTOSConfig.h和main.c


FreeRTOSConfig.h

/*

    FreeRTOS V9.0.0 - Copyright (C) 2016 Real Time Engineers Ltd.

    All rights reserved

    VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.

    This file is part of the FreeRTOS distribution.

    FreeRTOS is free software; you can redistribute it and/or modify it under

    the terms of the GNU General Public License (version 2) as published by the

    Free Software Foundation >>>> AND MODIFIED BY <<<< the FreeRTOS exception.

    ***************************************************************************

    >>!   NOTE: The modification to the GPL is included to allow you to     !<<

    >>!   distribute a combined work that includes FreeRTOS without being   !<<

    >>!   obliged to provide the source code for proprietary components     !<<

    >>!   outside of the FreeRTOS kernel.                                   !<<

    ***************************************************************************

    FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY

    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS

    FOR A PARTICULAR PURPOSE.  Full license text is available on the following

    link: http://www.freertos.org/a00114.html

    ***************************************************************************

     *                                                                       *

     *    FreeRTOS provides completely free yet professionally developed,    *

     *    robust, strictly quality controlled, supported, and cross          *

     *    platform software that is more than just the market leader, it     *

     *    is the industry's de facto standard.                               *

     *                                                                       *

     *    Help yourself get started quickly while simultaneously helping     *

     *    to support the FreeRTOS project by purchasing a FreeRTOS           *

     *    tutorial book, reference manual, or both:                          *

     *    http://www.FreeRTOS.org/Documentation                              *

     *                                                                       *

    ***************************************************************************

    http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading

    the FAQ page "My application does not run, what could be wrong?".  Have you

    defined configASSERT()?

    http://www.FreeRTOS.org/support - In return for receiving this top quality

    embedded software for free we request you assist our global community by

    participating in the support forum.

    http://www.FreeRTOS.org/training - Investing in training allows your team to

    be as productive as possible as early as possible.  Now you can receive

    FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers

    Ltd, and the world's leading authority on the world's leading RTOS.



关键字:FreeRTOS  移植  STM32平台 

『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
51单片机中断源的扩展方法