Page 1 of 1

STM32LowPower - Serial keeps STM32L452RE awake (undesired)

Posted: Thu Aug 10, 2023 1:52 pm
by brixton
Hello all,

I got my hands on a STML452RE nucleo board. I managed to write and run a program that demonstrates using timed-based sleep and external-interrupt-based sleep in the same program. It works fine and I've very happy with that. See script below.

However, it only works if Serial/hardwareSerial is not used in the program. As soon as I introduce those into the code (i.e. by uncommenting the sections of code below), the external-interrupt-based sleep is skipped and the MCU proceeds straight to the next piece of code, which is the time-based sleep.

Does anyone know what could be causing the issue here?

Code: Select all

#include "STM32LowPower.h"

#ifndef USER_BTN
#define USER_BTN pinNametoDigitalPin(SYS_WKUP1)
#endif

const int pin = USER_BTN;

// HardwareSerial Serial1(PA10, PA9);

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  // Serial1.begin(115200); 

}

void loop() {
  // Serial1.println("A");
  LowPower.begin();
  digitalWrite(LED_BUILTIN, HIGH);
  LowPower.deepSleep(1000);
  // Serial1.println("B");
  digitalWrite(LED_BUILTIN, LOW);
  LowPower.deepSleep(5*1000);
  digitalWrite(LED_BUILTIN, HIGH);
  // Serial1.println("C");
  delay(1000); 
  // Serial1.println("D");
  digitalWrite(LED_BUILTIN, LOW);

  pinMode(pin, INPUT_PULLUP); 
  LowPower.begin();
  LowPower.attachInterruptWakeup(pin, emptyISR, RISING, SLEEP_MODE);
  LowPower.deepSleep();
  // Serial1.println("E");
}


void emptyISR() {
  // This function will be called once on device wakeup

}

Re: STM32LowPower - Serial keeps STM32L452RE awake (undesired)

Posted: Thu Aug 10, 2023 2:42 pm
by fpiSTM
Serial uses IT, try to add Serial1.flush(); before entering in LP.

Re: STM32LowPower - Serial keeps STM32L452RE awake (undesired)

Posted: Thu Aug 17, 2023 10:09 am
by brixton
Hi fpiSTM,

Thanks that resolved the issue!

Funnily enough, when I disable Serial1.flush() the problem does not seem to reappear. Strange..

Best,