In this tutorial, we’ll discuss The STM32 Standby Mode, how to enter standby mode in STM32 microcontrollers, and how to exit from standby mode (Wakeup pin, RTC, etc) with some code examples and a full test project. Without further ado, let’s get right into it!
Table of Contents
- STM32 Standby Mode
- STM32 Enter Standby Mode
- STM32 Wakeup (Exit) Standby Mode
- STM32 Standby Mode Example Code Project
- Wrap Up
STM32 Standby Mode
The STM32 Standby mode is used to achieve the lowest power consumption with a brown-out reset. The internal regulator is switched OFF so that the VCORE domain is powered off. The PLL, the MSI RC, the HSI16 RC, and the HSE crystal oscillators are also switched OFF.
The RTC can remain active (Standby mode with RTC, Standby mode without RTC). Brown-out reset (BOR) always remains active in the Standby mode. The state of each I/O during standby mode can be selected by software: I/O with internal pull-up, internal pull-down, or floating.
The system can be woken up from standby mode using a SYS_WKUP pin, an RTC event (alarm or timer), IWDG, or an external reset in the NRST pin. After waking up from Standby mode, program execution restarts in the same way as after a Reset (boot pin sampling, option bytes loading, reset vector is fetched, etc.).
For the STM32L432KC target microcontroller, in Standby Mode, the current consumption is:
- Standby Mode at 25°C and VDD = 3V, the current consumption should be 90nA
To put things into perspective, this same target microcontroller (STM32L432KC) draws 72μA of current while operating in the DeepSleep (Low-Power Sleep) Mode. Even in Stop2 Mode, the same target microcontroller draws 1.23μA of current. Therefore, putting our microcontroller in the Standby Mode will significantly reduce current consumption.
When exiting Standby or Shutdown mode, all registers in the VCORE domain are set to their reset value. So it does lose context and waking up is similar to booting up after a sys reset.
STM32 Enter Standby Mode
By entering Standby Mode, the STM32 microcontroller loses context and all CPU registers’ content, so make sure you’ve handled all the logic operations needed before going into this mode.
#1
If you intend to wake the system up using a system wake-up (WKUP) pin, add the following line of code to clear the wake-up flag. Otherwise, standby mode will only be entered once.
1 | __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); |
Do the same in the case of wakeup using the RTC timer.
1 | __HAL_RTC_WAKEUPTIMER_CLEAR_FLAG(&hrtc, RTC_FLAG_WUTF); |
#2
Make sure you’ve enabled the system wakeup pin (WKUP1, or 2, etc..). In case of using RTC wakeup, make sure it’s also enabled as shown below.
1 2 3 4 5 6 | HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1); // Enable WKUP1 Pin // OR // Wakeup Time = WKUP_Counter * (RTCCLK_Div / 32kHz) HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 2000, RTC_WAKEUPCLOCK_RTCCLK_DIV16); // 1 sec = WKUP_Counter * (16 / 32kHz) => WKUP_Counter = 2000 |
#3
The last step is to enter the Standby Mode by calling the function below.
1 | HAL_PWR_EnterSTANDBYMode(); |
STM32 Wakeup (Exit) Standby Mode
When the STM32 microcontroller wakes up from Standby Mode, it’s like booting up after a complete system reset. The firmware execution starts from the very beginning, all previous context is lost and the system starts fresh. The only difference to tell whether it’s a clean boot up from a reset or a wakeup from standby is the SBF status flag in the PWR power control/status register (PWR_CSR).
The STM32 microcontroller can wakeup from standby mode by a WKUP pin rising edge, RTC alarm (Alarm A and Alarm B), RTC wakeup, tamper event, timestamp event, hardware reset on the NRST pin, or IWDG reset.
Auto Wakeup from Standby mode can be achieved using the internal RTC timer.
To learn more about Reset Reason Identification in STM32 microcontrollers, check out the linked tutorial.
STM32 Standby Mode Example Code Project
In this example project, we’ll configure our STM32L432KC microcontroller to run at full speed (80MHz) for 1 second. Then it’ll automatically switch to Standby Mode. The WKUP1 pin will be used to wake up the system.
Step #1
Open STM32CubeMX, create a new project and select the target microcontroller. For me, it’s (STM32L432KC)
Step #2
Enable the system wake-up pin (WKUP1 pin).
Step #3
Go to the Clock configuration page and select the internal HSI+PLL as a clock source to give you the maximum SysClk of 80MHz (in my case). This is the base full-speed run mode.
You can however, select the internal MSI which can give you a low-frequency clock source (2MHz down to 100kHz), if needed.
Step #4
Name & Generate The Project Initialization Code For CubeIDE or The IDE You’re Using.
Step #5
While connecting the WKUP1 pin, make sure it’s Pulled-Down externally with a 10k ohm resistor. Hook up a push button to give it HIGH signal on each button click.
STM32 Standby Mode Example Code
Here is The Application Code For This LAB (main.c)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | /* * LAB Name: STM32 Standby Mode Test Project * Author: Khaled Magdy * For More Info Visit: www.DeepBlueMbedded.com */ #include "main.h" void SystemClock_Config(void); static void MX_GPIO_Init(void); int main(void) { HAL_Init(); SystemClock_Config(); MX_GPIO_Init(); HAL_Delay(1000); // 1) Clear The Wakeup Flag __HAL_PWR_CLEAR_FLAG(PWR_FLAG_WU); // 2) Enable The WKUP1 Pin HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1); // 3) Enter The Standby Mode HAL_PWR_EnterSTANDBYMode(); while (1) { } } |
Required Parts For STM32 Examples
All the example Code/LABs/Projects in this STM32 Series of Tutorials are done using the Dev boards & Electronic Parts Below:QTY. Component Name Amazon.com AliExpress eBay 1 STM32-F103 BluePill Board (ARM Cortex-M3 @ 72MHz) Amazon AliExpress eBay 1 Nucleo-L432KC (ARM Cortex-M4 @ 80MHz) Amazon AliExpress eBay 1 ST-Link V2 Debugger Amazon AliExpress eBay 2 BreadBoard Amazon AliExpress eBay 1 LEDs Kit Amazon & Amazon AliExpress eBay 1 Resistors Kit Amazon & Amazon AliExpress eBay 1 Capacitors Kit Amazon & Amazon AliExpress & AliExpress eBay & eBay 1 Jumper Wires Pack Amazon & Amazon AliExpress & AliExpress eBay & eBay 1 Push Buttons Amazon & Amazon AliExpress eBay 1 Potentiometers Amazon AliExpress eBay 1 Micro USB Cable Amazon AliExpress eBay
★ Check The Links Below For The Full Course Kit List & LAB Test Equipment Required For Debugging ★
Download Attachments
You can download all attachment files for this Article/Tutorial (project files, schematics, code, etc..) using the link below. Please consider supporting our work through the various support options listed in the link down below. Every small donation helps to keep this website up and running and ultimately supports the whole community.
Wrap Up
In conclusion, we’ve explored the STM32 Standby Mode, what standby mode does to reduce the current consumption, and what are the current consumption numbers expected from this mode using the (STM32L432KC) target microcontroller.
We’ve also explored how to enter and exit (wake-up) from standby mode in STM32 microcontrollers. You can build on top of the provided example code project and integrate it into your system. You can also check the rest of the tutorials in this series to learn more about other low-power modes in STM32 microcontrollers.