Hi,
I take a look into example ExternalWakeup.ino and it looks familiar to me, because I done such things with a SAMD21. So my little experience is not about STM32, but may be usefull for you.
1. Wake up a processor from idle/sleep is made by an interrupt. So you have to write an interrupt service routine (ISR). The name of the function is a parameter in attachInterrupt().
2. ISR should be short. When program flow entering ISR, other interrupts are blocked, so you shouldn't spend much time inside ISR. I'm not sure about higher priority interrupts, if they can break your ISR ...
3. Variables you use inside ISR, should be defined as volatile.
4. delay() and millis() are not working inside ISR because they are using interrupts for counting. There is a hint on german Arduino reference, that micros() may work at beginning but after some milliseconds not more. delaymicroseconds() should work - I don't know, if this function is inside package of STM32adruino ...
5. You can't get values from a sensor inside ISR. Most sensors need some time after a request until registers are filled. Inside library you will find delay() for that and delay() is not working inside ISR. Easiest way is to set a flag inside ISR und do the rest inside loop().
6. One thing I don't understand in ExternalWakeup.ino is the line
Code: Select all
#define USER_BTN pinNametoDigitalPin(SYS_WKUP1)
Each processor in the Arduino world has different GPIOs, that can work for external interrupts. I don't know what is SYS_WKUP1 for a STM32 ...
And if you think, that is difficult, never use an ESP32 with interrupts!
As ag123 already pointed out, current consumption of the STM32 processor is only one part. A LDO with high quiescent current can ruin your calculation about current during sleep. Do you have external flash memory? Or a SD-card? What about current of sensors?
I don't understand your questions ...
Inside ArduinoIDE you have an icon looking like some books. It is the library manager. Open it and type in "low". You will see a list of libraries. Install the right one. May be you have to close IDE and start it again. ArduinoIDE 2.x sometimes don't recognize fresh installed libraries. Inside your code you will need an #include "STM32LowPower.h".
Bye, Jürgen