Я начинаю работу с межзадачным взаимодействием с FreeRTOS на esp32, следуя этому туториалу от pcbreflux, но я не могу собрать пример с esp-idf в VS Code, потому что два файла заголовков вызывают No such file or directory
ошибку:
#include "esp_heap_alloc_caps.h"
#include "freertos/heap_regions.h"
После некоторых исследований я обнаружил, что "esp_heap_caps.h"
может заменить "esp_heap_alloc_caps.h"
(может ли кто-нибудь подтвердить это?), и это действительно устраняет часть ошибок компиляции. Но "freertos/heap_regions.h"
все еще доставляет мне проблемы. Даже если я добавлю этот заголовочный файл вручную, я получаю ошибку компиляции undefined reference to xPortGetFreeHeapSizeTagged
. Я предполагаю, что это означает, что эта функция была удалена в пользу другой реализации. Что я должен использовать вместо этого?
Вот мой c_cpp_properties.json
:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"intelliSenseMode": "windows-msvc-x64",
"compileCommands": "${workspaceFolder}/build/compile_commands.json"
},
{
"name": "ESP-IDF",
"compilerPath": "c:\\Users\\arthu\\.espressif\\tools\\xtensa-esp32-elf\\esp-2021r2-patch5-8.4.0\\xtensa-esp32-elf\\bin\\xtensa-esp32-elf-gcc.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"includePath": [
"${config:idf.espIdfPath}/components/**",
"${config:idf.espIdfPathWin}/components/**",
"${config:idf.espAdfPath}/components/**",
"${config:idf.espAdfPathWin}/components/**",
"${workspaceFolder}/**"
],
"browse": {
"path": [
"${config:idf.espIdfPath}/components",
"${config:idf.espIdfPathWin}/components",
"${config:idf.espAdfPath}/components/**",
"${config:idf.espAdfPathWin}/components/**",
"${workspaceFolder}"
],
"limitSymbolsToIncludedHeaders": false
},
"configurationProvider": "ms-vscode.makefile-tools"
}
],
"version": 4
}
Мой CMakeLists.txt
внутри моей основной папки:
idf_component_register(SRCS "queue_main.c" INCLUDE_DIRS ".")
Мой CMakeLists.txt
внутри папки моего проекта:
cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(main)
И пример queue_main
:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "sdkconfig.h"
#include "esp_system.h"
#include "esp_heap_caps.h"
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "freertos/heap_regions.h"
#define COLOR_PRINT_BLACK "30"
#define COLOR_PRINT_RED "31"
#define COLOR_PRINT_GREEN "32"
#define COLOR_PRINT_BROWN "33"
#define COLOR_PRINT_BLUE "34"
#define COLOR_PRINT_PURPLE "35"
#define COLOR_PRINT_CYAN "36"
#define color_printf(COLOR, format, ...) \
{ \
printf("\033[0;" COLOR "m" format "\033[0m\n", ##__VA_ARGS__); \
}
xQueueHandle demo_queue;
void tx_task1(void *arg)
{
uint32_t txpos = 0;
color_printf(COLOR_PRINT_BLUE, "tx_task1");
while (1)
{
color_printf(COLOR_PRINT_BLUE, "free DRAM %u IRAM %u", esp_get_free_heap_size(), xPortGetFreeHeapSizeTagged(MALLOC_CAP_32BIT));
color_printf(COLOR_PRINT_BLUE, "tx_task1 notify %d", txpos);
if (xQueueSendToBack(demo_queue, &txpos, 1000 / portTICK_RATE_MS) != pdTRUE)
{
color_printf(COLOR_PRINT_RED, "tx_task1 fail to queue value %d", txpos);
}
vTaskDelay(10000 / portTICK_RATE_MS); // delay 10s
txpos++;
}
}
void tx_task2(void *arg)
{
uint32_t txpos = 0;
color_printf(COLOR_PRINT_CYAN, "\ttx_task2");
while (1)
{
color_printf(COLOR_PRINT_CYAN, "\tfree DRAM %u IRAM %u", esp_get_free_heap_size(), xPortGetFreeHeapSizeTagged(MALLOC_CAP_32BIT));
color_printf(COLOR_PRINT_CYAN, "\ttx_task2 notify %d", txpos);
if (xQueueSendToBack(demo_queue, &txpos, 1000 / portTICK_RATE_MS) != pdTRUE)
{
color_printf(COLOR_PRINT_RED, "\ttx_task2 fail to queue value %d", txpos);
}
vTaskDelay(7000 / portTICK_RATE_MS); // delay 7s
txpos++;
}
}
void rx_task(void *arg)
{
uint32_t rxpos;
color_printf(COLOR_PRINT_GREEN, "\t\trx_task");
while (1)
{
color_printf(COLOR_PRINT_GREEN, "\t\trx_task queue yield");
if (xQueueReceive(demo_queue, &rxpos, 60000 / portTICK_RATE_MS) != pdTRUE)
{ // max wait 60s
color_printf(COLOR_PRINT_RED, "\t\tfail to receive queued value");
}
else
{
color_printf(COLOR_PRINT_GREEN, "\t\tfree DRAM %u IRAM %u", esp_get_free_heap_size(), xPortGetFreeHeapSizeTagged(MALLOC_CAP_32BIT));
color_printf(COLOR_PRINT_GREEN, "\t\trx_task get queued value %d", rxpos);
}
if (uxQueueMessagesWaiting(demo_queue) == 0)
{ // no message? take a break
vTaskDelay(15000 / portTICK_RATE_MS); // delay 15s
}
}
}
void app_main()
{
color_printf(COLOR_PRINT_PURPLE, "start ESP32");
color_printf(COLOR_PRINT_PURPLE, "free DRAM %u IRAM %u", esp_get_free_heap_size(), xPortGetFreeHeapSizeTagged(MALLOC_CAP_32BIT));
demo_queue = xQueueCreate(10, sizeof(uint32_t));
color_printf(COLOR_PRINT_PURPLE, "free DRAM %u IRAM %u", esp_get_free_heap_size(), xPortGetFreeHeapSizeTagged(MALLOC_CAP_32BIT));
color_printf(COLOR_PRINT_PURPLE, "create three tasks");
xTaskCreate(tx_task1, "tx_task1", CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE, NULL, 5, NULL);
xTaskCreate(tx_task2, "tx_task2", CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE, NULL, 5, NULL);
xTaskCreate(rx_task, "rx_task", CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE, NULL, 5, NULL);
color_printf(COLOR_PRINT_PURPLE, "end of main");
}
Пожалуйста, дайте мне знать, если я должен предоставить более подробную информацию.
Я использую последнюю версию: 4.4.3
Какую макетную плату вы используете? В зависимости от цели сборки (MCU) определенные библиотеки недоступны...
Это плата разработчика ESP32-WROOM-32 от Az-Delivery. Я думаю, проблема в том, что xPortGetFreeHeapSizeTagged
устарела в esp-idf. Я просто не знаю, чем его заменить.
Согласно старой документации для xPortGetFreeHeapSizeTagged(BaseType_t tag)
:
Get the amount of free bytes in a certain tagged region.
Works like `xPortGetFreeHeapSize` but allows the user to specify a specific tag
Согласно документации для 4.4.3 вы можете использовать heap_caps_get_free_size(uint32_t caps)
вместо xPortGetFreeHeapSize
...
Parameters: caps – Bitwise OR of MALLOC_CAP_* flags indicating the type of memory
Returns: Amount of free bytes in the regions
Эти возможности определены в esp_heap_caps.h
.
Вы можете попробовать heap_caps_get_free_size(MALLOC_CAP_IRAM_8BIT)
.
Какую версию IDF вы используете?