1

I have encountered a pretty strange problem while I was exploring the capabilities of FreeRtos on a ESP32 Wrover module. Currently, I have two tasks in my program. The first task will be used to collect some data, and the second one will be dedicated to print out debug messages to the serial monitor. These task use a queue to exchange data. Since I want to create a few more tasks in the system, the data collector task recieves the queue as part of a parameter struct. Here is my problem: if the data collector task sends only one message to the queue, the program works perfectly. But if I tried to add another message to the queue (as shown in the last piece of code), it forced the CPU to encounter a "LoadProhibited" exception. From what I have read in other topics, this problem is usually caused by accessing a NULL pointer somewhere in the program. But as you can see in the code below, I tried to add some protection by checking the pointers before adding anything to the queue. I also tried to raise the amount of allocated memory of the tasks, and pinning both task to core 1. I still got the same result. Here is the main:

static QueueHandle_t debugMsgQueue      = NULL;
static QueueHandle_t sensorDataBufQueue = NULL;

TaskHandle_t debugTaskHandle        = NULL;
TaskHandle_t sensorTaskHandle       = NULL;

uint32_t sensorTaskWatchdog;

ESP32Time rtc;

void StreamDebugger(void* pvParameters) {
char debugMsg[_debugDataLength];

while (1) {
    if (debugMsgQueue != NULL) {
        if (xQueueReceive(debugMsgQueue, (void*)debugMsg, portMAX_DELAY) == pdPASS) {
            Serial.print(debugMsg);
        }
    }
}
}

void setup(){

Serial.begin(115200);
EEPROM.begin(_eepromSize);

/*CREATING GLOBAL DATA BUFFERS*/
debugMsgQueue       = xQueueCreate(5, sizeof(char[_debugDataLength]));
sensorDataBufQueue  = xQueueCreate(2, sizeof(char*));

if (debugMsgQueue == NULL || sensorDataBufQueue == NULL) {
    Serial.print("\r\nCouldn't create dataBuffers. Aborting operation.");
}

BaseType_t xReturned;

/*DEBUG MESSAGE HANDLER TASK*/
xReturned = xTaskCreate(StreamDebugger, "DEBUG", 2048, NULL, 1, &debugTaskHandle);
if (xReturned != pdPASS) {
    Serial.print("\r\nCouldn't create DEBUGTASK. Aborting operation.");
}

/*MEASURMENT HANDLER TASK*/
const ReadSensorsParameters sensorTaskDescriptor{ &debugMsgQueue,&sensorDataBufQueue,&sensorTaskWatchdog,rtc};

xReturned = xTaskCreate(ReadSensors, "GETDATA", 4096, (void*)&sensorTaskDescriptor, 1, &sensorTaskHandle);
if (xReturned != pdPASS) {
    Serial.print("\r\nCouldn't create GETDATATASK. Aborting operation.");
}
}

void loop(){

}

This is the struct which is used by the sensor data collector task:

typedef struct READSENTASKPARAMETERS {
QueueHandle_t* debugQueue;
QueueHandle_t* dataQueue;
uint32_t* watchdog;
ESP32Time &systemClock;
}ReadSensorsParameters;

This is the data collector task, the one that works:

void ReadSensors(void* pvParameters) {
ReadSensorsParameters* handlers = (ReadSensorsParameters*) pvParameters;

char debugMsg[_debugDataLength];
char dataMsg[_msgDataMaxLength];

strcpy(debugMsg, "READSENSORTASK");
if (debugMsg != NULL && *handlers->debugQueue != NULL) {
    xQueueSend(*handlers->debugQueue, (void*)debugMsg, portMAX_DELAY);
}
vTaskDelete(NULL);
}

And here is the modified task, which, for some reason does not work at all:

void ReadSensors(void* pvParameters) {
ReadSensorsParameters* handlers = (ReadSensorsParameters*) pvParameters;

char debugMsg[_debugDataLength];
char dataMsg[_msgDataMaxLength];

strcpy(debugMsg, "READSENSORTASK");
if (debugMsg != NULL && *handlers->debugQueue != NULL) {
    xQueueSend(*handlers->debugQueue, (void*)debugMsg, portMAX_DELAY);
}
if (debugMsg != NULL && *handlers->debugQueue != NULL) {
    xQueueSend(*handlers->debugQueue, (void*)debugMsg, portMAX_DELAY);
}
vTaskDelete(NULL);
}

And here is the error message I recieve: 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:1 load:0x3fff0018,len:4 load:0x3fff001c,len:1044 load:0x40078000,len:8896 load:0x40080400,len:5816 entry 0x400806ac READSENSORTASKGuru Meditation Error: Core 0 panic'ed (LoadProhibited). Exception was unhandled. Core 0 register dump: PC : 0x400d0e5c PS : 0x00060d30 A0 : 0x800889dc A1 : 0x3ffb2f80
A2 : 0x00000000 A3 : 0x3f400fad A4 : 0x3ffc07b8 A5 : 0x3ffb8058
A6 : 0x00000000 A7 : 0x00000000 A8 : 0x800d0e5a A9 : 0x3ffb2f70
A10 : 0x3ffb2f8a A11 : 0x3f400fbc A12 : 0x000000ff A13 : 0x0000ff00
A14 : 0x00ff0000 A15 : 0xff000000 SAR : 0x00000010 EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000000 LBEG : 0x4000142d LEND : 0x4000143a LCOUNT : 0xfffffff3

Backtrace: 0x400d0e5c:0x3ffb2f80 0x400889d9:0x3ffb2fe0

Does anyone have any idea?

2
  • What is the value of _debugDataLength?
    – Armandas
    Feb 19, 2022 at 15:17
  • I defined it as constexpr auto _debugDataLength = 50; Feb 19, 2022 at 18:41

1 Answer 1

1

SOLVED! Turned out (after a few sleepless nights) that

static const MyTaskParameters sensorTaskDescriptor{
    &debugMsgQueue,
    &sensorDataBufQueue,
    &sensorTaskWatchdog,
    rtc,
    &sensorTaskWatchdogSemaphore,
    &rtcSemaphore
};

had to be declared as a static variable. What I think had happened was that when READSENSORTASK was created, it immediately started running and was able to place data into the output buffer. After the first context switch the SETUP task was deleted automatically, and therefore this sensorTaskDescriptor variable was also deleted that is why next message placement invoked the LoadProhibited message. What is still weird for me is that I was trying to check all to pointers not to be NULL. I guess the faulty call was somewhere inside the xQueueSend function. Anyways, I hope this thread helps someone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.