stm32duino / STM32LowPower

Arduino Low Power library for STM32
183 stars 52 forks source link

deepSleep takes effect after power down #89

Closed xvedra closed 1 year ago

xvedra commented 1 year ago

Hi, I am working with deepSleep in a BluePill and I have notice that it takes effect only after a power down. Procedure: 1) BluePill power on from St-Link. 2) Clear flash memory 3) Program deepSleep example and does not take effect. 4) Power down: Switch off and switch on St-link . After that it takes effect. Thank you

fpistm commented 1 year ago

Hi @xvedra How did you flash it?

Which Arduino IDE? 1.8.x or 2.0.x? Host OS? upload method? Selected target?

What happen if you manually reset it (not power down)?

xvedra commented 1 year ago

Hi @fpistm, IDE 1.8.19 Under Windows 10 pro upload method: SWD (ST-LINK) Target: BluePill F103C8 What happen if you manually reset it (not power down)? The same...

After read this: https://github.com/stm32duino/STM32LowPower/issues/36

Works fine adding HAL_SuspendTick(); before LowPower.deepSleep();

... HAL_SuspendTick(); //Without this the MCU wakes up immediately (My problem) LowPower.deepSleep(); HAL_ResumeTick(); // I don't know if it's necessary ...

Thank you!

fpistm commented 1 year ago

You used LSE?

xvedra commented 1 year ago

BluePill board has LSE but I have used the simplest example without LSE (supposedly...):

void setup() { pinMode(LED_BUILTIN, OUTPUT); LowPower.begin(); }

void loop() { digitalWrite(LED_BUILTIN, HIGH);

if(1)

HAL_SuspendTick(); //added LowPower.deepSleep(2000); HAL_ResumeTick(); //added

else

LowPower.sleep();

endif

digitalWrite(LED_BUILTIN, LOW);

if(1)

HAL_SuspendTick(); //added LowPower.deepSleep(2000); HAL_ResumeTick(); //added

else

LowPower.sleep();

endif

}

There was no problem using with LowPower.sleep()

xvedra commented 1 year ago

For the problem to occur, must delete the flash or previously use a firmware that does not use deepSleep. Once the power down is done it works. By adding HAL_SuspendTick() it is no longer necessary to power down. It also continues to work on subsequent updates unless deepSleep is not used.

fpistm commented 1 year ago

Is it a legacy chip? Not a clone?

fpistm commented 1 year ago

I've tested on my side and have no issue. Ensure to have latest library version, latest core version and latest STM32CubeProgrammer as you used SWD. I've tested with different setup, USB enabled or not,... all works. Moreover it seems strange using HAL_SuspendTick allows to work as the deepSleepdisable the irq before entering in low power.

xvedra commented 1 year ago

Is it a legacy chip? Not a clone? My BluePill is from Aliexpress. I don't know if it's a clone. I have a custom board with a legacy (I want to believe it) STM32F108CB with the same result. Ensure to have latest library version, latest core version and latest STM32CubeProgrammer as you used SWD.. Latest versions I've tested with different setup, USB enabled or not,... all works. My test: 1) Run an example with LowPower.sleep(). (it works) 2) Run an example with LowPower.deepSleep(). (Now, this not woks for me...) 3) Reset. (still not working for me) 4) Power down and power on. (Now, it works).

Moreover it seems strange using HAL_SuspendTick allows to work as the deepSleep disable the irq before entering in low power. It's strange, but thank you very much for your support.

fpistm commented 1 year ago

I've made the same test than you and it works. I've tested with several BluePill, MapleMini and STM32F103ZE and all works. So I have no more clue except if it is a clone and in that case could explain why it does not work. You could try to ask on the forum maybe someone already met this issue. I close it as it works.