[SOLVED] Unwanted wakeup from sleep via serial

Working libraries, libraries being ported and related hardware
Post Reply
jgromes
Posts: 6
Joined: Sat Feb 15, 2020 10:43 am

[SOLVED] Unwanted wakeup from sleep via serial

Post 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!
Last edited by jgromes on Thu May 14, 2020 8:17 am, edited 1 time in total.
User avatar
fpiSTM
Posts: 1745
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Unwanted wakeup from sleep via serial

Post 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();
jgromes
Posts: 6
Joined: Sat Feb 15, 2020 10:43 am

Re: Unwanted wakeup from sleep via serial

Post 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!
User avatar
fpiSTM
Posts: 1745
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: [SOLVED] Unwanted wakeup from sleep via serial

Post 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);
jgromes
Posts: 6
Joined: Sat Feb 15, 2020 10:43 am

Re: [SOLVED] Unwanted wakeup from sleep via serial

Post 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 :)
Post Reply

Return to “Libraries & Hardware”