【转】FreeRTOS通用移植,以keil和IAR工程 M7核为例

目录

keil:

IAR


keil:

原文在https://bbs.eeworld.com.cn/thread-1281875-1-1.html

本篇讲述移植FreeRTOS,并创建运行一个任务,对象芯片为M7系列的兆易创新GD32H7xx系列。

一.准备工作

1.下载FreeRTOS源码官网 http://www.freertos.org/ 或者托管网站FreeRTOS Real Time Kernel (RTOS) - Browse /FreeRTOS at SourceForge.net

2.解压,选取Source下源文件

图1:FreeRTOS移植使用到的资源文件

二.移植FreeRTOS

1.在串口打印工程添加如下源文件

图2:工程添加FreeRTOS源文件

2.添加头文件路径

图3:添加FreeRTOS头文件路径

3.在gd32h7xx_it.c屏蔽SVC_Handler和PendSV_Handler函数,修改SysTick_Handler,如下:

复制

 
/*  gd32h7xx_it.c  */

#include "gd32h7xx_it.h"
#include "systick.h"

#include "FreeRTOS.h"
#include "task.h" 

extern void xPortSysTickHandler( void );

/*
......
*/

/*!
    \brief      this function handles SVC exception
    \param[in]  none
    \param[out] none
    \retval     none
*/
//void SVC_Handler(void)
//{
//    /* if SVC exception occurs, go to infinite loop */
//    while(1) {
//    }
//}

/*!
    \brief      this function handles PendSV exception
    \param[in]  none
    \param[out] none
    \retval     none
*/
//void PendSV_Handler(void)
//{
//    /* if PendSV exception occurs, go to infinite loop */
//    while(1) {
//    }
//}

/*!
    \brief      this function handles SysTick exception
    \param[in]  none
    \param[out] none
    \retval     none
*/
void SysTick_Handler(void)
{
    delay_decrement();
    if(xTaskGetSchedulerState()!=taskSCHEDULER_NOT_STARTED)//系统已经运行
    {
        xPortSysTickHandler();        
    }
}

      PendSV_Handler()与 SVC_Handler()这两个很重要的函数 在 port.c 文件中已经实现 xPortPendSVHandler()与 vPortSVCHandler()函 数.SysTick_Handler提供系统节拍。

4.在FreeRTOSConfig.h配置。这里定义下HEAP_SIZE等,留意下SystemCoreClock为系统时钟。

/* Ensure stdint is only used by the compiler, and not the assembler. */
#if  defined(__ICCARM__) || defined(__CC_ARM) || defined(__TASKING__) || defined(__GNUC__)
	#include <stdint.h>
	extern uint32_t SystemCoreClock;
#endif

#define configTOTAL_HEAP_SIZE			( ( size_t ) ( 30 * 1024 ) )


/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
standard names. */
#define vPortSVCHandler SVC_Handler
#define xPortPendSVHandler PendSV_Handler
//#define xPortSysTickHandler SysTick_Handler


5.创建任务,启动调度器


void user_task(void *pvParameters)
{
    while(1)
    {
        printf("Run  user_task\r\n");
        vTaskDelay(1000);
    }
}

int main(void)
{
	/*
     ...
    */
					
     /* init task */
    xTaskCreate(user_task, "INIT", configMINIMAL_STACK_SIZE * 2, NULL, 3, NULL);

    /* start scheduler */
    vTaskStartScheduler();
	while(1);
}

6.编译配置,在C/C++选项卡下,去掉勾选Execute-only Code,如下

图4:编译配置

三.编译烧录测验

      编译烧录后,打开串口工具,按复位键,可看到任务创建成功并运行。

图5:FreeRTOS系统运行日志

     至此,实现了开发板MCU GD32H759IMK6的FreeRTOS系统移植。        

IAR

iar的移植,和keil一样,唯一的区别就是port.c这里,如果按照keil的路径选择编译不成功。

iar的选择应该如下:

选择IAR路径下的,同时将portasm.s也添加到工程里,这里面实现了一些底层的东西,不然链接的时候一堆extern 声明的显示找不到定义。

注意:portasm.s是汇编语言,需要在汇编的工程选项中添加头文件路径

  • 24
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值