cancel
Showing results for 
Search instead for 
Did you mean: 

Using FreeRTOS with STM32 STOP0/1/2 Mode

Rogers.Gary
Senior II

Hi,

Looking for ANY references to or better yet, a coded example of how to set up an STM32L processor with FreeRTOS and wake up from STOP0 mode on an RTC calendar event.

FreeRTOS and sleep mode isn't an issue, that works fine. However anything more than this it appears no one has either done it, or not willing to share the secret that is power saving with RTOS. Or Google is not finding it...

Thanks a lot if you can help.

2 REPLIES 2
Jack Peacock_2
Senior III

Not really a secret, more that it's very application specific. To enter a low power mode all unnecessary tasks and peripherals need to be suspended first. That usually involves running down the list of tasks, notifying each one to go into suspend after powering down it's associated hardware, along with a wakeup source if it' related to the task. And a task not yet suspended may hang waiting on a suspended task, so there are race conditions to avoid in order to ensure tasks are in a known state before going into STOP mode.

This includes shutting down Systick or whatever timer is used for the FreeRTOS timebase. Which means no task must be blocked for some tick count, since the scheduler and systick aren't running.

When a wakeup event occurs all the suspended tasks and peripherals need to be resumed, so another rundown list is needed for all the suspended tasks. Like suspending the resume process is sensitive to race conditions so some type of synchronization is needed )I use event groups for this).

It's not a trivial process. I create a power management task to handle all this. It's the first task to start, last to suspend, first to resume. Every task uses an event queue. The p[ower management sends messages to trigger task suspension, synchronized with an event group. On wakeup the power task runs down the resume list, restarting each task. All tasks wait on an event group before continuing, to ensure everything is synchronized.

I have no idea how this can be done with the HAL and Cube, so no advice there.

Jack Peacock

Rogers.Gary
Senior II

Thanks John....please see below.

I'm looking for the first STOP mode below wake that will provide a reasonable degree of power saving performance. Doesn't need to go to nanoamps, even a couple hundred uA's consumption is OK.

You said: "Which means no task must be blocked for some tick count, since the scheduler and systick aren't running."

Can you clarify....are you stating as a matter of course? Since tasks are suspended first, it should be safe to then suspend TIMx (using timer fro FreeRTOS)?

As I mentioned - I want the RTC to "wake" every 48 hours. However - I also need the flexibility to also use a task that might run every 10 seconds to check the status of a value or a pin. I understand the RTC will keep ticking regardless of the RTOS tick being suspended, so it will wake up, then I can resume the "power control" task/event and go from there.

However - in the case of the task with a 10 second timer - will this execute the same? If the RTOS TIMx is suspended, how will the task know it's time to execute?

Thanks.