Skip to content

feat/sleep stm working#17

Open
jacek-kow wants to merge 20 commits into
mainfrom
feat/sleep-stm-working
Open

feat/sleep stm working#17
jacek-kow wants to merge 20 commits into
mainfrom
feat/sleep-stm-working

Conversation

@jacek-kow
Copy link
Copy Markdown
Contributor

No description provided.

@wybran wybran requested a review from Copilot March 21, 2026 17:40
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-manager implementation to a SleepManagerBase + per-SoC sleep manager (STM/ESP) with a thin SleepManager wrapper.
  • 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.

Comment thread west.yml
Comment thread app/src/sensors/bme280/bme280.cpp Outdated
Comment on lines 31 to 37
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;
}
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread app/src/main.cpp
Comment thread app/src/peripherals/sleep/sleep_manager_stm.cpp Outdated
Comment on lines +38 to +42
uint32_t SleepManagerStm::get_and_clear_wakeup_count() {
uint32_t current_count = wkup_count;
wkup_count = 0;
return current_count;
}
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread app/src/peripherals/rtc/rtc_peripheral.cpp
Comment thread app/src/peripherals/rtc/rtc_peripheral.cpp Outdated
Comment thread app/src/peripherals/sleep/sleep_manager.hpp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants