STM32LowPower - Serial keeps STM32L452RE awake (undesired)

What are you developing?
Post Reply
brixton
Posts: 24
Joined: Thu Mar 30, 2023 11:51 am
Answers: 1

STM32LowPower - Serial keeps STM32L452RE awake (undesired)

Post 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

}
User avatar
fpiSTM
Posts: 1758
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: STM32LowPower - Serial keeps STM32L452RE awake (undesired)

Post by fpiSTM »

Serial uses IT, try to add Serial1.flush(); before entering in LP.
brixton
Posts: 24
Joined: Thu Mar 30, 2023 11:51 am
Answers: 1

Re: STM32LowPower - Serial keeps STM32L452RE awake (undesired)

Post 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,
Post Reply

Return to “Projects”