LOGBOOK

HELP

Quiz Entry - updated: 2026.09.25

In the FreeRTOS blink code, what do xTaskCreate and vTaskDelay do?

xTaskCreate registers the blink function as a new task with a name, stack size, argument and priority; vTaskDelay(500 / portTICK_PERIOD_MS) blocks that task for 500 ms so the CPU is free for other work.

void blink_task(void *pvParameter) {
    gpio_set_direction(BLINK_GPIO, GPIO_MODE_OUTPUT);
    while (1) {
        gpio_set_level(BLINK_GPIO, 0);             /* LED off */
        vTaskDelay(500 / portTICK_PERIOD_MS);
        gpio_set_level(BLINK_GPIO, 1);             /* LED on  */
        vTaskDelay(500 / portTICK_PERIOD_MS);
    }
}

void app_main(void) {
    xTaskCreate(&blink_task,           /* task function            */
                "blink_task",          /* descriptive name         */
                configMINIMAL_STACK_SIZE, /* stack depth           */
                NULL,                  /* argument -> pvParameter  */
                5,                     /* priority                 */
                NULL);                 /* task handle (not needed) */
}
  • The task function is an endless loop. Tasks are long-living; returning from one is not allowed.
  • xTaskCreate gives the task its own stack of the requested size (in words in standard FreeRTOS, in bytes on ESP-IDF), puts it in the Ready state at priority 5, and returns. app_main is ESP-IDF's entry point and itself runs as a FreeRTOS task.
  • vTaskDelay takes a count of ticks, not milliseconds; dividing by portTICK_PERIOD_MS converts 500 ms into ticks (50 ticks at a 100 Hz tick rate). The newer pdMS_TO_TICKS(500) macro does the same.

The crucial difference from a busy-wait for loop is that vTaskDelay moves the task into the Blocked state. For those 500 ms it consumes no CPU, so other tasks run, or the idle task lets the chip save power.

Tip: in an RTOS, never busy-wait. Block, and let the scheduler do the waiting.

Go deeper:

From Quiz: SIOT / Real-Time Operating Systems and Task Scheduling | Updated: Sep 25, 2026