Reducing power consumption using FreeRTOS sleep mode in a dual-threaded system

I’m currently working on a project where I have a dual-threaded system using FreeRTOS, and my primary goal is to minimize power consumption. I have two threads in my system, each with its own sleep requirements. Here’s what I’m trying to achieve:

  1. Thread 1: This thread needs to go into sleep mode every 1 minute after receiving valid data. The idea here is to conserve power when the thread is not actively processing any new data.
  2. Thread 2: This thread needs to go into sleep mode for every 5 minutes after sending data. The aim is to reduce power consumption during periods of inactivity, as the thread doesn’t have any immediate tasks to handle after data transmission.

To accomplish these goals, I’m looking for guidance on how to effectively utilize FreeRTOS’s sleep mode functionality. How can I implement this in my system to achieve the desired power savings?


A great place to start is tickless idle. A default implementation of tickless idle is provided by FreeRTOS for Cortex M targets.

In FreeRTOSConfig.h, add this:

#define configUSE_TICKLESS_IDLE 1

Then, any time both of your tasks are sleeping, FreeRTOS will put the ESP32 into a basic sleep mode.

Note, “Threads” going to sleep don’t save power, as the processor just goes to another task. This is also not normally called “sleeping”, but the thread BLOCKING.

You save power by having the PROCESSOR go to sleep.

It sounds like you want Thread 1 to block for up to a minute waiting to get data, and after that mark that it thinks it is ok to put the processor into a deeper sleep, and Thead 2 to similarly block for up to 5 minutes waiting for data to send (or maybe you can know if you aren’t going to get more data to send). If both agree, then perhaps you can enter a deeper sleep than just tickless idle.

Here’s the ESP32 reference for sleep modes: Sleep Modes - ESP32 - — ESP-IDF Programming Guide latest documentation

Using light/deep sleep with an RTC timer wakeup could be useful for this application. The wifi stack will have to be stopped if using either of the sleep modes. Any active connections will be lost, however.