Why vTaskList and vTaskListTasks not working on FreeRTOS 11.0.1?

58 Views Asked by At

I am trying to debug a FreeRTOS application scheduling on a RP2040 Raspberry Pico using the functions vTaskList or vTaskLists and can't get any output on my serial line (minicom).

This is my main() on the source code:

    char pcWriteBuffer[0xFFFF];
    stdio_init_all();
    if (cyw43_arch_init()) {
        return -1;
    }

    xTaskCreate(external_led_task, "External_LED_Task", 256, NULL, 3, NULL);
    xTaskCreate(onboard_led_task, "Onboard_LED_Task", 256, NULL, 3, NULL);
    vTaskStartScheduler();

    vTaskList(pcWriteBuffer);
    printf("%s\n", pcWriteBuffer);




    while(1){};

My serial output via USB is already enabled on CMakeLists.txt and i have tested other printfs on the same code, showed properly on minicom.

pico_enable_stdio_usb(${ProjectName} 1)
pico_enable_stdio_uart(${ProjectName} 0)

I have already defined the two FreeRTOSConfig.h macros required to use these functions:

#define configUSE_TRACE_FACILITY                1
#define configUSE_STATS_FORMATTING_FUNCTIONS    1

I also tried using vTaskListTasks this way:

    char pcWriteBuffer[1024];
    vTaskListTasks(pcWriteBuffer, 1024);
    printf("%s\n", pcWriteBuffer);

I tried creating a task only for the vTaskList or vTaskListTasks, I don't know why but the program don't even run when I try this, tried the same task priority for all tasks.

1

There are 1 best solutions below

3
Clifford On

The buffer pcWriteBuffer is a 64KB object on the stack, on a part with only 256KB of RAM. Apart from being far larger than reasonably necessary for the task list (the documentation suggests 40 bytes per task), it is also larger than your likely main stack size, which will typically be a few KB. Make the buffer smaller and declare it static. vTaskList() blocks the scheduler, so there are no reentrancy issues with using a static.

However that is not the reason for your issue (although it is an issue). The primary issue is here:

    vTaskStartScheduler();

    vTaskList(pcWriteBuffer);
    printf("%s\n", pcWriteBuffer);

vTaskList() will never be called because vTaskStartScheduler() never returns as the documentation states:

vTaskStartScheduler() will only return if there is insufficient RTOS heap available to create the idle or timer daemon tasks.

It only makes sense to call vTaskList from a task context (or after creating tasks and before calling vTaskStartScheduler() perhaps, though that serves little purpose)