Beken: zero PS_DEEP_CTRL_PARAM before entering deep sleep - #2200
Merged
openshwprojects merged 2 commits intoSep 2, 2026
Merged
Conversation
openshwprojects
approved these changes
Sep 2, 2026
|
🎉 This PR is included in version 1.18.306 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While getting deep sleep working on a BK7238 battery sensor, timed wakeups behaved randomly:
PinDeepSleep 20came back after ~7 s, andDeepSleep 5never came back at all - the device had to be power-cycled, and twice, because Beken deep sleep survives a short interruption.PS_DEEP_CTRL_PARAMhas nine fields:Both call sites declare it on the stack and fill only a few. Everything else is whatever happened to be on the stack - including:
lpo_32k_src, which selects the RTC clock source for the timed wakeup. A random value here is exactly why timed wakeups fired at arbitrary times.gpio_stay_lo_map/gpio_stay_hi_map, which pin GPIOs to a fixed level during sleep.gpio_last_index_map/gpio_last_edge_map, extra wake sources for GPIO32-39.CMD_DeepSleep()additionally leaves the GPIO maps garbage, andPINS_BeginDeepSleepWithPinWakeUp()leavessleep_timegarbage when called without a timer.Zeroing the struct fixes it, and the zero defaults happen to be the right ones: empty stay/last maps, and
lpo_32k_src = 0 = LPO_SELECT_ROSC, the internal oscillator, which is present on every board (a 32k crystal may not be fitted).Tested on BK7238 (T1-U-HL). Before:
PinDeepSleep 20woke after ~7 s. After: commanded 30 s, actually slept ~31 s. GPIO wakeup also became reliable, and both sources work together - with a 600 s timer armed, a knock on the accelerometer woke the device after 4 s.