In Freertos tickless mode,system not entering stop mode?

Hi everyone,

I’m currently working on putting my STM MCU system into stop mode for low power consumption while using FreeRTOS. Here’s the setup of my project:

  1. A default task whereosDelay(1) is called.
  2. A second task where I’m working with the CAN protocol. I am using a software timer to push a message into a queue; the timer periodicity is 10 seconds.The CAN task starts its treatment when a message is received from the queue.
    In the CAN task, after some lines of code for CAN communication testing, I have an osDelay(5000) to enter the system into stop mode for low power.
    The expected behavior is that the system should enter stop mode after the osDelay(5000) in the CAN task. However, the system is not entering stop mode as expected. Interestingly, if I increase the value of the osDelay in the default task, the system then enters stop mode. When debugging, after the osDelay in the CAN task, it enters stop mode.

What could be the issue causing the system not to enter stop mode as expected with the current osDelay settings? Any insights or suggestions would be greatly appreciated.

Thanks in advance!

FreeRTOS will not induce a tickless period if a task (any task) will become ready in 1 tick. So your observations are as expected. If the next task to become ready is 2 or more ticks away, then FreeRTOS will induce a tickless idle period. The “2” is actually configEXPECTED_IDLE_TIME_BEFORE_SLEEP, where 2 is a minimum value.

However, one observation is not expected:

1 Like

Thank you for your reply, can you tell me more why isn’t this observation expected?

Can you elaborate on what you mean by the following line:

When debugging, after the osDelay in the CAN task, it enters stop mode.

Are you saying that the system enters sleep mode without increasing the value of the osDelay in the default task?

No, when I increase the osDelay in the default task, the system enters sleep mode, whether it is after the osDelay of the default task or the osDelay of the CAN task.

Great, then the behavior is explained by @jefftenney’s explanation.

If the next task to become ready is 2 or more ticks away, then FreeRTOS will induce a tickless idle period. 
1 Like