Repeater, room server, sensor, companion: fix nRF52 sleep wake-up loop and keep DC/DC enabled after BLE init

This commit is contained in:
tth committed 2026-11-24 19:38:41 +01:00
1 parent be46cfa5fb
commit 86e2a16703
3 files changed
+40 -4

No files matched your search

+15
View File
@@ -218,6 +218,21 @@ then shows `RESETREAS=0x00020000`, bit 17, wake from LPCOMP); with a cutoff
set, lowering the supply below it must switch the node off within ~3 minutes
and `get pwr` after the wake must say `last off: Low Voltage`.
## nRF52 sleep & peripheral fixes (bench verification pending)
Audit of the nRF52840 firmware and Adafruit core identified several sources of
unnecessary idle draw that affect all nRF52 boards (not only SenseCAP Solar):
- **`CRYPTOCELL_IRQn` sleep insomnia**: `USE_CC310_HW_CRYPTO=1` runs CC310 in
polling mode with `CRYPTOCELL_IRQn` disabled in NVIC; completed operations
leave it pending and immediately wake `sd_app_evt_wait()`/`__WFE()`.
`NRF52Board::sleep()` now clears `CRYPTOCELL_IRQn` before sleeping, matching
Adafruit core's `wiring.c`.
- **DC/DC regulator after SoftDevice start**: `NRF52BoardDCDC::begin()` runs
before `Bluefruit.begin()`, which enables SoftDevice S140 (defaulting
`NRF_POWER` to LDO). `NRF52BoardDCDC::onBootComplete()` now re-enables DC/DC
via `sd_power_dcdc_mode_set(NRF_POWER_DCDC_ENABLE)` once SoftDevice is active.
## Measuring this yourself — two traps
1. **A solar node measured on its USB side measures the CHARGER.** With a
+24 -4
View File
@@ -288,10 +288,7 @@ void NRF52Board::pwrmgtWakeArmVbus() {
}
#endif
void NRF52BoardDCDC::begin() {
NRF52Board::begin();
// Enable DC/DC converter for improved power efficiency
static void enableNrf52Dcdc() {
uint8_t sd_enabled = 0;
sd_softdevice_is_enabled(&sd_enabled);
if (sd_enabled) {
@@ -301,6 +298,21 @@ void NRF52BoardDCDC::begin() {
}
}
void NRF52BoardDCDC::begin() {
NRF52Board::begin();
// Enable DC/DC converter for improved power efficiency
enableNrf52Dcdc();
}
void NRF52BoardDCDC::onBootComplete() {
NRF52Board::onBootComplete();
// SoftDevice (Bluefruit.begin()) starts after board.begin() and defaults
// NRF_POWER to LDO mode; re-enable DC/DC once SoftDevice owns NRF_POWER.
enableNrf52Dcdc();
}
bool NRF52Board::isExternalPowered() {
// Check if SoftDevice is enabled before using its API
uint8_t sd_enabled = 0;
@@ -324,6 +336,14 @@ void NRF52Board::sleep(uint32_t secs) {
NVIC_ClearPendingIRQ(FPU_IRQn);
#endif
// Clear pending CRYPTOCELL interrupt to avoid WFE/sd_app_evt_wait() insomnia.
// Adafruit_nRFCrypto polls CC310 with CRYPTOCELL_IRQn disabled in NVIC, so
// completed crypto/TRNG calls leave it pending (same workaround as Adafruit
// core wiring.c / port_cmsis_systick.c).
#ifdef NRF_CRYPTOCELL
NVIC_ClearPendingIRQ(CRYPTOCELL_IRQn);
#endif
// On nRF52, we use event-driven sleep instead of timed sleep
// The 'secs' parameter is ignored - we wake on any interrupt
uint8_t sd_enabled = 0;
+1
View File
@@ -93,5 +93,6 @@ class NRF52BoardDCDC : virtual public NRF52Board {
public:
NRF52BoardDCDC() {}
virtual void begin() override;
virtual void onBootComplete() override;
};
#endif