FreeRTOS Deep Dive · Part 7 of 8
Low-Power RTOS & Tickless Idle
44:05
Part 7 / 8
🧠 FreeRTOS Deep Dive Series · 8 Parts
Part 7 of 8
Part 01
Scheduler, Priorities & Context Switch
55:30
Part 02
Task Notifications vs Event Groups
38:15
Part 03
Software Timers & Idle Hook Patterns
29:44
Part 04
Queues, Semaphores & Mutexes
42:18
Part 05
Memory Management & Heap Models
36:50
Part 06
Stack Sizing & Overflow Detection
31:20
Part 07
Low-Power RTOS & Tickless Idle
44:05
Part 08
Debugging & Trace with Tracealyzer
50:40
01
Overview
Battery-powered IoT devices live and die by average current draw. FreeRTOS's tickless idle mode lets the MCU sleep between ticks instead of spinning in the idle loop — cutting average current from milliamps to microamps. This part covers enabling it, configuring wake sources, and verifying the savings with a current probe.
- Enable tickless idle with
configUSE_TICKLESS_IDLE - Implement a custom sleep function using STM32 Stop Mode
- Reconfigure clocks correctly after waking from deep sleep
- Measure average current reduction on real hardware
02
Sleep Modes
Standard Idle
Idle task spins. Tick fires every 1ms. MCU never sleeps. Average current: 5–20mA.
configUSE_TICKLESS_IDLE = 0
Tickless Idle
FreeRTOS calculates max sleep time, programs a wake timer, and calls your sleep function. Average current: 10–100µA.
configUSE_TICKLESS_IDLE = 1
Custom Sleep
Override
vPortSuppressTicksAndSleep() for vendor-specific Stop/Standby modes and deepest possible sleep.configUSE_TICKLESS_IDLE = 2
03
Code
01
Custom tickless sleep on STM32low_power.c
C
#define configUSE_TICKLESS_IDLE 1 #define configEXPECTED_IDLE_TIME_BEFORE_SLEEP 2 void vPortSuppressTicksAndSleep(TickType_t xIdleTime) { uint32_t ms = xIdleTime * portTICK_PERIOD_MS; HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, ms, RTC_WAKEUPCLOCK_CK_SPRE_16BITS); // Enter STM32 Stop Mode — wakes on RTC or GPIO EXTI HAL_PWR_EnterSTOPMode(PWR_MAINREGULATOR_ON, PWR_STOPENTRY_WFI); // Stop mode resets PLL — must reconfigure clocks SystemClock_Config(); HAL_RTCEx_DeactivateWakeUpTimer(&hrtc); } void vSensorTask(void *pv) { TickType_t xLast = xTaskGetTickCount(); while(1) { ReadAndTransmit(); // ~8ms of work // System sleeps ~992ms per cycle vTaskDelayUntil(&xLast, pdMS_TO_TICKS(1000)); } }
Reconfigure clocks after Stop mode
On STM32, Stop mode resets the PLL. Always call
SystemClock_Config() after waking or all peripherals run at the wrong frequency.Continue the Series
Work through all 8 parts of the FreeRTOS Deep Dive to master real-time embedded systems programming.