# Wake and Sleep Using FreeRTOS on STM32F4/Cortex-M4

**URL:** <https://forums.freertos.org/t/wake-and-sleep-using-freertos-on-stm32f4-cortex-m4/6786>\
**Category:** Kernel\
**Created:** [September 19, 2017, 4:44am UTC](https://forums.freertos.org/t/wake-and-sleep-using-freertos-on-stm32f4-cortex-m4/6786 "2017-09-19T04:44:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [September 19, 2017, 4:44am UTC](https://forums.freertos.org/t/wake-and-sleep-using-freertos-on-stm32f4-cortex-m4/6786/1 "2017-09-19T04:44:44Z")

</div>

**[groger57](https://sourceforge.net/u/groger57/)** wrote on [Tuesday, September 19, 2017](https://sourceforge.net/p/freertos/discussion/382005/thread/587fe29a/#6779):

Hello:  
I’m using an STM32F4 and have FreeRTOS 9.0.0 implemented.  
There’s now a requirement to sleep (then wake) the device for short intervals to save battery power. Are there some examples using FreeRTOS on how this could be implemented?

Thank you for any guidance on this.

---

<div class="post-metadata">

**Author:** ![McuOnEclipse](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/mcuoneclipse/32/32_2.png) [@McuOnEclipse](https://forums.freertos.org/u/McuOnEclipse)\
**Post date:** [September 19, 2017, 5:24am UTC](https://forums.freertos.org/t/wake-and-sleep-using-freertos-on-stm32f4-cortex-m4/6786/2 "2017-09-19T05:24:38Z")

</div>

**[xz8987f](https://sourceforge.net/u/xz8987f/)** wrote on [Tuesday, September 19, 2017](https://sourceforge.net/p/freertos/discussion/382005/thread/587fe29a/#5fac):

Hello,  
there are two basic things you can use:

- tickless idle mode (reducing the amount of tick interrupts)
- going into low power mode in the IDLE hook  
See [http://www.freertos.org/low-power-tickless-rtos.html](http://www.freertos.org/low-power-tickless-rtos.html) and [http://www.freertos.org/RTOS-idle-task.html](http://www.freertos.org/RTOS-idle-task.html)

You might have a read at [https://mcuoneclipse.com/2013/07/06/low-power-with-freertos-tickless-idle-mode/](https://mcuoneclipse.com/2013/07/06/low-power-with-freertos-tickless-idle-mode/) and [https://mcuoneclipse.com/2014/02/09/iot-freertos-down-to-the-micro-amps/](https://mcuoneclipse.com/2014/02/09/iot-freertos-down-to-the-micro-amps/).

I hope this helps,  
Erich

---

<div class="post-metadata">

**Author:** ![htibosch](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/htibosch/32/62_2.png) [@htibosch](https://forums.freertos.org/u/htibosch)\
**Post date:** [September 19, 2017, 6:43am UTC](https://forums.freertos.org/t/wake-and-sleep-using-freertos-on-stm32f4-cortex-m4/6786/3 "2017-09-19T06:43:09Z")

</div>

**[heinbali01](https://sourceforge.net/u/heinbali01/)** wrote on [Tuesday, September 19, 2017](https://sourceforge.net/p/freertos/discussion/382005/thread/587fe29a/#5409):

> There’s now a requirement to sleep the device for short intervals

Often it is more beneficial to sleep for **longer intervals** like 30 seconds or more. It is necessary to use tickless idle for that.

Can you tell which situations ( = i.e. which interrupts ) should wake-up your device? When that situation occurs, should it wake-up immediately?

Beside those great references mentioned by Erich, don’t forget to read AN4365 and RM0090 about the STM32F4 Power Controller.

Also think about each GPIO : pins that are defined as outputs, and/or pins that have an internal pull enabled, may consume power, depending on the circuit. When their actual output during sleep is not important, consider making them “inputs”. Floating ( undefined ) inputs may also increase consumption: when a level is around `VCC / 2`, the input logic may be unstable ( on/ off/ on). In those cases an internal pull may be useful.

Good luck.

---

<div class="post-metadata">

**Author:** ![system](https://d2v6vdsk2p900z.cloudfront.net/original/1X/7fc8fdb729c645aab5b20282bbe34e57cb407be6.jpeg) [@system](https://forums.freertos.org/u/system)\
**Post date:** [September 19, 2017, 9:55pm UTC](https://forums.freertos.org/t/wake-and-sleep-using-freertos-on-stm32f4-cortex-m4/6786/4 "2017-09-19T21:55:07Z")

</div>

**[groger57](https://sourceforge.net/u/groger57/)** wrote on [Tuesday, September 19, 2017](https://sourceforge.net/p/freertos/discussion/382005/thread/587fe29a/#ad57):

Thank you for the references, I’ll be sure to read them.

The sleep duration will be only 2 seconds, then it will self-wake. I was plannng on using the RTC to accomplish this. In my case, I have no external oscillator, but have already configured and tested the LSI for the RTC and it appears to be “ticking”. For what I would like to do, it’s accuracy should be OK.

The reason for doing so is to save power - the controller can be sleeping for up to 2 seconds, self-wake, check for the presence of a signal, and if there is a signal, execure the tasks. If not, back to sleep. I’m hoping to save at least 50% of the overall power consumption, provided there’s not a penalty for sleep/wake itself.

Yes - I already have all unused pins set as inputs and pulled high.
