基于FreeRtos的stm32多任务程序

本文详细介绍了如何将FreeRTOS移植到STM32平台上,包括FreeRTOS源码的整理、工程配置、文件添加以及编译过程。在完成移植后,还展示了如何编写多任务程序,并成功烧录到STM32开发板中进行运行。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

基于FreeRtos的stm32多任务程序

FreeRtos的移植

FreeRtos的源码(解压码为:g6jk)
keil5的工程(解压码为:lwpq)
都解压完成之后进入keil工程目录“FreeRTOS工程\Project\RVMDK(uv5)”下双击打开工程
在这里插入图片描述
点击下图处编译,编译结果无误
在这里插入图片描述
这时便可以移植FreeRtos
打开解压后的FreeRtos工程文件夹,新建文件夹“FreeRtos”
在这里插入图片描述

然后到FreeRtos源码中在路径FreeRTOSv9.0.0\FreeRTOS\Source下,将include文件夹复制到刚创建好的FreeRtos文件夹下
在这里插入图片描述
然后再在FreeRtos文件夹下新建两个文件夹,分别命名为“port”、“src”
在这里插入图片描述
之后回到FreeRtos源码文件夹下,路径FreeRTOSv9.0.0\FreeRTOS\Source\portable下将“ MemMang”和“RVDS”文件夹复制到创建的“port”文件下
在这里插入图片描述
再将路径FreeRTOSv9.0.0\FreeRTOS\Source下的所有.c文件复制到“src”文件夹中
在这里插入图片描述
之后打开工程
在项目中创建“FreeRtos/src”和“FreeRtos/port”在这里插入图片描述
添加c源程序,双击FreeRtos/src文件,选择“src”中所有的.c文件,点击“Add”添加
在这里插入图片描述

添加 FreeRTOS 端口源程序,在路径FreeRTOS工程\FreeRTOS\port\RVDS\ARM_CM3中找到port.c文件加入FreeRtos中
在这里插入图片描述
还有路径FreeRTOS工程\FreeRTOS\port\MemMang下的heap_4.c加入
在这里插入图片描述
添加路径FreeRTOS工程\User下的FreeRTOSConfig.h 到 USER 中(文件中可能么有,那就自己创建一个FreeRTOSConfig.h 后面会添加代码)

在这里插入图片描述
魔术棒 ——> C/C++ ——> … ——> 添加按钮 ——> 添加两个路径:…\FreeRTOS\include和…\FreeRTOS\port\RVDS\ARM_CM3

在这里插入图片描述
将下列代码添加到“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.

    http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
    including FreeRTOS+Trace - an indispensable productivity tool, a DOS
    compatible FAT file system, and our tiny thread aware UDP/IP stack.

    http://www.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.
    Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.

    http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High
    Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS
    licenses offer ticketed support, indemnification and commercial middleware.

    http://www.SafeRTOS.com - High Integrity Systems also provide a safety
    engineered and independently SIL3 certified version for use in safety and
    mission critical applications that require provable dependability.

*/


#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H

#include "stm32f10x.h"
#include "bsp_usart.h"


//针对不同的编译器调用不同的stdint.h文件
#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__)
    #include <stdint.h>
    extern uint32_t SystemCoreClock;
#endif

//断言
#define vAssertCalled(char,int) printf("Error:%s,%d\r\n",char,int)
#define configASSERT(x) if((x)==0) vAssertCalled(__FILE__,__LINE__)

/************************************************************************
 *               FreeRTOS基础配置配置选项 
 *********************************************************************/
/* 置1:RTOS使用抢占式调度器;置0:RTOS使用协作式调度器(时间片)
 * 
 * 注:在多任务管理机制上ÿ
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值