Page 1 of 1

[SOLVED] Unwanted wakeup from sleep via serial

Posted: Thu May 14, 2020 6:16 am
by jgromes
Hi,

I'm using Nucleo L452RE-P, and I'm having some issues with sleep mode. I have external device (GPS receiver) connected to UART4 on pins PA0 and PA1. For some reason, when going to sleep mode using the STM32LowPower library, the STM32 will wake up whenever there's some data on the USART port. See the slightly modified TimedWakeup example below:

Code: Select all

#define GPS_TX    PA0
#define GPS_RX    PA1

#include "STM32LowPower.h"

HardwareSerial GpsSerial(GPS_RX, GPS_TX);

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  GpsSerial.begin(9600);
  
  // Configure low power
  LowPower.begin();
}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);
  LowPower.sleep(1000);
  digitalWrite(LED_BUILTIN, LOW);
  LowPower.sleep(1000);
}
Connecting an oscilloscope to the builtin LED pin, I can see it switching on and off rapidly when there's activity on the USART interface. This only seems to happen when using LowPower.sleep() and only after the USART interface is initialized via GpsSerial.begin(9600)

Is there something I missed in the configuration? Does the serial wakeup need to be explicitly disabled?

Thanks!

Re: Unwanted wakeup from sleep via serial

Posted: Thu May 14, 2020 8:07 am
by fpiSTM
When you use the sleep() then in enter in SLEEP mode with WFI instruction then I guess the Serial IT wake up the device.
you should disable Serial interrupt or close it.

Code: Select all

GpsSerial.end();

Re: Unwanted wakeup from sleep via serial

Posted: Thu May 14, 2020 8:16 am
by jgromes
Ah, that makes sense - then I guess there's no way to "disable" it since it's UART that causes the interrupt and WFI doesn't distinguish between that and RTC interrupt.

I'll amend my application to stop all UART interfaces prior to using sleep() and restart them afterwards. Thank you for the assistance!

Re: [SOLVED] Unwanted wakeup from sleep via serial

Posted: Thu May 14, 2020 8:36 am
by fpiSTM
Maybe you could try using:

Code: Select all

void HAL_NVIC_DisableIRQ(IRQn_Type IRQn)

void HAL_NVIC_EnableIRQ(IRQn_Type IRQn)
with UART4_IRQn if I'm not wrong.

So:

Code: Select all

HAL_NVIC_DisableIRQ(UART4_IRQn);
LowPower.sleep(1000);
HAL_NVIC_EnableIRQ(UART4_IRQn);

Re: [SOLVED] Unwanted wakeup from sleep via serial

Posted: Thu May 14, 2020 10:00 am
by jgromes
That could be an alternative, though it doesn't really matter in my use case - I don't really care if the UART interface is stopped, or if it's just the IRQ that's disabled. Thanks for the extra info though :)