Search code examples
esp32freertos

ESP32 task priority with respect to main loop


The function xTaskCreate allows to specify a uxPriority number, higher for higher priority as specified at https://www.freertos.org/a00125.html.

But how is this priority considered with respect to the main loop, e.g.:

void myTask(void *p) {
//
// Doing stuff...
//
}

void init() {

xTaskCreate(myTask, "myStuff", 8*1024, NULL, 1, NULL); // Priority 1 or any other number.

}

void app_main() {
    
    init();


    while (1) { 
    //
    // **myTaskMain** doing other stuff.
    //
    }
}

What will have high priority? The function myTask running via xTaskCreate or myTaskMain running inside the main loop?


Solution

  • According to this table in de documentation, the app_main task has priority 1, so in your example the tasks will have the same priority.

    Another way to get the priority of the app_main task is by calling uxTaskPriorityGet(NULL) (docs here) from app_main. If you want to change the priority of the app_main task you can do that by calling vTaskPrioritySet(NULL, uxNewPriority) (docs here) from app_main.