【前言】
在MAX78000中有freertos的demo了但是他是基于EVKit1的,对于FTHR是没有FreeRTOS的Demo的,因此需要手工移植。现做分享如下:
【代码拷贝】
将sdk中的Freertos文件夹复制到工程中:
2、添加make file编译规则,在根目录的makefile中,修改规则如下:
VPATH += . VPATH += src VPATH += FreeRTOS/Source VPATH += FreeRTOS/Source/portable/GCC/ARM_CM4F VPATH := $(VPATH) # Where to find header files for this project IPATH += . IPATH += include IPATH += FreeRTOS/Source/include IPATH += FreeRTOS/Source/portable/GCC/ARM_CM4F IPATH := $(IPATH)
3、添加内存管理,我使用heap_4,由于在MemMang文件夹下有好几个内存管理的.c,我们可以删除其他的文件,将其添加到工程中参与编译,也可以指定编译这个文件,我这里指定编译文件:
AUTOSEARCH ?= 1 ifeq ($(AUTOSEARCH), 1) # Auto-detect all C/C++ source files on VPATH SRCS += $(wildcard $(addsuffix /*.c, $(VPATH))) SRCS += $(wildcard $(addsuffix /*.cpp, $(VPATH))) SRCS += FreeRTOS/Source/portable/MemMang/heap_4.c //指定编译文件 endif
4、复制一份在evkt1的的FreeRTOS_Debug.c、freertos_tickless.c、FreeRTOSConfig.h到工程中,然后在Main.c中添加测试代码,代码如下:
/****************************************************************************** * * Copyright (C) 2022-2023 Maxim Integrated Products, Inc. (now owned by * Analog Devices, Inc.), * Copyright (C) 2023-2024 Analog Devices, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ******************************************************************************/ /** * @file main.c * @brief Hello World! * @details This example uses the UART to print to a terminal and flashes an LED. */ /***** Includes *****/ #include <stdio.h> #include <stdint.h> #include "mxc_device.h" #include "led.h" #include "board.h" #include "mxc_delay.h" #include "FreeRTOS.h" #include "FreeRTOSConfig.h" #include "task.h" /***** Definitions *****/ /***** Globals *****/ /***** Functions *****/ /* 定义任务句柄 */ TaskHandle_t xTask1Handle = NULL; /* 任务函数声明 */ void vTask1(void *pvParameters); /* 任务1的实现 */ void vTask1(void *pvParameters) { /* 任务参数 */ int *param = (int *)pvParameters; /* 任务循环 */ for(;;) { /* 任务要执行的代码 */ printf("Task1 is running...\n"); /* 延时一段时间 */ vTaskDelay(pdMS_TO_TICKS(1000)); /* 延时1秒 */ } /* 注意:任务函数不应该返回,如果返回则必须调用vTaskDelete(NULL) */ vTaskDelete(NULL); } // ***************************************************************************** int main(void) { int count = 0; printf("Hello World!\n"); /* 创建任务1 */ xTaskCreate( vTask1, /* 任务函数 */ "Task1", /* 任务名称 */ configMINIMAL_STACK_SIZE, /* 栈大小 */ NULL, /* 传递给任务函数的参数 */ 1, /* 任务优先级 */ &xTask1Handle /* 任务句柄 */ ); /* 启动调度器 */ vTaskStartScheduler(); /* This code is only reached if the scheduler failed to start */ printf("ERROR: FreeRTOS did not start due to above error!\n"); while (1) { __NOP(); } while (1) { LED_On(LED1); MXC_Delay(500000); LED_Off(LED1); MXC_Delay(500000); printf("count : %d\n", count++); } }
【测试效果】
打开串口助手,可以看到周期打印,说明移植成功:
【总结】
在eclipse maxiSDK中,添加完源代码后,需要手工添加编译规则到工程,从而实现既定功能。值得注意的是,需要添加指定的内存管理文件为heap_4.c,如果没有指定,会报动态申请内存失败的错误。当然这也是官方给出了demo,自己不需要配置复杂的freertos的配置文件。