Site icon Renzo Mischianti

STM32 power saving: library LowPower, wiring, and Idle mode – 4

Spread the love

STM32 power saving: library LowPower, wiring, and Idle mode

In a remote device, one important feature can be the power consumption, and like other devices, STM32 allows a set of Low Power states.

In this article, we look at the library to use and performance with our devices.

Here my selection of STM32 STM32F103C8T6 STM32F401 STM32F411 ST-Link v2 ST-Link v2 official

Library

In the Arduino framework, we are going to use the STM32LowPower library, so the process becomes effortless.

You can find that library on the Arduino library manager.

Arduino library manager: STM32 Low Power

This library has dependencies also, including a library that we used in the article “STM32: internal RTC, clock and battery backup (VBAT)“, which is used to interface the internal RTC clock.

As usual, you can find It in the library manager.

Arduino library manager: STM32 RTC

API

Note: With the STM32RTC version lower than 1.1.0, the minimum milliseconds is 1000 ms.

Begin() function must be called at least once before idle()sleep()deepSleep() or shutdown() functions.

attachInterruptWakeup() or enableWakeupFrom() functions should be called before idle()sleep()deepSleep() or shutdown() functions.

HardwareSerial used as a wake-up source will configure it to use the HSI clock source even if another peripheral clock is configured.

RTC used as a wake-up source will configure it to use the LSE clock source even if another RTC clock source is selected.

The board will restart when it exits the deepSleep or shutdown mode.

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 obtain the serial output, we use an external FTDI connected only to the GND and Tx pins of the STM32, which are then connected to the GND and Rx pins of the FTDI.

STM32F1 and Serial to debug

STM32: programming via ST-Link, Serial debug via FTDI, and Amperage check on breadboard

STM32F1 and Serial2 to debug

STM32: programming via ST-Link, Serial2 debug via FTDI, and Amperage check on breadboard

STM32F4 and Serial to debug

STM32F4 black pill and ST-Link: Serial debug via FTDI with Amperage check

STM32F4 and Serial2 to debug

STM32F4 black pill and ST-Link: Serial2 debug via FTDI with Amperage check

Wake up with internal interrupt managed by RTC

Now we are going to do some tests, first of all, we check the power consumption of all sleep statuses (idle, sleep, deepSleep, shutdown), and we use an internal interrupt managed by RTC to wake up the device.

In this article, we will only consider the “Idle” state, and in the upcoming articles, we will cover the remaining states.

Pinout STM32F103C6 low resolution

For this test, you need the STM32LowPower library and STM32RTC library.

Idle

As described, Idle status is the Sleep on the ST framework. This state has a speedy wake-up time and stops the CPU.

STM32F1

STM32F103C8 Blue-Pill: configuration for the low power test

The first device we use is an STM32F103C8 blue pill.

/**
 *	STM32 Low Power IDLE wake up test from RTC
 *
 * 	This sketch demonstrates the usage of Internal Interrupts to wakeup a chip
 *	in idle 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 idle in ");
	for (int i=5; i>0; i--) {Serial.print(i);Serial.print(" ");delay(500);}
	Serial.println();
	delay(100); // Needed to give time to write the Serial
	LowPower.idle(5000); // Entering in idle

	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 output in the Serial is

Entering idle in 5 4 3 2 1 
Wake for 10 seconds! 10 9 8 7 6 5 4 3 2 1 
Entering idle in 5 4 3 2 1 
Wake for 10 seconds! 10 9 8 7 6 5 4 3 2 1 
Entering idle in 5 4 3 2 1 
Wake for 10 seconds! 10 9 8 7 6 5 4 3 2 1 
Entering idle in 5 4 3 2 1 
Wake for 10 seconds! 10 9 8 7 6 5 4 

When entering Idle, the power consumption from 17.50mAh goes down to 9.37mAh.

STM32F401

STM32 STM32F401 STM32F401CCU6 pinout low resolution

The same sketch in the STM32F401CC Black-Pill from 23.50mAh obtain a lower result for STM32F103, 7.55mAh.

STM32F411

STM32 STM32F411 STM32F411CEU6 pinout low resolution

The same sketch in the STM32F411CE Black-Pill from 32.50mAh obtain a similar result for STM32F103, 11.05mAh.

Thanks

  1. STM32F1 Blue-Pill: pinout, specs, and Arduino IDE configuration (STM32duino and STMicroelectronics)
  2. STM32: program (STM32F1) via USB with STM32duino bootloader
  3. STM32: programming (STM32F1 STM32F4) via USB with HID boot-loader
  4. STM32F4 Black-Pill: pinout, specs, and Arduino IDE configuration
  5. STM32: ethernet w5500 with plain HTTP and SSL (HTTPS)
  6. STM32: ethernet enc28j60 with plain HTTP and SSL (HTTPS)
  7. STM32: WiFiNINA with ESP32 WiFi Co-Processor
    1. STM32F1 Blue-pill: WiFi shield (WiFiNINA)
    2. STM32F4 Black-pill: WiFi shield (WiFiNINA)
  8. How to use SD card with stm32 and SdFat library
  9. \STM32: SPI flash memory FAT FS
  10. STM32: internal RTC, clock, and battery backup (VBAT)
  11. STM32 LoRa
    1. Unleashing IoT Potential: Integrating STM32F1 Blue-Pill with EByte LoRa E32, E22, and E220 Shields
    2. Unleashing IoT Potential: Integrating STM32F4 Black-Pill with EByte LoRa E32, E22, and E220 Shields
  1. STM32 Power saving
    1. STM32F1 Blue-Pill clock and frequency management
    2. STM32F4 Black-Pill clock and frequency management
    3. Intro and Arduino vs STM framework
    4. Library LowPower, wiring, and Idle (STM Sleep) mode
    5. Sleep, deep sleep, shutdown, and power consumption
    6. Wake up from RTC alarm and Serial
    7. Wake up from the external source
    8. Backup domain intro and variable preservation across reset
    9. RTC backup register and SRAM preservation
  1. STM32 send emails with attachments and SSL (like Gmail): w5500, enc28j60, SD, and SPI Fash
  2. FTP server on STM32 with w5500, enc28j60, SD Card, and SPI Flash
  3. Connecting the EByte E70 to STM32 (black/blue pill) devices and a simple sketch example

Spread the love
Exit mobile version