Skip to content

[BUG] xTaskGetTickCount strange behavior causes xTaskDelayUntil to always fail #1349

@ntd

Description

@ntd

I think that my loop starts with a last wake up time (last) greater than the current time (tick, from xTaskGetTickCount) and #1339 does the rest, so xTaskDelayUntil becomes a no-op and fails always.

  • Development board: ESP32-S3, dual core
  • Instruction Set Architecture: XTENSA32 LX7?
  • IDE and version: esp-idf 5.5.1
  • Toolchain and version: xtensa-esp-elf esp-14.2.0_20241119
  • Host OS: Archlinux

To Reproduce

#include "freertos/FreeRTOS.h"
#include <stdio.h>

static void loop(void *data)
{
        TickType_t last = xTaskGetTickCount();
        for (int i = 0; ; ++i) {
                if (xTaskDelayUntil(&last, 5) == pdFALSE) {
                        printf("Iteration %d too slow (last=%lu, tick=%lu)\n", i, last, xTaskGetTickCount());
                }
        }
}

void app_main(void)
{
        TaskHandle_t handle;
        xTaskCreate(loop, "TEST", 2048, NULL, 1, &handle);
        /* The following two lines trigger the issue */
        vTaskSuspend(handle);
        vTaskResume(handle);
}

With the above code, I get a busy loop that starts with:

Iteration 1 too slow (last=11, tick=2)
Iteration 2 too slow (last=16, tick=3)
Iteration 3 too slow (last=21, tick=3)
Iteration 4 too slow (last=26, tick=4)

Without vTaskSuspend/vTaskResume everything works as expected.

No idea how last can be greater than tick or if this is an issue specific to the dual core nature of the ESP32-S3 (i.e. the above code works on other architectures).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions