Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ void Power::shutdown()
#if HAS_SCREEN
messageStore.saveToFlash();
#endif
#if defined(ARCH_NRF52) || defined(ARCH_ESP32) || defined(ARCH_RP2040)
#if defined(ARCH_NRF52) || defined(ARCH_ESP32) || defined(ARCH_RP2040) || defined(ARCH_STM32WL)
#ifdef PIN_LED1
ledOff(PIN_LED1);
#endif
Expand Down
31 changes: 30 additions & 1 deletion src/platform/stm32wl/main-stm32wl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <stm32wlxx_hal.h>

#if HAS_LSE
#include <STM32LowPower.h>
#include <STM32RTC.h>

// LSEDRV is a 2-bit RCC_BDCR field where every combination is a legal drive level, so this covers all 4 values.
Expand Down Expand Up @@ -120,6 +121,7 @@ void stm32wlSetup()
rtc.setClockSource(STM32RTC::LSE_CLOCK);
rtc.begin();
stm32wlRtcValid = true;
LowPower.begin();
LOG_INFO("STM32WL: LSE locked, hardware RTC available");
} else {
// Don't leave a failed oscillator burning current.
Expand All @@ -138,7 +140,34 @@ bool stm32wlRtcAvailable()
void stm32wlSetup() {}
#endif

void cpuDeepSleep(uint32_t msecToWake) {}
void cpuDeepSleep(uint32_t msecToWake)
{
#if HAS_LSE
if (!stm32wlRtcAvailable()) {
// Hardware can't shutdown, but firmware has already prepared itself for shutdown
// Do not leave the device unresponsive, reset instead
LOG_WARN("STM32WL: hardware RTC failed, cannot deep sleep/shutdown");
if (Serial) {
Serial.flush();
Serial.end();
}
HAL_NVIC_SystemReset();
}

if (Serial) {
Serial.flush();
Serial.end();
}

if (msecToWake != portMAX_DELAY) {
LowPower.shutdown(msecToWake);
} else {
LowPower.shutdown();
}
// RTC wakes from shutdown into MCU reset, so this code should never be reached
HAL_NVIC_SystemReset();
#endif
}

// Hacks to force more code and data out.

Expand Down
2 changes: 2 additions & 0 deletions variants/stm32/rak3172/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,7 @@ lib_deps =
${stm32_base.lib_deps}
# renovate: datasource=github-tags depName=STM32RTC packageName=stm32duino/STM32RTC
https://github.com/stm32duino/STM32RTC/archive/refs/tags/1.9.0.zip
# renovate: datasource=github-tags depName=STM32LowPower packageName=stm32duino/STM32LowPower
https://github.com/stm32duino/STM32LowPower/archive/refs/tags/1.5.0.zip

upload_port = stlink
Loading