stm32l412kb nucleo not waking up from sleep mode. · Issue #73 · stm32duino/STM32LowPower · GitHub
Skip to content

stm32l412kb nucleo not waking up from sleep mode. #73

Description

@yadunandan6176

I am using Nucleo stml412kb with the STM32LowPower library. I wanted to wake my MCU from sleep mode for every external interrupt. I used one of the examples that is provided by the library (ExternalWakeup). The code works fine for some time and then the MCU won't wake up from sleep mode for the external interrupt, later if the reset button is pressed then only the MCU wakes up from sleep mode.

I am, not able to understand what is the issue. I tried debugging by adding some flags in the ISR and serial print statements in the loop. But still, I could not debug the issue.

Here is the code I was using :

#include "STM32LowPower.h"

// Blink sequence number
// Declare it volatile since it's incremented inside an interrupt
volatile int repetitions = 1;

// Pin used to trigger a wakeup
#ifndef USER_BTN
#define USER_BTN SYS_WKUP1
#endif

const int pin = USER_BTN;

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  // Set pin as INPUT_PULLUP to avoid spurious wakeup
  pinMode(pin, INPUT_PULLUP);

  // Configure low power
  LowPower.begin();
  // Attach a wakeup interrupt on pin, calling repetitionsIncrease when the device is woken up
  // Last parameter (LowPowerMode) should match with the low power state used: in this example LowPower.sleep()
  LowPower.attachInterruptWakeup(pin, repetitionsIncrease, RISING, SLEEP_MODE);
}

void loop() {
  for (int i = 0; i < repetitions; i++) {
    digitalWrite(LED_BUILTIN, HIGH);
    delay(500);
    digitalWrite(LED_BUILTIN, LOW);
    delay(500);
  }
  // Triggers an infinite sleep (the device will be woken up only by the registered wakeup sources)
  // The power consumption of the chip will drop consistently
  LowPower.sleep();
}

void repetitionsIncrease() {
  // This function will be called once on device wakeup
  // You can do some little operations here (like changing variables which will be used in the loop)
  // Remember to avoid calling delay() and long running functions since this functions executes in interrupt context
  repetitions ++;
}

Any help would be grateful.

Metadata

Metadata

Assignees

Labels

bug 🐛Something isn't working

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions