feat/sleep stm working#17
Conversation
…g sleep manager code
…ication and LoRaWANHandler
…lication cycle reporting
There was a problem hiding this comment.
Pull request overview
This PR introduces a new platform-specific sleep management implementation (STM32 + ESP32) with RTC/pin wake support, and updates power management usage across the app.
Changes:
- Migrates from a single
utils/sleep-managerimplementation to aSleepManagerBase+ per-SoC sleep manager (STM/ESP) with a thinSleepManagerwrapper. - Adds STM32WL55 RTC peripheral + wakeup pin handling and wires wakeup event reporting into the application cycle.
- Updates BME280 reads to use Zephyr runtime PM and adjusts Zephyr/West configuration to support the new power/RTC features.
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
west.yml |
Pins Zephyr revision and updates imported modules list for the new baseline. |
app/src/utils/sleep-manager.hpp |
Removes legacy generic SleepManager header (migrated to new structure). |
app/src/utils/sleep-manager.cpp |
Removes legacy generic SleepManager implementation (migrated to new structure). |
app/src/sensors/bme280/bme280.cpp |
Adds runtime PM get/put around sensor reads and formatting cleanup. |
app/src/peripherals/sleep/sleep_manager_stm.hpp |
Introduces STM32 sleep manager interface and RTC/wakeup pin members. |
app/src/peripherals/sleep/sleep_manager_stm.cpp |
Implements STM32 sleep behavior using RTC alarm + wakeup GPIO callbacks. |
app/src/peripherals/sleep/sleep_manager_esp.hpp |
Introduces ESP32 sleep manager interface. |
app/src/peripherals/sleep/sleep_manager_esp.cpp |
Implements ESP32 timed/light/deep sleep + wake cause mapping. |
app/src/peripherals/sleep/sleep_manager_base.hpp |
Adds common cross-platform sleep manager base API. |
app/src/peripherals/sleep/sleep_manager.hpp |
Adds SoC-selected SleepManager wrapper and dummy fallback implementation. |
app/src/peripherals/rtc/rtc_peripheral.hpp |
Introduces RTC peripheral wrapper API. |
app/src/peripherals/rtc/rtc_peripheral.cpp |
Implements RTC init/time/alarm helpers and alarm callback signaling. |
app/src/peripherals/peripheral.hpp |
Adds ERROR_ALREADY_INITIALIZED status for init idempotency. |
app/src/peripherals/lorawan_handler/lorawan_handler.hpp |
Removes an include as part of header cleanup. |
app/src/main.cpp |
Wires new sleep manager + semaphore, and adjusts app loop for sleep vs polling. |
app/src/Application.hpp |
Switches sleep manager ownership to a raw pointer (caller-owned). |
app/src/Application.cpp |
Updates sleep manager usage, adds wakeup-count reporting, and adjusts sleep fallback behavior. |
app/protobufs |
Updates protobuf submodule revision. |
app/prj.conf |
Enables PM/RTC/reset and STM32 wakeup/power features needed by new sleep flow. |
app/boards/nucleo_wl55jc.overlay |
Adds wakeup pin aliases/keys and enables &pwr for STM32WL55. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| pm_device_runtime_get(bme280_dev); | ||
|
|
||
| if (sensor_sample_fetch(bme280_dev) != 0) { | ||
| LOG_ERR("Failed to fetch BME280 data"); | ||
| pm_device_runtime_put(bme280_dev); | ||
| return Status::READ_ERR; | ||
| } |
There was a problem hiding this comment.
pm_device_runtime_get() returns a status code (and can fail). Currently the return value is ignored, which can hide runtime-PM failures and make subsequent sensor operations behave unpredictably. Consider checking the return code, logging on failure, and skipping the fetch if the device couldn't be resumed.
| uint32_t SleepManagerStm::get_and_clear_wakeup_count() { | ||
| uint32_t current_count = wkup_count; | ||
| wkup_count = 0; | ||
| return current_count; | ||
| } |
There was a problem hiding this comment.
wkup_count is modified in an ISR and read/reset in thread context without atomic protection. The read+clear sequence can race with an interrupt increment and lose counts. Use an atomic type/operation (e.g., atomic_t + atomic_set/atomic_get or atomic_cas patterns), or briefly lock/disable interrupts around the read/reset to make this operation race-free.
…nhance GPIO handling
…pheral initialization
No description provided.