diagnosing LowPower.deepSleep() behaviour

Post here first, or if you can't find a relevant section!
Post Reply
fro
Posts: 8
Joined: Tue Mar 23, 2021 8:26 am

diagnosing LowPower.deepSleep() behaviour

Post by fro »

I'm trying to diagnose a strange deepSleep() behaviour on a custom designed PCB with STM32L412KBT6 with LSE. After a power up, the MCU deepSleeps/wakes up normally for 2-3 minutes, but after 2-3 minutes, the wake up does not happen.

Test setup:
- A single led is connected through a current limiting resistor to PA10, not other peripherals are connected.
- The minimal reproducing code is below (effectively a Blink).
- 2-3 minutes after the power up, the led stops blinking.
- LowPower.sleep(2000) instead of LowPower.deepSleep(2000) works as expected.
- Configuration used for uploading code: Board: "Nucleo-32", Board part number: "Nucleo L412KB"
- To no surprise, trying to connect to the MCU through SWD with STM32CubeProgrammer (I have the SWO pin connected) naturally resets the MCU.

Ideas on how to diagnose this further are much appreciated.

Versions:
- STM32 Core 1.9.0 (did not try 2.0.0 yet)
- STM32duino_Low_Power 1.1.0
- STM32duino_RTC at 1.1.0
- Arduino IDE 1.8.13

Code: Select all

#include <STM32LowPower.h>
void setup() {
  pinMode(PA10, OUTPUT);
  LowPower.begin();  
}

void loop() {
  digitalWrite(PA10, HIGH);
  LowPower.deepSleep(2000);

  digitalWrite(PA10, LOW);
  LowPower.deepSleep(2000);
}
mebab
Posts: 115
Joined: Mon Aug 24, 2020 12:42 pm
Answers: 4

Re: diagnosing LowPower.deepSleep() behaviour

Post by mebab »

Maybe the reason is that your system is always in deep sleep mode. There is not enough time for the processor to wake up and process the clocks, timers, etc between two deep sleep operations.
try to add a short sleep mode between two deep sleep modes. Something like:

Code: Select all

LowPower.sleep(100); 
.
fro
Posts: 8
Joined: Tue Mar 23, 2021 8:26 am

Re: diagnosing LowPower.deepSleep() behaviour

Post by fro »

Thanks for you suggestion @mebab. There is a small delay already provisioned for in LowPower_stop() (called from LowPower.deepSleep()) - https://github.com/stm32duino/Arduino_C ... wer.c#L246
fro
Posts: 8
Joined: Tue Mar 23, 2021 8:26 am

Re: diagnosing LowPower.deepSleep() behaviour

Post by fro »

The workaround seems to be using LSE as a clock source for the RTC:

Code: Select all

#include <STM32LowPower.h>

STM32RTC& rtc = STM32RTC::getInstance();

void setup() {
  pinMode(PA10, OUTPUT);
  
  // with LSE as a clock source, the MCU wakes up from deepSleep() as expected
  rtc.setClockSource(STM32RTC::LSE_CLOCK);
  rtc.begin();
    
  LowPower.begin();  
}

void loop() {
  digitalWrite(PA10, HIGH);
  LowPower.deepSleep(2000);

  digitalWrite(PA10, LOW);
  LowPower.deepSleep(2000);
}
I have performed a series of tests with LSE_CLOCK vs LSI_CLOCK. With the LSI_CLOCK the code is identical to the original post (no wake up after 2-3 mins), while with the LSE_CLOCK everything works as expected.

This is still puzzling as per "UM1884 Description of STM32L4/L4+ HAL and low-layer drivers" (https://www.st.com/resource/en/user_man ... ronics.pdf) the code eventually called from the library is effectively "Stop 1" low power mode, which in turn should be able to run with both LSI and LSE (as described by the STM32L412xx datasheet).

As using the LSE_CLOCK as a clock source totally satisfies my use case, I did not investigate further the issue with LSI. I've also noticed quite a few changes in the STM32 Core 2.0.0 for this area, so I might give it a another try with 2.0.0.
Post Reply

Return to “General discussion”