STM32F103CB ‘Sleepy mode’ and ‘Wake up’ function

Post here first, or if you can't find a relevant section!
myksj1105
Posts: 86
Joined: Sun Jun 18, 2023 11:35 am
Answers: 2

STM32F103CB ‘Sleepy mode’ and ‘Wake up’ function

Post by myksj1105 »

STM32F103CB ‘Sleepy mode’ and ‘Wake up’ function

[Status]
1. MCU: STM32F103CB
2. CORE1: https://github.com/rogerclarkmelbourne/Arduino_STM32
3. CORE2: https://github.com/stm32duino/Arduino_Core_STM32


hello.

We want to configure it with low power.
1. Enter ‘Sleepy Mode’ through firmware.
2. In terms of hardware, the ‘3.3V’ or ‘GND’ signal enables the ‘Wake up’ function.
3. The firmware re-enters ‘Sleepy mode’ after a certain period of time.

Are there any examples or libraries? help me.
by ag123 » Tue May 14, 2024 6:12 am
library is here
https://github.com/stm32duino/STM32LowPower
you need to use stm core for that

low power is not for novices, to do low power, the simplest way is to consult the reference manual and figure out how to do that from there.
in some low power modes, you need to trigger a reset after wake up from low power.

the simplest way to reduce power is to use

Code: Select all

asm("wfi");
when your code is not doing anything. you can put that in loop(), and that is good as delay(1)

for a properly designed app, stm32 can run for days on reusable AA or Lipo batteries without special low power modes.
and you can re-charge and use again.
normally, things like your leds etc can take more power than a stm32
Go to full post
myksj1105
Posts: 86
Joined: Sun Jun 18, 2023 11:35 am
Answers: 2

Re: STM32F103CB ‘Sleepy mode’ and ‘Wake up’ function

Post by myksj1105 »

#include "STM32LowPower.h"

Can I use the above library? 'STM32LowPower' ?
ag123
Posts: 1709
Joined: Thu Dec 19, 2019 5:30 am
Answers: 27

Re: STM32F103CB ‘Sleepy mode’ and ‘Wake up’ function

Post by ag123 »

library is here
https://github.com/stm32duino/STM32LowPower
you need to use stm core for that

low power is not for novices, to do low power, the simplest way is to consult the reference manual and figure out how to do that from there.
in some low power modes, you need to trigger a reset after wake up from low power.

the simplest way to reduce power is to use

Code: Select all

asm("wfi");
when your code is not doing anything. you can put that in loop(), and that is good as delay(1)

for a properly designed app, stm32 can run for days on reusable AA or Lipo batteries without special low power modes.
and you can re-charge and use again.
normally, things like your leds etc can take more power than a stm32
myksj1105
Posts: 86
Joined: Sun Jun 18, 2023 11:35 am
Answers: 2

Re: STM32F103CB ‘Sleepy mode’ and ‘Wake up’ function

Post by myksj1105 »

@ag123


Thank you for answer.

How to use the 'STM32LowPower' library?
CORE2: https://github.com/stm32duino/Arduino_Core_STM32

Is it possible to implement it through ‘CORE’ above?
ag123
Posts: 1709
Joined: Thu Dec 19, 2019 5:30 am
Answers: 27

Re: STM32F103CB ‘Sleepy mode’ and ‘Wake up’ function

Post by ag123 »

that is designed for Arduino_Core_STM32
I've not used it prior, hence you would need to review the examples, codes yourself.

beyond the library, review the reference manual for your soc
https://www.st.com/resource/en/referenc ... ronics.pdf
STM32ardui
Posts: 45
Joined: Mon May 06, 2024 1:46 pm
Answers: 1
Location: Germany

Re: STM32F103CB ‘Sleepy mode’ and ‘Wake up’ function

Post by STM32ardui »

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! :lol:


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?
myksj1105 wrote: Wed May 15, 2024 5:36 am How to use the 'STM32LowPower' library?
CORE2: https://github.com/stm32duino/Arduino_Core_STM32

Is it possible to implement it through ‘CORE’ above?
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
myksj1105
Posts: 86
Joined: Sun Jun 18, 2023 11:35 am
Answers: 2

Re: STM32F103CB ‘Sleepy mode’ and ‘Wake up’ function

Post by myksj1105 »

@STM32ardui

Thank you for answer.
Currently, the plan is
1. Wake up via ‘external pin’,
2. After counting, we plan to save it to ‘EEPROM’.

if,
1. Is there any problem when saving to ‘EEPROM’ of ‘STM32F103CB’?
2. It counts momentarily and goes into 'deep sleep'. Is there a chance that an error may occur at this time?
STM32ardui
Posts: 45
Joined: Mon May 06, 2024 1:46 pm
Answers: 1
Location: Germany

Re: STM32F103CB ‘Sleepy mode’ and ‘Wake up’ function

Post by STM32ardui »

myksj1105 wrote: Fri May 17, 2024 12:27 am 1. Is there any problem when saving to ‘EEPROM’ of ‘STM32F103CB’?
2. It counts momentarily and goes into 'deep sleep'. Is there a chance that an error may occur at this time?
DON'T TALK, JUST TRY! :mrgreen:
Sorry but you are asking and asking and asking ...
Why don't you take your board and test everything?

1. I don't use "old BluePill boards" and I never used that EEPROM functionallity. So simple try out, if you will have problems.

Flash memory can be overwritten a lot of times. But some day will come it will not work anymore. You don't give any information how often your µC should sleep and wake up again and how many data you want to store in Flash/EEPROM, how many years it should work.

2. idle(), sleep() and deepSleep() are functions of STM32 Low Power library.
For all these modes they write: "Memories and voltage supplies are retained".
If this is correct: why do you want to store something like a counter?

But you should read datasheet and other documents of STM32F103xx!
I see in datasheet run, sleep, stop, standby - but no "deep sleep".

So you should find out, which effects library really have on your µC. And you should have equipment to measure currents from 1 µA up to 50 mA without changing range.

And you should think about your STM32F103xx, if it is the right µC. STMicroelectronics made several STM32Lxxx series, that should have lower power consumption. Also the new STM32Uxxx are advertised as low power ...
myksj1105
Posts: 86
Joined: Sun Jun 18, 2023 11:35 am
Answers: 2

Re: STM32F103CB ‘Sleepy mode’ and ‘Wake up’ function

Post by myksj1105 »

@STM32ardui

Thank you for answer.

Currently, it has been functionally implemented.
However, I looking for a ‘definite answer’.

1) Using internal 'EEPROM'
2) Use of external 'EEPROM'
3) SD card storage

After measuring something, you need to record it,
The question was about what type of low-power mode should be used to get closer to the correct answer.

And, thank you for hearing your considerations.
I will refer to the contents carefully.
STM32ardui
Posts: 45
Joined: Mon May 06, 2024 1:46 pm
Answers: 1
Location: Germany

Re: STM32F103CB ‘Sleepy mode’ and ‘Wake up’ function

Post by STM32ardui »

myksj1105 wrote: Fri May 17, 2024 6:31 am 1) Using internal 'EEPROM'
2) Use of external 'EEPROM'
3) SD card storage
4) Use of external FRAM.
Post Reply

Return to “General discussion”