移植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'的滴答执行时调用原来的滴答定时器处理函数

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

相关推荐
Brilliantwxx9 小时前
【STM32】 初认识USART串口
linux·stm32·单片机·嵌入式硬件·架构
分享资料9 小时前
用小电容消除高频信号的原因
嵌入式硬件·硬件工程
沐欣工作室_lvyiyi10 小时前
基于STM32的人脸识别门禁系统的设计与实现(论文+源码)
stm32·单片机·嵌入式硬件
这张生成的图像能检测吗10 小时前
(论文速读)GMA-Net:面向嵌入式物联网设备的航空发动机损伤检测轻量级实时网络
物联网·目标检测·缺陷检测·轻量化·设备部署
wtblszn11 小时前
光伏封装产线智能管理平台方案
网络·物联网
星恒讯工业路由器12 小时前
分布式光伏站点分散难联网?4G/5G点对多点自组网方案解析
分布式·物联网·5g·分布式光伏·自组网·点对多点通信·4g/5g
zcmodeltech13 小时前
智慧矿山沙盘模型多场景控制系统设计——基于STM32与Modbus RTU的智能开采、无人矿卡、数字孪生全场景联动方案
数据库·stm32·单片机·嵌入式硬件·物联网
youcans_14 小时前
【嵌入式软件AI编程】03. STM32 VS Code 开发环境与工具链
stm32·单片机·ai编程·嵌入式软件·claude code
国科安芯14 小时前
抗辐射MCU在低轨卫星电源管理单元中的电压监测与保护策略研究
大数据·单片机·嵌入式硬件·电源管理·低轨卫星·抗辐射·星间链路
2601_9539880714 小时前
Ricon组态实时监控 - 毫秒级数据可视化
前端·物联网·数学建模·信息可视化·架构·前端框架