I’m interested in using the STM32L452RE Nucleo board for a project. For the application that I had in mind I would need the MCU to go into sleep, and in some cases be woken by timer and in other cases by external pin interrupt. And then I’d like the RAM to be retained after wake-up.
However I don’t want the wakeup sources to be active at the same time. I.e. if the MCU goes into sleep and is woken by timer, I don’t want it to also be able to be woken up by pin change. For that to work it essentially means that it should be possible for the pin interrupt to be deactivated again…but I haven’t found any functions that are able to do that.
So my questions about that are:
0) Is this the right place to ask this question? I could also post it on the "issues" page of the github repo.
1) Is what I want possible at all, for any of the sleep states?
2) Is what I want possible for deepSleep specifically? That would have my preference.
See below an Arduino script that illustrates what I would want the LowPower library to be able to do. It does compile, but I am not able to test it because I haven’t bought the Nucleo boad yet.
N.b. I had a look at the source code for the deepSleep function
https://github.com/stm32duino/STM32LowP ... er.cpp#L99, and that seems to only allow the timer and the Serial as interrupt sources for deepSleep. So my third question is, 3) Is that correct?
Sample script:void STM32LowPower::shutdown(uint32_t ms)
{
if ((ms != 0) || _rtc_wakeup) {
programRtcWakeUp(ms, SHUTDOWN_MODE);
}
LowPower_shutdown();
}
Code: Select all
#include "STM32LowPower.h"
#ifndef USER_BTN
#define USER_BTN pinNametoDigitalPin(SYS_WKUP1)
#endif
const int pin = USER_BTN;
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
// Configure low power
LowPower.attachInterruptWakeup(pin, wake_up_ISR, RISING, DEEP_SLEEP_MODE);
LowPower.begin();
}
void loop() {
digitalWrite(LED_BUILTIN, HIGH);
delay(5*1000);
digitalWrite(LED_BUILTIN, LOW);
Serial.println("Going into timed sleep");
LowPower.deepSleep(10*1000);
Serial.println("Waking up from timed sleep");
digitalWrite(LED_BUILTIN, HIGH);
delay(5*1000);
digitalWrite(LED_BUILTIN, LOW);
Serial.println("Going into sleep - pin wakeup");
LowPower.deepSleep(); // <- wakeup source should only be pin change.
Serial.println("Waking up from sleep - pin wakeup");
}
void wake_up_ISR(){
// Disable the pin change interrupt here?
}
Many thanks!