In this tutorial, we’ll discuss The STM32 Shutdown Mode, how to enter shutdown mode in STM32 microcontrollers, and how to exit from shutdown 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 Shutdown Mode
- STM32 Enter Shutdown Mode
- STM32 Wakeup (Exit) Shutdown Mode
- STM32 Shutdown Mode Example Code Project
- Wrap Up
STM32 Shutdown Mode
The STM32 Shutdown mode allows us to achieve the lowest power consumption. The internal regulator is switched OFF so that the VCORE domain is powered off. The PLL, the HSI16, the MSI, the LSI, and the HSE oscillators are also switched OFF.
The system can be woken up from shutdown mode using a SYS_WKUP pin, an RTC event (alarm or timer), or an external reset in the NRST pin. After waking up from Shutdown mode, program execution restarts like after a Reset (boot pin sampling, option bytes loading, reset vector is fetched, etc.).
For the STM32L432KC target microcontroller, in Shutdown Mode, the current consumption is:
- Shutdown Mode at 25°C and VDD = 3V, the current consumption should be 44.3nA
This is the minimum power consumption we could ever achieve with this target microcontroller.
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. In Standby Mode, it gets down to 90nA, which is double the current consumption in the Shutdown Mode.
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 Shutdown Mode
By entering Shutdown 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
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 |
#2
The last step is to enter the Shutdown Mode by calling the function below.
1 | HAL_PWREx_EnterSHUTDOWNMode(); |
STM32 Wakeup (Exit) Shutdown Mode
When the STM32 microcontroller wakes up from Shutdown 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 STM32 microcontroller can wake up from shutdown 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 shutdown 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 Shutdown 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 Shutdown 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 Shutdown 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 | /* * LAB Name: STM32 Shutdown 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) Enable The WKUP1 Pin HAL_PWR_EnableWakeUpPin(PWR_WAKEUP_PIN1); // 2) Enter The Standby Mode HAL_PWREx_EnterSHUTDOWNMode(); 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 Shutdown Mode, what the shutdown 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 shutdown 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.