移植FreeRTOS于LPC54608芯片,IAR

1.源码下载

· 在移植之前,我们首先要获取到FreeRTOS的官方的源码包

FreeRTOS - Market leading RTOS (Real Time Operating System) for embedded systems with Internet of Things extensions

直接在官网下载freertos源码包。

下载后打开文件夹 可以看到:

进入FreeRTOS文件夹

然后在打开Source

2.移植

在你的原有项目中,新建一个FreeRTOS文件夹

然后将源码文件\FreeRTOSv202212.01\FreeRTOS\Source中的几个.c文件复制到freeRTOS文件夹中

然后新建include和portable文件夹

然后我们回到源码文件夹,点开Source,确定好你用的是哪个IDe,我用的是IAR

所以进入SOurce后,点开portable,找到IAR

然后去网上搜芯片型号,可知,lpc54608的架构是arm cortex M4,所以打开ARM_CM4F文件夹,将整个文件夹复制到工程FreeRTOS/portable中(我的项目中在freeRTOS中还新建了个IAR文件夹,然后将ARM_CM4F放入了portable/IAR中,其实没有必要 )

然后回到源码路径:source/portable中,找到memmang

也复制到工程FreeRTOS/portable中(其实只要ARM_CM4F和mengmang就行)

然后将源码文件中的include全部复制到FreeRTOS文件夹中

移植成功

3.工程修改

右键option,添加以下group:FreeRTOS,然后将FreeRTOS中整个include文件夹添加到inc文件中,FreeRTOS中的的七个.c文件加入,然后选择MemMang中的heap_4.c和ARM_CM4F中的三个文件加入

然后添加头文件路径,主要是FreeRTos中的include,然后ARM_CM4F,不放心的话,新建的几个文件夹都可以加进去。

如果这时候点击编译会发现,其报错SysTick_Handler出现重定义,这是因为,原来代码文件中含有SysTick_Handler,而FreeRTOS的port.c中也需要用的,一般只要把原工程文件的SysTick_Handler主注释掉留下port中的就行。

但是我原来程序中,有用到SysTick_Handler,直接注释会导致功能不完整,所以可以新建一个函数,因为原工程中的SysTick_Handler位于system_LPC54608.c,所以打开工程,注释掉SysTick_Handler,将其改为Original_SysTick_Handler。

cpp 复制代码
void Original_SysTick_Handler(void)
{
    if(!Delay_Enable) // 如果延时未启用
    {
        TimeMS++; // 计时增加
    }
    else
    {
        TimeTick++; // 延时计数增加
    }
}
//void SysTick_Handler(void)
//{
//    if(!Delay_Enable) // 如果延时未启用
//    {
//        TimeMS++; // 计时增加
//    }
//    else
//    {
  //      TimeTick++; // 延时计数增加
//    }
//}

然后回到port.c,注释掉原来的,修改为

cpp 复制代码
//void xPortSysTickHandler( void )
//{
//    /* The SysTick runs at the lowest interrupt priority, so when this interrupt
//     * executes all interrupts must be unmasked.  There is therefore no need to
//     * save and then restore the interrupt mask value as its value is already
//     * known. */
//    portDISABLE_INTERRUPTS();
//    {
//        /* Increment the RTOS tick. */
//        if( xTaskIncrementTick() != pdFALSE )
//        {
//            /* A context switch is required.  Context switching is performed in
//             * the PendSV interrupt.  Pend the PendSV interrupt. */
//            portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT;
//        }
//    }
//    portENABLE_INTERRUPTS();
//}
void xPortSysTickHandler(void)
{
    /* The SysTick runs at the lowest interrupt priority, so when this interrupt
     * executes all interrupts must be unmasked.  There is therefore no need to
     * save and then restore the interrupt mask value as its value is already
     * known. */
    portDISABLE_INTERRUPTS();
    {
        /* Increment the RTOS tick. */
        if(xTaskIncrementTick() != pdFALSE)
        {
            /* A context switch is required.  Context switching is performed in
             * the PendSV interrupt.  Pend the PendSV interrupt. */
            portNVIC_INT_CTRL_REG = portNVIC_PENDSVSET_BIT;
        }

        /* 调用原来的 SysTick 处理函数 */
        Original_SysTick_Handler();
    }
    portENABLE_INTERRUPTS();
}

实现FreeRTOS'的滴答执行时调用原来的滴答定时器处理函数

编译成功!测试后也没有发现问题

相关推荐
钡铼技术1 小时前
通过iFIX在ARMxy边缘计算网关上实现维护管理
人工智能·物联网·边缘计算·钡铼技术·armxy边缘计算网关
华清远见IT开放实验室4 小时前
【项目案例】物联网比较好的10+练手项目推荐,附项目文档/源码/视频
物联网·音视频
limingade4 小时前
手机实时提取SIM卡打电话的信令和声音-新的篇章(一、可行的方案探讨)
物联网·算法·智能手机·数据分析·信息与通信
redcocal9 小时前
地平线秋招
python·嵌入式硬件·算法·fpga开发·求职招聘
思为无线NiceRF11 小时前
全双工多路并发、低延时数传解决行业信号拥堵问题
物联网
辰哥单片机设计12 小时前
门磁模块详解(防盗感应开关 STM32)
stm32·单片机·嵌入式硬件·传感器
夜间去看海13 小时前
基于51单片机的自动清洗系统(自动洗衣机)
嵌入式硬件·51单片机·proteus·洗衣机
yrx02030713 小时前
stm32 IIC总线busy解决方法
stm32·单片机·嵌入式硬件
YHPsophie15 小时前
ATGM331C-5T杭州中科微BDS/GNSS全星座定位授时模块应用领域
经验分享·笔记·单片机·信息与通信·交通物流