STM32 Shutdown Mode Example & Wakeup Pin, RTC

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

  1. STM32 Shutdown Mode
  2. STM32 Enter Shutdown Mode
  3. STM32 Wakeup (Exit) Shutdown Mode
  4. STM32 Shutdown Mode Example Code Project
  5. 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.).

STM32 Shutdown Mode

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.

❕ Note

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.

#2

The last step is to enter the Shutdown Mode by calling the function below.


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.

❕ Note

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).

STM32 Standby Mode Wakeup Pin WKUP1

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.

STM32 Low Power Run Mode Example Clock Configuration

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)


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 NameAmazon.comAliExpresseBay
1STM32-F103 BluePill Board (ARM Cortex-M3 @ 72MHz)AmazonAliExpresseBay
1Nucleo-L432KC (ARM Cortex-M4 @ 80MHz)AmazonAliExpresseBay
1ST-Link V2 DebuggerAmazonAliExpresseBay
2BreadBoardAmazonAliExpresseBay
1LEDs KitAmazonAmazonAliExpresseBay
1Resistors KitAmazonAmazonAliExpresseBay
1Capacitors KitAmazonAmazonAliExpress & AliExpresseBay & eBay
1Jumper Wires PackAmazonAmazonAliExpress & AliExpresseBay & eBay
1Push ButtonsAmazonAmazonAliExpresseBay
1PotentiometersAmazonAliExpresseBay
1Micro USB CableAmazonAliExpresseBay

★ 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.

This Tutorial is Part of The Following Multi-Part Tutorial Series:

Share This Page With Your Network!
Join Our +25,000 Newsletter Subscribers!

Stay Updated With All New Content Releases. You Also Get Occasional FREE Coupon Codes For Courses & Other Stuff!

Photo of author
Author
Khaled Magdy
Embedded systems engineer with several years of experience in embedded software and hardware design. I work as an embedded SW engineer in the Automotive & e-Mobility industry. However, I still do Hardware design and SW development for DSP, Control Systems, Robotics, AI/ML, and other fields I'm passionate about.
I love reading, writing, creating projects, and teaching. A reader by day and a writer by night, it's my lifestyle. I believe that the combination of brilliant minds, bold ideas, and a complete disregard for what is possible, can and will change the world! I will be there when it happens, will you?

Leave a Comment