What is the idle task and what is it used for?
Short answer: The idle task is created by the kernel at the lowest priority and runs whenever no other task is ready. In FreeRTOS it frees the memory of deleted tasks and calls an optional idle hook that applications use to enter low-power sleep, do background work, or measure CPU load. It must never block or take long, because then deleted tasks are not cleaned up and the system cannot sleep.
Uses of the idle hook (vApplicationIdleHook, configUSE_IDLE_HOOK)
- Power saving: execute
__WFI()so the CPU sleeps until the next interrupt (or use tickless idle for deeper sleep). - CPU load measurement: count how often the idle loop runs, or measure time spent in idle:
load = 1 − idle_time / total_time. - Low-priority background work that must never delay real tasks (e.g. scrubbing memory, non-urgent checks). Keep it short and non-blocking.
What it must not do: call blocking APIs (it must always be ready), or run long jobs (a task of equal priority 0 would wait; and stuck idle means memory from deleted tasks never gets freed).
Diagnostic value: if the idle task never runs, some task is busy-waiting or the system is overloaded, so many teams monitor idle time as a health metric and alarm when it drops below a threshold (e.g. 20%).
Zephyr: has an idle thread too; power management integrates with it automatically (CONFIG_PM).