windows clion MingW cmake 编译运行 FreeRTOS

说明

在 windows 平台上,使用 clion IDE,cmake 方式编译 FreeRTOS,编译工具链使用 MingW gcc

下载 FreeRTOS

  • 可以只下载FreeRTOS-Kernel,也可以下载整个 FreeRTOS(包括 git 子模块,体积较大)

  • https://github.com/FreeRTOS/FreeRTOS-Kernel.git

clion 工程目录

  • 目录如下,FreeRTOS-Kernel为 FreeRTOS 内核代码, port 为 FreeRTOS 适配, sim 为 main 函数入口,用户应用。
CMakeLists.txt FreeRTOS-Kernel port sim

编写CMakeLists.txt

  • 当前不直接使用FreeRTOS-Kernel自带的CMakeLists.txt,内容如下
cmake_minimum_required(VERSION3.15)project(rtos-sim)add_definitions(-DprojCOVERAGE_TEST=0)include_directories(port)include_directories(FreeRTOS-Kernel/include FreeRTOS-Kernel/portable/MSVC-MingW port)set(FREERTOS_SOURCES FreeRTOS-Kernel/croutine.c FreeRTOS-Kernel/event_groups.c FreeRTOS-Kernel/list.c FreeRTOS-Kernel/queue.c FreeRTOS-Kernel/stream_buffer.c FreeRTOS-Kernel/tasks.c FreeRTOS-Kernel/timers.c)set(FREERTOS_PORT_SOURCES FreeRTOS-Kernel/portable/MSVC-MingW/port.c FreeRTOS-Kernel/portable/MemMang/heap_4.c port/rtos_port.c)add_executable(rtos-sim sim/main.c${FREERTOS_SOURCES}${FREERTOS_PORT_SOURCES})target_link_libraries(rtos-sim winmm)
  • 【注意】PC端使用FreeRTOS-Kernel/portable/MSVC-MingW

  • port/rtos_port.c内容如下,主要为 FreeRTOS 需要适配的几个函数,其中 HOOK 函数可以为空函数

#include<stdio.h>#include"FreeRTOS.h"voidvAssertCalled(unsignedlongulLine,constchar*constpcFileName){}voidvApplicationGetIdleTaskMemory(StaticTask_t**ppxIdleTaskTCBBuffer,StackType_t**ppxIdleTaskStackBuffer,uint32_t*pulIdleTaskStackSize){staticStaticTask_t xIdleTaskTCB;staticStackType_t uxIdleTaskStack[configMINIMAL_STACK_SIZE];*ppxIdleTaskTCBBuffer=&xIdleTaskTCB;*ppxIdleTaskStackBuffer=uxIdleTaskStack;*pulIdleTaskStackSize=configMINIMAL_STACK_SIZE;}voidvApplicationGetTimerTaskMemory(StaticTask_t**ppxTimerTaskTCBBuffer,StackType_t**ppxTimerTaskStackBuffer,uint32_t*pulTimerTaskStackSize){staticStaticTask_t xTimerTaskTCB;staticStackType_t uxTimerTaskStack[configTIMER_TASK_STACK_DEPTH];*ppxTimerTaskTCBBuffer=&xTimerTaskTCB;*ppxTimerTaskStackBuffer=uxTimerTaskStack;*pulTimerTaskStackSize=configTIMER_TASK_STACK_DEPTH;}unsignedlongulGetRunTimeCounterValue(void){#if0LARGE_INTEGER liCurrentCount;unsignedlongulReturn;/* What is the performance counter value now? */QueryPerformanceCounter(&liCurrentCount);/* Subtract the performance counter value reading taken when the application started to get a count from that reference point, then scale to (simulated) 1/100ths of a millisecond. */if(llTicksPerHundedthMillisecond==0){/* The trace macros are probably calling this function before the scheduler has been started. */ulReturn=0;}else{ulReturn=(unsignedlong)((liCurrentCount.QuadPart-llInitialRunTimeCounterValue)/llTicksPerHundedthMillisecond);}returnulReturn;#endifreturn0;}voidvApplicationIdleHook(void){}voidvApplicationDaemonTaskStartupHook(void){}voidvConfigureTimerForRunTimeStats(void){#if0LARGE_INTEGER liPerformanceCounterFrequency,liInitialRunTimeValue;/* Initialise the variables used to create the run time stats time base. Run time stats record how much time each task spends in the Running state. */if(QueryPerformanceFrequency(&liPerformanceCounterFrequency)==0){llTicksPerHundedthMillisecond=1;}else{/* How many times does the performance counter increment in 1/100th millisecond. */llTicksPerHundedthMillisecond=liPerformanceCounterFrequency.QuadPart/100000LL;/* What is the performance counter value now, this will be subtracted from readings taken at run time. */QueryPerformanceCounter(&liInitialRunTimeValue);llInitialRunTimeCounterValue=liInitialRunTimeValue.QuadPart;}#endif}voidvApplicationTickHook(void){}voidvApplicationMallocFailedHook(void){printf("%s : memory alloc failed\n",__func__);}
  • port/FreeRTOSConfig.h,这个来自 FreeRTOS 的 demo,FreeRTOS\FreeRTOS\Demo\WIN32-MingW,基本可以不改动,如下
/* * FreeRTOS V202212.00 * Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of * the Software, and to permit persons to whom the Software is furnished to do so, * subject to the following conditions: * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * * https://www.FreeRTOS.org * https://github.com/FreeRTOS * */#ifndefFREERTOS_CONFIG_H#defineFREERTOS_CONFIG_H/*----------------------------------------------------------- * Application specific definitions. * * These definitions should be adjusted for your particular hardware and * application requirements. * * THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE * FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE. See * https://www.FreeRTOS.org/a00110.html *----------------------------------------------------------*/#defineconfigUSE_PREEMPTION1#defineconfigUSE_PORT_OPTIMISED_TASK_SELECTION1#defineconfigUSE_IDLE_HOOK1#defineconfigUSE_TICK_HOOK1#defineconfigUSE_DAEMON_TASK_STARTUP_HOOK1#defineconfigTICK_RATE_HZ(1000)/* In this non-real time simulated environment the tick frequency has to be at least a multiple of the Win32 tick frequency, and therefore very slow. */#defineconfigMINIMAL_STACK_SIZE((unsignedshort)70)/* In this simulated case, the stack only has to hold one small structure as the real stack is part of the win32 thread. */#defineconfigTOTAL_HEAP_SIZE((size_t)(100*1024))#defineconfigMAX_TASK_NAME_LEN(12)#defineconfigUSE_TRACE_FACILITY1#defineconfigIDLE_SHOULD_YIELD1#defineconfigUSE_MUTEXES1#defineconfigCHECK_FOR_STACK_OVERFLOW0#defineconfigUSE_RECURSIVE_MUTEXES1#defineconfigQUEUE_REGISTRY_SIZE20#defineconfigUSE_APPLICATION_TASK_TAG1#defineconfigUSE_COUNTING_SEMAPHORES1#defineconfigUSE_ALTERNATIVE_API0#defineconfigUSE_QUEUE_SETS1#defineconfigUSE_TASK_NOTIFICATIONS1#defineconfigSUPPORT_STATIC_ALLOCATION1/* Tick type width is defined based on the compiler type (32bit or 64bit). */#ifdef__x86_64__#defineconfigTICK_TYPE_WIDTH_IN_BITSTICK_TYPE_WIDTH_64_BITS#else#defineconfigTICK_TYPE_WIDTH_IN_BITSTICK_TYPE_WIDTH_32_BITS#endif/* Software timer related configuration options. The maximum possible task priority is configMAX_PRIORITIES - 1. The priority of the timer task is deliberately set higher to ensure it is correctly capped back to configMAX_PRIORITIES - 1. */#defineconfigUSE_TIMERS1#defineconfigTIMER_TASK_PRIORITY(configMAX_PRIORITIES-1)#defineconfigTIMER_QUEUE_LENGTH20#defineconfigTIMER_TASK_STACK_DEPTH(configMINIMAL_STACK_SIZE*2)#defineconfigMAX_PRIORITIES(7)/* Run time stats gathering configuration options. */unsignedlongulGetRunTimeCounterValue(void);/* Prototype of function that returns run time counter. */voidvConfigureTimerForRunTimeStats(void);/* Prototype of function that initialises the run time counter. */#defineconfigGENERATE_RUN_TIME_STATS1#defineportCONFIGURE_TIMER_FOR_RUN_TIME_STATS()vConfigureTimerForRunTimeStats()#defineportGET_RUN_TIME_COUNTER_VALUE()ulGetRunTimeCounterValue()/* Co-routine related configuration options. */#defineconfigUSE_CO_ROUTINES0#defineconfigMAX_CO_ROUTINE_PRIORITIES(2)/* This demo can use of one or more example stats formatting functions. These format the raw data provided by the uxTaskGetSystemState() function in to human readable ASCII form. See the notes in the implementation of vTaskList() within FreeRTOS/Source/tasks.c for limitations. */#defineconfigUSE_STATS_FORMATTING_FUNCTIONS0/* Enables the test whereby a stack larger than the total heap size is requested. */#defineconfigSTACK_DEPTH_TYPEuint32_t/* Set the following definitions to 1 to include the API function, or zero to exclude the API function. In most cases the linker will remove unused functions anyway. */#defineINCLUDE_vTaskPrioritySet1#defineINCLUDE_uxTaskPriorityGet1#defineINCLUDE_vTaskDelete1#defineINCLUDE_vTaskCleanUpResources0#defineINCLUDE_vTaskSuspend1#defineINCLUDE_vTaskDelayUntil1#defineINCLUDE_vTaskDelay1#defineINCLUDE_uxTaskGetStackHighWaterMark1#defineINCLUDE_uxTaskGetStackHighWaterMark21#defineINCLUDE_xTaskGetSchedulerState1#defineINCLUDE_xTimerGetTimerDaemonTaskHandle1#defineINCLUDE_xTaskGetIdleTaskHandle1#defineINCLUDE_xTaskGetHandle1#defineINCLUDE_eTaskGetState1#defineINCLUDE_xSemaphoreGetMutexHolder1#defineINCLUDE_xTimerPendFunctionCall1#defineINCLUDE_xTaskAbortDelay1#defineconfigINCLUDE_MESSAGE_BUFFER_AMP_DEMO0#if(configINCLUDE_MESSAGE_BUFFER_AMP_DEMO==1)externvoidvGenerateCoreBInterrupt(void*xUpdatedMessageBuffer);#definesbSEND_COMPLETED(pxStreamBuffer)vGenerateCoreBInterrupt(pxStreamBuffer)#endif/* configINCLUDE_MESSAGE_BUFFER_AMP_DEMO */externvoidvAssertCalled(unsignedlongulLine,constchar*constpcFileName);/* projCOVERAGE_TEST should be defined on the command line so this file can be used with multiple project configurations. If it is */#ifndefprojCOVERAGE_TEST#errorprojCOVERAGE_TEST should be defined to1or0on the command line.#endif#if(projCOVERAGE_TEST==1)/* Insert NOPs in empty decision paths to ensure both true and false paths are being tested. */#definemtCOVERAGE_TEST_MARKER()__asmvolatile("NOP")/* Ensure the tick count overflows during the coverage test. */#if(configTICK_TYPE_WIDTH_IN_BITS==TICK_TYPE_WIDTH_64_BITS)#defineconfigINITIAL_TICK_COUNT0xffffffffffffd800ULL#else#defineconfigINITIAL_TICK_COUNT0xffffd800UL#endif/* Allows tests of trying to allocate more than the heap has free. */#defineconfigUSE_MALLOC_FAILED_HOOK0/* To test builds that remove the static qualifier for debug builds. */#defineportREMOVE_STATIC_QUALIFIER#else/* It is a good idea to define configASSERT() while developing. configASSERT() uses the same semantics as the standard C assert() macro. Don't define configASSERT() when performing code coverage tests though, as it is not intended to asserts() to fail, some some code is intended not to run if no errors are present. */#defineconfigASSERT(x)if((x)==0)vAssertCalled(__LINE__,__FILE__)#defineconfigUSE_MALLOC_FAILED_HOOK1/* Include the FreeRTOS+Trace FreeRTOS trace macro definitions. */// #include "trcRecorder.h"#endif#endif/* FREERTOS_CONFIG_H */
  • 接下来就是sim/main.c,也就是主程序 main 函数,当前创建一个 FreeRTOS 的 task,如果 task 正常运行,就说明 FreeRTOS 在 PC 端适配初步成功
#include<stdio.h>#include"FreeRTOS.h"#include"task.h"#defineTEST_01_TASK_PRIORITY2#defineTEST_01_STACK_SIZE1024staticvoidtest_01(void*pvParameters){uint32_tcnt=0;while(1){vTaskDelay(2000*portTICK_PERIOD_MS);printf("%s : cnt = %d\n",__func__,cnt++);}}intmain(intargc,char*argv[]){xTaskCreate(test_01,"test_01",TEST_01_STACK_SIZE,NULL,TEST_01_TASK_PRIORITY,NULL);/* Start the scheduler itself. */vTaskStartScheduler();return0;}

编译与运行

  • clion 中 【同步】Cmake,然后进行编译,如果链接失败,注意确认
target_link_libraries(rtos-sim winmm)
  • windows 上链接winmmlib

  • 正常编译链接后,运行效果如下

  • 说明 FreeRTOS clion cmake 编译,然后成功运行在 windows 上了。后续一些 FreeRTOS 的开发与调试,比如开发一些组件,可以基于 windows 进行【模拟】调试验证,非常的方便,不需要实际的硬件开发板与调试器。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/1141212.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

构建高并发AI服务网关:C++与gRPC的工程实践

随着AI服务在企业中的规模化部署&#xff0c;如何高效、可靠地将多个异构AI模型集成到统一的服务架构中&#xff0c;成为后端工程师面临的重要挑战。本文介绍基于C与gRPC构建高并发AI服务网关的完整实践方案&#xff0c;涵盖架构设计、性能优化、容错机制等关键环节。 1. 问题背…

Java后端实习高频考点深度解析:美团27届后端开发二面全真复盘(限流·负载均衡·消息队列·链表分割)

Java后端实习高频考点深度解析&#xff1a;美团27届后端开发二面全真复盘&#xff08;限流负载均衡消息队列链表分割&#xff09; 阅读建议&#xff1a;本文适合准备大厂后端实习/校招的同学精读&#xff0c;建议配合动手实践与源码阅读&#xff0c;效果更佳。 在竞争日益激烈的…

AI 技能工程入门:从独立能力到协作生态

随着大型语言模型&#xff08;LLM&#xff09;能力的飞速发展&#xff0c;如何让它们稳定、高效地执行复杂任务&#xff0c;已成为AI工程化的核心挑战。作为应对&#xff0c;“技能”&#xff08;Skills&#xff09; 作为一种新兴的AI能力封装范式应运而生&#xff0c;而由其引…

提示工程架构实战:小样本场景下的模型压缩方案

提示工程架构实战:小样本场景下的模型压缩方案设计与落地 摘要/引言:小样本时代,我们需要怎样的模型压缩? 你有没有遇到过这样的困境? 为了做一个移动端的图像分类应用,你选了轻量级模型ViT-Tiny,但用5张图/类的小样本数据训练后,准确率勉强到70%;想再压缩模型大小(…

蟑螂的种类与预防方法

冬天来了&#xff0c;温度降到10以下&#xff0c;蚊子不见了&#xff0c;但是蟑螂却到处横行。有时候&#xff0c;打开包裹&#xff0c;或者移动沙发&#xff0c;突然窜出黄色的小颗粒&#xff0c;仔细一看&#xff0c;原来是蟑螂。这里介绍蟑螂的种类与预防方法。图(1) 蟑螂的…

Java版LeetCode热题100之滑动窗口最大值:从暴力解法到工业级最优解的深度剖析

Java版LeetCode热题100之滑动窗口最大值&#xff1a;从暴力解法到工业级最优解的深度剖析前言&#xff1a;为什么这道题值得深入研究&#xff1f; 在 LeetCode 热题 100 的榜单中&#xff0c;「滑动窗口最大值」&#xff08;LeetCode 239&#xff09;是一道极具代表性的算法题。…

大数据领域OLAP的用户权限管理

大数据OLAP权限管理&#xff1a;如何给数据加一把“智能锁”&#xff1f; 关键词&#xff1a;OLAP 权限管理 行列级权限 RBAC 数据安全 大数据 动态权限 摘要&#xff1a;在大数据时代&#xff0c;OLAP&#xff08;在线分析处理&#xff09;就像一个“数据超市”&#xff0c;让…

蓝牙低功蓝牙LTK跟传统蓝牙LinkKey互转技术介绍,Cross-transport key derivation(CTKD)

一. 概念 1. 概念 蓝牙CTKD是蓝牙4.2版本引入的一种交叉传输密钥派生的安全机制&#xff0c;全称 Cross-transport key derivation&#xff0c;主要用在蓝牙双模设备上&#xff0c;它可以跨越BLE和BT的边界&#xff0c;通过将BLE配对生成的LTK转化成BT配对的LinkKey&#xff…

亚马逊Java后端开发一面深度复盘:16道系统设计与底层原理高频题全解析(附工业级解决方案)

亚马逊Java后端开发一面深度复盘&#xff1a;16道系统设计与底层原理高频题全解析&#xff08;附工业级解决方案&#xff09;阅读建议&#xff1a;本文适合准备大厂后端岗位&#xff08;尤其是亚马逊、AWS、微软等外企&#xff09;的同学精读。建议结合动手实验与源码阅读&…

人机协作新模式:程序员与AI的共生关系

人机协作新模式:程序员与AI的共生关系 关键词:人机协作、程序员、AI、共生关系、编程效率、代码质量 摘要:本文深入探讨了程序员与AI之间的共生关系这一全新的人机协作模式。首先介绍了该研究的背景、目的、预期读者等内容。接着阐述了人机协作相关的核心概念与联系,分析了…

彼得林奇对公司并购后文化整合成功率的评估

彼得林奇对公司并购后文化整合成功率的评估 关键词:彼得林奇、公司并购、文化整合成功率、评估方法、企业管理 摘要:本文聚焦于彼得林奇对公司并购后文化整合成功率的评估。首先介绍了相关背景,包括研究目的、预期读者、文档结构和术语表。接着阐述了核心概念,如公司并购、…

MobaXterm高效运维实战技术文章大纲快速执行重复命令)

MobaXterm高效运维实战技术文章大纲简介MobaXterm的核心功能与优势&#xff08;SSH、X11、远程桌面、文件传输等&#xff09;适用场景&#xff1a;Windows平台下的Linux运维、开发调试、网络管理基础配置与优化安装与初始设置&#xff08;便携版与安装版的选择&#xff09;会话…

Hive执行模式对比:本地模式 vs 集群模式

Hive执行模式对比&#xff1a;本地模式 vs 集群模式的终极对决 关键词 Hive、本地模式、集群模式、大数据处理、执行计划、MapReduce、资源调度 摘要 作为Hadoop生态中最常用的数据仓库工具&#xff0c;Hive的执行模式选择直接影响着数据处理的效率与资源消耗。本文将通过&…

金融领域大数据文本挖掘实战案例解析

金融领域大数据文本挖掘实战案例解析&#xff1a;从海量噪音中提炼真金白银一、引言 钩子&#xff1a; “昨夜&#xff0c;某科技巨头财报中出现一个词&#xff1a;‘利润率承压’。瞬间&#xff0c;全球交易员屏幕飘红&#xff0c;万亿市值灰飞烟灭。而在另一个角落&#xff0…

国产麒麟系统卡启动项或图标如何解决

在使用国产麒麟系统的过程中&#xff0c;遇到开机卡启动项或者卡麒麟图标&#xff0c;如何解决&#xff1f;卡启动项和卡麒麟图标就如下图中的状态一样&#xff1b;那么如何解决呢&#xff1f;下面直接上干货&#xff0c;之前使用过的一个方法&#xff0c;分图解的形式来告诉你…

CAD(Creo)各模块的操作和配置

Creo各模块操作与配置详解1. Creo Parametric&#xff08;核心建模模块&#xff09;功能与操作草图设计&#xff1a;支持直线、圆弧、样条曲线等基本图元绘制&#xff0c;结合几何约束&#xff08;水平、垂直、相切等&#xff09;和尺寸标注&#xff08;线性、半径、角度等&…

速学!AI应用架构师分享金融市场AI监控系统的实时监控技术优化

速学!AI应用架构师分享金融市场AI监控系统的实时监控技术优化 关键词:金融市场监控、实时数据处理、AI异常检测、流处理架构、低延迟优化、机器学习模型、分布式系统 摘要:金融市场瞬息万变,每分钟甚至每毫秒的波动都可能带来巨大风险或机遇。传统监控系统常因响应迟缓、误…

RAR 、 ZIP、7z 之间的联系与区别

RAR 、 ZIP、7z之间的联系与区别RAR、ZIP 和 7z 是三种最主流的压缩文件格式&#xff0c;它们各有侧重和优缺点。下面我将从多个维度进行详细对比和介绍。 核心总结&#xff08;一目了然&#xff09; ZIP&#xff1a;通用性之王。历史最久、兼容性最广&#xff0c;是“默认选择…

主动学习在AI Agent训练中的应用

主动学习在AI Agent训练中的应用关键词&#xff1a;主动学习、AI Agent训练、机器学习、不确定性采样、查询合成摘要&#xff1a;本文深入探讨了主动学习在AI Agent训练中的应用。首先介绍了主动学习和AI Agent的背景知识&#xff0c;明确文章目的、预期读者和文档结构。接着阐…

工业协议全兼容:实时监控与智能控制

要实现对主流工业协议&#xff08;如 Modbus、Profinet、EtherCAT、OPC UA 等&#xff09;的支持&#xff0c;并完成 设备状态实时监控 与 指令下发 功能&#xff0c;通常需要构建一个具备协议兼容性、高实时性和安全性的工业通信平台。以下是关键设计思路和技术建议&#xff1…