Page 1 of 1

STLink debugger doesn't come back from deepsleep

Posted: Thu Jun 18, 2020 7:49 am
by dolfandringa
Hi all,

I am using the LowPower and STM32RTC libraries for the Arduino Core, using platformio, to put my device into a 1 minute wake/sleep cycle. After 4 sleep cycles there is a problem which I want to debug using my STLink debugger (and gdb).
This is the code to put it to sleep

Code: Select all

    STM32RTC &rtc = STM32RTC::getInstance();
    LowPower.enableWakeupFrom(&rtc, wakeup, &data);
    uint32_t now = rtc.getEpoch();
    rtc.setAlarmEpoch(now + sleep_time);
    LowPower.deepSleep();
This works fine normally, but once I run the code in debug mode using the debugger, the device never comes out of deepSleep. If I abort the code, it seems to be stuck in

Code: Select all

/system/Drivers/STM32F1xx_HAL_Driver/Src/stm32f1xx_hal_pwr.c:120
120       __asm volatile( "nop" );
Is there any way to get the deepSleep to work with the stlink debugger so I can debug the actual problem that I am having?

Re: STLink debugger doesn't come back from deepsleep

Posted: Thu Jun 18, 2020 8:24 am
by fpiSTM
In debug mode some context are not the same.
This would require some extra configuration.

For example for he STM32F103:
http://www.st.com/st-web-ui/static/acti ... 171691.pdf
dbg_lp.png
dbg_lp.png (12.06 KiB) Viewed 3310 times

Re: STLink debugger doesn't come back from deepsleep

Posted: Fri Jun 19, 2020 1:29 am
by dolfandringa
Cool, thanks. That gave me a pointer to search in the source of the arduino core. There is a function HAL_DBGMCU_EnableDBGStopMode (the official name of the LowPower.deepSleep mode is actually STOP mode in STM32 lingo) that I can use to set that register. But that still doesn't solve the issue. Even if I call it before LowPower.deepSleep, the device still hangs at the same place.