STM32 power saving: sleep, deep sleep, shutdown, and power consumption – 5
We have already described Idle mode and the relative power consumption, in this article we continue to measure power consumption of other sleep modes to have a brief comparison.
Wiring for our tests
We are going to use ST-Link to program and power the STM32, but we are going to put in the middle of the 3v3 pin of ST-Link V2 and 3.3v of the STM32 a multimeter to measure the amperage to analyze the power consumption.
Here the STM32 and ST-Link V2 used in this test STM32F103C8T6 STM32F401 STM32F411 ST-Link v2 ST-Link v2 official
Here the FTDI USB to TTL CH340G - USB to TTL FT232RL
Here my multimeter Aneng SZ18
To get the Serial output we use an external FTDI with only GND and Tx from STM32 to Rx of FTDI connected.
STM32F1 and Serial to debug
STM32F1 and Serial2 to debug
STM32F4 and Serial to debug
STM32F4 and Serial2 to debug
Wake up with internal interrupt managed by RTC
Sleep
The Sleep status is the Low-Power Sleep mode equivalent in the ST framework. Respect the previous example, and the regulator is placed into low power mode.
STM32F1
The first device we use is an STM
/**
* STM32 Low Power Sleep wake up test from RTC
*
* This sketch demonstrates the usage of Internal Interrupts to wakeup a chip
* in Sleep mode.
*
* In this sketch, the internal RTC will wake up the processor.
*
* Renzo Mischianti <www.mischianti.org>
* en: https://mischianti.org/category/tutorial/stm32-tutorial/
* it: https://mischianti.org/it/category/guide/guida-alla-linea-di-microcontrollori-stm32/
*/
#include "STM32LowPower.h"
// If you use generic STM32F103C8
// you don't need this explicit declaration
// This is needed by bluepill specified version
//HardwareSerial Serial(USART2); // PA3 (RX) PA2 (TX)
void setup() {
Serial.begin(115200);
while (!Serial){ delay(100); }
Serial.println("START!");
// Configure low power
LowPower.begin();
}
void loop() {
Serial.print("Entering sleep in ");
for (int i=5; i>0; i--) {Serial.print(i);Serial.print(" ");delay(500);}
Serial.println();
delay(100); // Needed to give the time to write on Serial
LowPower.sleep(5000); // Entering in sleep
delay(100); // Needed to restore the Serial
Serial.print("Wake for 10 seconds! ");
for (int i=10; i>0; i--) {Serial.print(i);Serial.print(" ");delay(1000);}
Serial.println();
}
The Serial output is:
START!
Entering sleep in 5 4 3 2 1
Wake for 10 seconds! 10 9 8 7 6 5 4 3 2 1
Entering sleep in 5 4 3 2 1
Wake for 10 seconds! 10 9 8 7 6 5 4 3 2 1
Entering sleep in 5 4 3 2 1
When entering Sleep, the power consumption from 17.50mAh goes down to 9.35mAh like the Sleep.
STM32F401
The same sketch in the STM32F401CC Black-Pill from 23.50mAh obtain the same result of Idle, 7.55mAh.
STM32F411
The same sketch in the STM32F411CE Black-Pill from 32.50mAh obtain the same result of Idle, 10.90mAh.
Deep Sleep
In DeepSleep (or Stop mode for ST Framework), some clocks are turned off, and only a minimal set of peripherals is in working mode.
STM32F1
Here is the code for my STM32F103C8 Blue pill
/**
* STM32 Low Power Deep Sleep wake up test from RTC
*
* This sketch demonstrates the usage of Internal Interrupts to wakeup a chip
* in DeepSleep mode.
*
* In this sketch, the internal RTC will wake up the processor.
*
* Renzo Mischianti <www.mischianti.org>
* en: https://mischianti.org/category/tutorial/stm32-tutorial/
* it: https://mischianti.org/it/category/guide/guida-alla-linea-di-microcontrollori-stm32/
*/
#include "STM32LowPower.h"
// If you use generic STM32F103C8
// you don't need this explicit declaration
// This is needed by bluepill specified version
//HardwareSerial Serial(USART2); // PA3 (RX) PA2 (TX)
void setup() {
Serial.begin(115200);
while (!Serial){ delay(100); }
Serial.println("START!");
// Configure low power
LowPower.begin();
}
void loop() {
Serial.print("Entering deep sleep in ");
for (int i=5; i>0; i--) {Serial.print(i);Serial.print(" ");delay(500);}
Serial.println();
delay(100); // Needed to give the time to write on Serial
LowPower.deepSleep(5000); // Entering in deep sleep
delay(100); // Needed to restore the Serial
Serial.print("Wake for 10 seconds! ");
for (int i=10; i>0; i--) {Serial.print(i);Serial.print(" ");delay(1000);}
Serial.println();
}
Here is the Serial output:
START!
Entering deep sleep in 5 4 3 2 1
Wake for 10 seconds! 10 9 8 7 6 5 4 3 2 1
Entering deep sleep in 5 4 3 2 1
Wake for 10 seconds! 10 9 8 7 6 5 4 3 2 1
Now the power consumption has a consistent change, and we get 1.914mAh.
STM32F401
The same sketch in the STM32F401CC Black-Pill from 24.48mAh obtain the result of 1.63mAh.
STM32F411
The same sketch in the STM32F401CC Black-Pill from 32.48mAh obtain the result of 6.56mAh.
Shutdown
As already described, shutdown (Standby) is simple to explain, the only oscillators available are the LSI and LSE, and the only peripherals that can function are the RTC and IWDG.
We do a minor change to the example sketch, and I put the wait before the shutdown because we must remember that when It wakes from this state, the device completely reboots and restart from the beginning (setup()
).
STM32F1
We are going to start with the Blue-Pill as usual.
/**
* STM32 Low Power shutdown wake up test from RTC
*
* This sketch demonstrates the usage of Internal Interrupts to wakeup a chip
* in shutdown mode.
*
* In this sketch, the internal RTC will wake up the processor.
*
* Renzo Mischianti <www.mischianti.org>
* en: https://mischianti.org/category/tutorial/stm32-tutorial/
* it: https://mischianti.org/it/category/guide/guida-alla-linea-di-microcontrollori-stm32/
*/
#include "STM32LowPower.h"
// If you use generic STM32F103C8
// you don't need this explicit declaration
// This is needed by bluepill specified version
//HardwareSerial Serial(USART2); // PA3 (RX) PA2 (TX)
void setup() {
Serial.begin(115200);
while (!Serial){ delay(100); }
Serial.println("START!");
// Configure low power
LowPower.begin();
}
void loop() {
delay(100); // Needed to restore the Serial
Serial.print("Wake for 10 seconds! ");
for (int i=10; i>0; i--) {Serial.print(i);Serial.print(" ");delay(1000);}
Serial.println();
Serial.print("Entering shutdown in ");
for (int i=5; i>0; i--) {Serial.print(i);Serial.print(" ");delay(500);}
Serial.println();
delay(100); // Needed to give the time to write on Serial
LowPower.shutdown(5000); // Entering in shutdown
}
Also, the serial output has a new structure.
START!
Wake for 10 seconds! 10 9 8 7 6 5 4 3 2 1
Entering shutdown in 5 4 3 2 1
START!
Wake for 10 seconds! 10 9 8 7 6 5 4 3 2 1
Entering shutdown in 5 4 3 2 1
As you can see, every wake the START!
string is written. And the power consumption goes down to 1.780mAh.
STM32F401
Also for this, every wake the START!
string is written. And the power consumption goes down to 0.31mAh.
STM32F411
Also for this, every wake the START!
string is written. And the power consumption goes down to 4.67mAh.
Comparison table
The results are as expected, now, we are going to resume in a table.
You must remember that we analyze the prototype board not only the chip STM32, so there is some additional power consumption like led and additional external clock.
Mode | STM32F1 | STM32F401 | STM32F411 |
---|---|---|---|
Idle | 9.37mAh | 7.55mAh | 11.05mAh |
Sleep | 9.35mAh | 7.55mAh | 10.90mAh |
Deep Sleep | 1.914mAh | 1.63mAh | 6.56mAh |
Shutdown | 1.780mAh | 0.31mAh | 4.67mAh |
The first thing you can understand is that in RTC wake the Low power voltage regulator does not offer a real advantage, but remember in Low power sleep you can disable selectively the peripheral, and, if you don’t need to gain other milliamperes, the DeepSleep is preferable to Shutdown so you don’t lose the memory data and the device is not restarted.
You can notice also that STM32F401 offers the best low-power performance, for the other device, you must work also over peripherals and frequencies.
Thanks
- STM32F1 Blue-Pill: pinout, specs, and Arduino IDE configuration (STM32duino and STMicroelectronics)
- STM32: program (STM32F1) via USB with STM32duino bootloader
- STM32: programming (STM32F1 STM32F4) via USB with HID boot-loader
- STM32F4 Black-Pill: pinout, specs, and Arduino IDE configuration
- STM32: ethernet w5500 with plain HTTP and SSL (HTTPS)
- STM32: ethernet enc28j60 with plain HTTP and SSL (HTTPS)
- STM32: WiFiNINA with ESP32 WiFi Co-Processor
- How to use SD card with stm32 and SdFat library
- \STM32: SPI flash memory FAT FS
- STM32: internal RTC, clock, and battery backup (VBAT)
- STM32 LoRa
- STM32 Power saving
- STM32F1 Blue-Pill clock and frequency management
- STM32F4 Black-Pill clock and frequency management
- Intro and Arduino vs STM framework
- Library LowPower, wiring, and Idle (STM Sleep) mode
- Sleep, deep sleep, shutdown, and power consumption
- Wake up from RTC alarm and Serial
- Wake up from the external source
- Backup domain intro and variable preservation across reset
- RTC backup register and SRAM preservation
- STM32 send emails with attachments and SSL (like Gmail): w5500, enc28j60, SD, and SPI Fash
- FTP server on STM32 with w5500, enc28j60, SD Card, and SPI Flash
- Connecting the EByte E70 to STM32 (black/blue pill) devices and a simple sketch example