All Posts

Tickless Mode in FreeRTOS Explained: Sleep Longer, Save More Power

1. Introduction

One of the biggest challenges in today's microcontroller-based systems is reducing power consumption. A common technique is to put the MCU into sleep or deep-sleep modes whenever the system is idle, only waking it up on interrupts.

In a FreeRTOS-based project, this becomes tricky because the kernel relies on the SysTick timer, a periodic interrupt that fires at a fixed rate such as every 1 ms. This constant tick means the CPU is regularly woken up even when no tasks are running, which prevents it from staying in low-power modes for long periods.

To solve this problem, FreeRTOS introduced tickless idle mode, a feature that suppresses unnecessary SysTick interrupts and allows the processor to remain in sleep longer, resulting in significant power savings.

2. What is Tickless Mode?

In a traditional FreeRTOS setup, the SysTick timer generates an interrupt at a fixed frequency, often every 1 millisecond. This tick drives the scheduler, timeouts, and task delays, but it also forces the CPU to wake up constantly, even if there is nothing useful to do.

Tickless mode changes this behavior. Instead of running periodic ticks at all times, FreeRTOS suppresses them when the system is idle. The kernel calculates when the next task or timeout is due and programs a hardware timer to wake the MCU at exactly that moment. Until then, the processor can stay in sleep or deep-sleep mode.

When the timer or an external interrupt finally wakes the system, FreeRTOS updates its internal tick counter to account for the time that has passed. To tasks, it looks as if all the ticks occurred normally, but in reality the CPU stayed asleep, saving power.

This approach allows microcontroller-based devices to extend battery life significantly without changing application code. Tasks continue to use the same delay and timeout APIs, while the OS takes care of the low-power optimization behind the scenes.

Normal mode vs Tickless mode

Figure 1: Normal mode vs Tickless mode — normal wakes the CPU every tick, tickless lets it sleep until the next real event

3. How to Use Tickless Mode in FreeRTOS

To enable tickless idle in FreeRTOS, you simply set configUSE_TICKLESS_IDLE = 1 in your FreeRTOSConfig.h. Once this is enabled, the kernel will call the function vPortSuppressTicksAndSleep() whenever the system becomes idle.

Inside this function, you decide how the MCU should sleep. In the simplest case, the CPU can just execute a Wait For Interrupt (WFI) instruction, which puts it into a low-power state until the next interrupt occurs.

When the processor wakes, FreeRTOS adjusts its internal tick counter with vTaskStepTick() to account for the time spent sleeping. This way, tasks still resume at the right time, but the system avoids unnecessary periodic wake-ups from the SysTick timer.

Example Implementation

The following example shows a minimal implementation:

void vPortSuppressTicksAndSleep(TickType_t expectedIdleTicks)
{
    if (expectedIdleTicks > 10) 
    {
        if (eTaskConfirmSleepModeStatus() != eAbortSleep)
        {
            disable_interrupts();
            
            /* Enter low-power mode until the next interrupt */
            __DSB();
            __WFI();
            __ISB();
            
            /* Correct the RTOS tick count */
            vTaskStepTick(expectedIdleTicks);
            
            enable_interrupts();
        }
    }
}

With this simple setup, FreeRTOS no longer wakes the CPU on every SysTick interrupt while idle. Instead, the processor stays in sleep mode until the next real event, which can lead to significant power savings in applications where the system spends most of its time waiting.

FreeRTOS tickless flow

Figure 2: FreeRTOS tickless flow — Scheduler runs the Idle task, checks if the system can sleep long enough

4. Benefits of Tickless Mode

Power Efficiency

The primary benefit of tickless idle mode is power efficiency. By suppressing unnecessary SysTick interrupts during idle periods, the CPU can remain in sleep or deep-sleep states for much longer stretches. This directly reduces energy consumption and extends the lifetime of battery-powered devices.

Transparent to Application Code

Another important advantage is that tickless mode is transparent to application code. Developers do not need to change how they write tasks — functions like vTaskDelay() or timeouts continue to work exactly as expected. FreeRTOS internally tracks the elapsed time and ensures tasks resume correctly after sleep.

Highly Effective for Idle Systems

Finally, tickless idle mode is highly effective in systems where the processor spends most of its time waiting. Examples include:

  • IoT devices
  • Wireless sensors
  • Wearables

In such cases, where workloads are often bursty, the reduction in unnecessary wakeups can translate into days, weeks, or even months of additional battery life.

5. Conclusion

Tickless mode lets FreeRTOS cut down unnecessary wakeups, keeping the CPU asleep longer and saving power. It's a simple feature that can make a big difference in battery-powered systems.

By enabling configUSE_TICKLESS_IDLE = 1 and implementing vPortSuppressTicksAndSleep(), developers can achieve significant power savings without modifying their application logic. This makes tickless mode an essential feature for any power-conscious embedded system using FreeRTOS.