Esp32 tasks cause system to crash/reset after 3-4 seconds

The problem occurs when i do NOT create a task pinned to a core.
Specifically the analogPollTask.
When i compile without it, i get resets every 3-4 seconds.
Plus for some reason when using TFT_eSPI (which i have to use) the debug output is complete gibberish so i have no idea what is going on.

I am using WiFI, utilizing the ESPAsyncWebServer.
(GitHub - me-no-dev/ESPAsyncWebServer: Async Web Server for ESP8266 and ESP32)
Disabling this does not prevent the crash however.

creating the tasks:

void Controller::launchTasks(){
    createFftTask();
    createRenderTask();
    createAnalogPollTask();
    fftToggledOn();
}

void Controller::createRenderTask(){
    #ifndef SCREEN_DISABLE
        xTaskCreatePinnedToCore(
            Renderer::renderSpectrumTaskWrapper,
            "renderTask",
            8000,
            (void*)renderer,
            2,
            &renderSpectrumTaskHandle,
            1
        );
    #endif
}

void Controller::createFftTask(){
    xTaskCreatePinnedToCore(
        Engine::fftTaskWrapper,
        "fftTask",
        6000,
        (void*)engine,
        1,
        &fftTaskHandle,
        0
    );
}

void Controller::createAnalogPollTask(){
    #ifndef ANALOG_DISABLE
        xTaskCreatePinnedToCore(
            AnalogManager::pollTaskWrapper,
            "analogPollTask",
            8000,
            (void*)analogManager,
            1,
            &analogPollTask,
            1
        );
    #endif
}

Engine's loop:

for(;;){
		readAudioData();
		executeFFT();
		xSemaphoreGive(goForRender);
	}

Renderer's loop:

for(;;) {
        if (xSemaphoreTake(goForRender, portMAX_DELAY)) {
            spectrum.drawSpectrum();
        }
    }

Analog job:

for(;;){
        //don't do anything with result
        //here just to keep the system from crashing
        analogRead(33);
    }

Main:

void setup(){

  Controller controller;
  controller.launchTasks();
  
  vTaskDelete(NULL);
}

void loop() {} 

In the Arduino environment you should always pin the task to a core as the Arduino's main task is also pinned.

You don't ask a question. You don't describe the problem in detail (does it occur if you start no additional task, if you don't start one specific task?). Is the NOT bound to the "pinned" word or to the "create" word (which would mean you do absolutely nothing, which doesn't make sense).

I'd guess you have to post your complete code to analyze the problem, as multitasking problems often are race conditions and they can originate from any code part.

In the Arduino environment you should always pin the task to a core as the Arduino's main task is also pinned

I delete the main loop task as it is shown in Main: vTaskDelete(NULL);
To my understanding this is what this line of code does.

You don't describe the problem in detail (does it occur if you start no additional task, if you don't start one specific task?)

The problem (getting resets every 3-4 seconds) occurs when i do NOT create the analogPollTask.

Is the NOT bound to the "pinned" word or to the "create" word

Since "NOT" is just before "create", it is bound to the word "create".

I'd guess you have to post your complete code to analyze the problem, as multitasking problems often are race conditions and they can originate from any code part.

Race conditions are presumably prevented since a semaphore is utilized, and in any case something like that would make sense if it occurred when I instantiated the analogPollTask, not when I omitted it completely from the codebase.

You don't ask a question

The question is: How do i avoid crashing the system, which i believe is deducible from what i provided. Being pedantic for the sake of being pedantic makes no sense. This is not stackoverflow

I believe i managed to solve the issue by changing the order of task creation :

  1. createRenderTask()
  2. createFftTask()

and refactoring as shown below:

void Controller::createRenderTask(){
    #ifndef SCREEN_DISABLE
        xTaskCreatePinnedToCore(
            Renderer::renderSpectrumTaskWrapper,
            "renderTask",
            4000,
            (void*)renderer,
            2,
            &renderSpectrumTaskHandle,
            0
        );
    #endif
}

void Controller::createFftTask(){
    xTaskCreatePinnedToCore(
        Engine::fftTaskWrapper,
        "fftTask",
        4000,
        (void*)engine,
        2,
        &fftTaskHandle,
        1
    );
}

P.S. By giving a relatively low priority to the tasks, the WiFI operations are given enough time to keep the system responsive.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.