"compiling error" FreeRTOS Arduino 库与 Visual Studio 2015 和 Visual Micro 插件



我最近安装了带有Arduino插件的MS Visual Studio 2015"Visual Micro";。一切都很好,上传草图等等。除了当我使用FreeRTOS时试图编译代码时。我通过Arduino IDE(库管理器)下载了FreeRTOS库。因此(在2015年微软VS中)我可以选择将该库包含在2015年的微软VS中。所以我把图书馆包括在我的一个草图中。下面是我的代码示例。在Arduino IDE中,我可以编译代码并将其上传到设备,但在MS VS中存在一些错误。

#include <timers.h>
#include <task.h>
#include <StackMacros.h>
#include <semphr.h>
#include <queue.h>
#include <projdefs.h>
#include <portmacro.h>
#include <portable.h>
#include <mpu_wrappers.h>
#include <list.h>
#include <FreeRTOSVariant.h>
#include <FreeRTOSConfig.h>
#include <event_groups.h>
#include <croutine.h>
#include <Arduino_FreeRTOS.h>
//define Tasks
void TaskBlinkSlow(void *pvParameters);
void TaskBlinkFast(void *pvParameters);
void setup()
{
/* add setup code here */
xTaskCreate(TaskBlinkSlow, "TaskSlow", 128, NULL, 1, NULL);
xTaskCreate(TaskBlinkFast, "TaskFast", 128, NULL, 2, NULL);
pinMode(13, OUTPUT);
}
void loop()
{
//Empty, things are done in tasks!!!
}
void TaskBlinkSlow(void * pvParameters)
{
for (;;) {
for (int i = 0; i < 8; i++) {
digitalWrite(13, HIGH);   
delay(1000); 
digitalWrite(13, LOW);  
delay(1000);
}

vTaskDelay(5000 / portTICK_PERIOD_MS); 
}
}
void TaskBlinkFast(void * pvParameters)
{
for (;;) {
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
}
}

在这篇文章的末尾,你会发现编译器错误日志的一小段。也许有人已经解决了同样的问题,并有了快速的解决方案。

已经创建了一个调试器断点示例。切换演示断点关闭,取消选择Visual Micro>教程模式。

正在为"Arduino/Genuino Uno"编译"FreeRTOS"的调试版本FreeRTOS.ino:在计时器包含的文件中。h:75:3:error:#error"include Arduino_FreeRTOS.h在include之前必须出现在源文件中定时器.h":#错误";include Arduino_FreeRTOS.h必须出现在源中之前的文件包括定时器;timers.h:包含在文件中FreeRTOS.ino:来自任务。h:75:3:错误:#error";包括Arduino_FreeRTOS.h必须在包含task.h之前出现在源文件中;:"错误";include Arduino_FreeRTOS.h必须出现在源文件中包括任务;task.h:在计时器中包含的文件中。h:来自FreeRTOS.ino:来自列表.h:99:3:错误:#error Arduino_FreeRTOS.h必须必须包含在列表之前。h:#error Arduino_FreeRTOS.h在列表之前。h FreeRTOS.ino:在semphr中包含的文件中。h:74:3:错误:

错误";包括Arduino_FreeRTOS.h";必须出现在源文件中的";包括semphr.h":#错误";包括Arduino_FreeRTOS.h";必须出现在

源文件在";包括semphr.h";semphr.h:包含在的文件中FreeRTOS.ino:来自队列。h:75:3:错误:#error";包括Arduino_FreeRTOS.h";必须出现在源文件中的";包括队列.h":#错误";包括Arduino_FreeRTOS.h";必须出现在源中在";包括队列.h";FreeRTOS.ino:包含在文件中list.h:99:3:error:#error之前必须包含Arduino_FreeRTOS.hlist.h:#error必须在list.h之前包含Arduino_FreeRTOS.htask.h:在计时器包含的文件中。h:来自FreeRTOS.ino:来自list.h:184:22:错误:"TickType_t"未命名类型:configLIST_VOLATILE TickType_t xItemValue*<价值是上市的在大多数情况下,这用于按降序对列表进行排序订单。*list.h:196:22:错误:"TickType_t"未命名类型:configLIST_VOLATILE TickType_t xItemValue列表。h:28:22:错误:"UBaseType_t"未命名类型:configLIST_VOLATILE UBaseType_tuxNumberOfItems列表.h:386:47:错误:之前应为初始值设定项'PRIVILED_FUNCTION:void vListInitialize(List_t*const pxList)PRIVILEGED_UNCTION列表.h:397:55:错误:之前需要初始值设定项'PRIVILED_FUNCTION:void vListInitializeItem(ListItem_t*constpxItem)PRIVILED_FUNCTION列表。h:410:77:错误:应为"PRIVILEGED_UNCTION"之前的初始值设定项:void vListInsert(List_t*const pxList,ListItem_t*const pxDewListItem)PRIVILEGED_UNCTIONlist.h:431:80:错误:"PRIVILED_FUNCTION"之前应为初始值设定项:void vListInsertEnd(List_t*常量pxList,ListItem_t*常量pxNewListItem)PRIVILED_FUNCTION列表。h:446:1:错误:"UBaseType_t"未命名类型:UBaseType_t uxListRemove(ListItem_t*constpxItemToRemove)PRIVILEGED_UNCTION timers.h:包含在的文件中FreeRTOS.ino:来自任务.h:109:20:错误:ISO C++禁止声明没有类型的"BaseType_t"[-fpermission]:typedef BaseType_t(*TaskHookFunction_t)(void*)任务。h:109:20:error:typedef"BaseType_t"已初始化(请改用decltype)任务。h:109:22:错误:未在此作用域中声明"TaskHookFunction_t":typedefBaseType_t(*TaskHookFunction_t)(void*)timers.h:包含在文件中from FreeRTOS.ino:from task.h:136:2:错误:"BaseType_t"未命名a type:BaseType_t xOverflowCount任务。h:137:2:错误:'TickType_t'未命名类型:TickType_t xTimeOnEntering任务。h:146:2:错误:"uint32_t"未命名类型:uint32_t ulLengthInBytestask.h:147:2:错误:"uint32_t"未命名类型:uint32-tulParameters task.h:155:2:错误:"TaskFunction_t"未命名类型:TaskFunction_t pvTaskCode任务。h:157:2:错误:"uint16_t"执行未命名类型:uint16_t usStackDepth任务。h:159:2:错误:"UBaseType_t"未命名类型:UBaseType_t uxPrioritytask.h:160:2:错误:"StackType_t"未命名类型:StackType_t*puxStackBuffer任务.h:161:27:错误:未在此作用域中声明"portNUM_CONFIGURABLE_REGIONS":MemoryRegion_t xRegions[portNUM_CONFIGURABLE_REGIONS]任务。h:170:2:错误:"UBaseType_t"执行不命名类型:UBaseType_t xTaskNumber;*唯一的数字任务。*task.h:1172:2:错误:"UBaseType_t"未命名类型:UBaseType_t uxCurrentPriority;*任务的优先级在填充结构时正在运行(可能是继承的)*task.h:173:2:错误:"UBaseType_t"未命名类型:UBaseType_tuxBasePriority;*如果任务的当前优先级已被继承以避免无限制的优先级获取互斥时的反转。仅当configUSE_MUTEXES为在FreeRTOSConfig.h*timers.h中定义为1:在文件中包括

如果您阅读了错误消息,就会清楚地解释这个问题。

include Arduino_FreeRTOS.h必须首先出现。

您的示例显示它包含在最后。把它放在第一位,错误就会消失。

Arduino_FreeRTOS.h包含了许多在其他地方使用的定义,因此它需要成为第一个定义。

与您的问题无关,但使用delay()是令人讨厌的,因为它不必要地消耗CPU周期。尝试使用vTaskDelay()作为替代方案,它将延迟(或阻止)到调度器来取消阻止其他任务或运行空闲任务,即Arduino loop()函数。

loop()函数可以使CPU进入睡眠状态,从而降低功耗。有关更多信息,请参阅feilipu.me关于主题的帖子。

vTaskDelay()计算Tick,因此需要除以以毫秒为单位的Tick周期。即。时间(单位:ms/portTICK_PERIOD_ms=Ticks )

#include <Arduino_FreeRTOS.h>
#include <croutine.h>
#include <event_groups.h>
#include <FreeRTOSConfig.h>
#include <FreeRTOSVariant.h>
#include <list.h>
#include <mpu_wrappers.h>
#include <portable.h>
#include <portmacro.h>
#include <projdefs.h>
#include <queue.h>
#include <semphr.h>
#include <Stack_Macros.h>
#include <task.h>
#include <timers.h>

void setup()
{
}
void loop() 
{
}

发现问题,includes的位置顺序错误:不知道为什么;)。您不能只在MS VS中包含freeRTOS,您需要自己更正包含的顺序。

这是正确的顺序:

#include <Arduino_FreeRTOS.h>
#include <croutine.h>
#include <event_groups.h>
#include <FreeRTOSConfig.h>
#include <FreeRTOSVariant.h>
#include <list.h>
#include <mpu_wrappers.h>
#include <portable.h>
#include <portmacro.h>
#include <projdefs.h>
#include <queue.h>
#include <semphr.h>
#include <StackMacros.h>
#include <task.h>
#include <timers.h>

我不确定您所指的Arduino代码,但通常没有理由直接包含FreeRTOSConfig.h,而是首先包含FreeRTOS。h,这将使端口层文件和FreeRTOSConfig.h文件的顺序正确,然后包含包含您要使用的API函数的头文件。

最新更新