PlatformIO Community

What is "r***ERROR***"?

I’m creating a mini FreeRTOS project based on ESP32.

This is my src code

#include <Arduino.h>

#define QUEUE_LEN       10u
#define BLINKED_MSG     "Blinked"
#define MSG_LEN_MAX     20u

typedef int duration_t;

#if CONFIG_FREERTOS_UNICORE
    static const BaseType_t app_cpu = 0;
#else
    static const BaseType_t app_cpu = 1;
#endif

static QueueHandle_t blinked_queue;
static QueueHandle_t duration_queue;

void rxMsgHandlerTask(void *param)
{

}

void ledControllerTask(void *param)
{

}

void setup() {
    Serial.begin(115200);
    vTaskDelay(1000 / portTICK_PERIOD_MS);
    Serial.println("---FreeRTOS 05 Assignment---");

    // Create queue:
    Serial.println("Creating queue...");
    blinked_queue = xQueueCreate(QUEUE_LEN, sizeof(BLINKED_MSG));
    duration_queue = xQueueCreate(QUEUE_LEN, sizeof(duration_t));

    // Create task:
    Serial.println("Creating task...");
    xTaskCreatePinnedToCore(rxMsgHandlerTask, "Msg Handler", 1024, NULL, 1, NULL, app_cpu);
    xTaskCreatePinnedToCore(ledControllerTask, "LED Controller", 1024, NULL, 1, NULL, app_cpu);
    
    Serial.println("Initialize succesfully");
}

void loop() {
  // put your main code here, to run repeatedly:
}

The code is built and uploaded successfully without any errors.

The point keep resetting after the code is uploaded, and I can not understand what the log want to imply here.

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:10124
load:0x40080400,len:5828
entry 0x400806a8
---FreeRTOS 05 Assignment---
Creating queue...
Creating task...
Initialize succesfully
E (1024) FreeRTOS: FreeRTOS Task "Msg Handler" should not r***ERROR*** A stack overflow in task Msg Handler has been detected.
abort() was called at PC 0x4008512c on core 1

ELF file SHA256: 0000000000000000

Backtrace: 0x40084ea0:0x3ffb82b0 0x40085115:0x3ffb82d0 0x4008512c:0x3ffb82f0 0x40086a1b:0x3ffb8310 0x400883b4:0x3ffb8330 0x4008836a:0x8cfcf05c
  #0  0x40084ea0:0x3ffb82b0 in invoke_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp32/panic.c:715
  #1  0x40085115:0x3ffb82d0 in abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp32/panic.c:715
  #2  0x4008512c:0x3ffb82f0 in vApplicationStackOverflowHook at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp32/panic.c:715
  #3  0x40086a1b:0x3ffb8310 in vTaskSwitchContext at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/tasks.c:4560
  #4  0x400883b4:0x3ffb8330 in _frxt_dispatch at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/portasm.S:406
  #5  0x4008836a:0x8cfcf05c in _frxt_int_exit at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/portasm.S:206

As you can see the log stated that

E (1024) FreeRTOS: FreeRTOS Task “Msg Handler” should not r***ERROR*** A stack overflow in task Msg Handler has been detected.

So what is r***ERROR*** and how should I fix this error?

No, you can’t just exit a thread function without calling vTaskDelete(NULL);. A task is supposed to be running forever or must terminate correctly. Doing so anyways is a violation of the FreeRTOS guidelines

Tasks are normally implemented as an infinite loop; the function which implements the task must never attempt to return or exit. Tasks can, however, delete themselves.

…and will also really upset the FreeRTOS component in ESP-IDF, which will immediately call abort(), killing the firmware.

Hence you see that the message is not supposed to be r***ERROR***, it’s just that due to buffering the “should not return, Aborting now!” message has not been sent out fully yet before the abort() occurrs and prints ***ERROR***

You can change the code to e.g.

void rxMsgHandlerTask(void *param)
{
    for(;;) {
       vTaskDelay(1000 / portTICK_PERIOD_MS);
    }
}

void ledControllerTask(void *param)
{
    for(;;) {
       vTaskDelay(1000 / portTICK_PERIOD_MS);
    }
}

so that the tasks idle all the time by delaying (through the RTOS, not blocking other tasks).

1 Like