Enable RAK4631 Companion DC/DC in all transports

This commit is contained in:
mikecarper committed 2026-10-17 11:35:50 -07:00
1 parent 2fb4d2e793
commit 86984e8e22
5 files changed
+129 -20

No files matched your search

+1
View File
@@ -318,6 +318,7 @@ jobs:
python3 -B test/test_sensor_tracker_sleep.py -v
python3 -B test/test_power_saving_deadlines.py -v
python3 -B test/test_t096_regulator.py -v
python3 -B test/test_nrf52_board_regulators.py -v
python3 -B test/test_power_saving_diagnostics.py -v
python3 -B test/test_power_saving_role_diagnostics.py -v
python3 -B test/test_companion_power_diagnostics.py -v
+24
View File
@@ -96,3 +96,27 @@ for all page names and commands.
The [nRF52 idle-sleep investigation](nrf52_sleep_event_validation.md) describes
an eligible-but-not-sleeping regression, its fix, controlled hardware evidence
and the limits of CPU-state sampling without a current meter.
## Board regulator initialization
RAK4631 Companion uses the same nRF52840 REG1 DC/DC initialization as the other
RAK4631 roles. The former Companion-only force-LDO flag has been removed. This
does not change REG0, the SX1262 regulator, storage layout, or boot-voltage
protection. The shared initializer uses the SoftDevice API when BLE's stack is
already active and the hardware register otherwise; Companion starts the board
before it starts Bluetooth.
[RAK documents DC/DC support](https://docs.rakwireless.com/product-categories/wisduo/rak4630-module/quickstart/)
for the module. The related upstream [battery-startup report #1878](https://github.com/meshcore-dev/MeshCore/issues/1878)
concerned Repeater firmware, with BLE Companion reported working on an affected
board. It did not establish filesystem corruption or a Companion-specific
DC/DC failure. [PR #1914](https://github.com/meshcore-dev/MeshCore/pull/1914)
also changes boot-voltage/wakeup handling and is not proof that every failure
in that thread has the same cause.
Host startup tests cover both SoftDevice states and regulator selection before
the boot-voltage check. Firmware compilation is not hardware qualification:
compare battery-only cold starts, low-voltage recovery, BLE operation and
settings writes/reboots on the actual board/baseboard revisions before a fleet
rollout. USB power can mask the reported startup symptoms. A current meter is
still needed to quantify the power difference.
+101
View File
@@ -0,0 +1,101 @@
#!/usr/bin/env python3
"""Run real board startup methods against counted nRF52 regulator SDK calls."""
import configparser
import os
from pathlib import Path
import subprocess
import tempfile
import unittest
from cpp_source import body
ROOT = Path(__file__).resolve().parents[1]
HARNESS = r'''
#include <cassert>
#include <cstdint>
#define NRF52_POWER_MANAGEMENT 1
#define PIN_BOARD_SDA 1
#define PIN_BOARD_SCL 2
#define PIN_USER_BTN 9
#define PIN_USER_BTN_ANA 31
constexpr int INPUT = 0, OUTPUT = 1, INPUT_PULLUP = 2, LOW = 0, HIGH = 1;
constexpr int PIN_VBAT_READ = 5, WB_IO2 = 34, SX126X_POWER_EN = 37;
constexpr int NRF_POWER_DCDC_ENABLE = 1, NRF_POWER_DCDC_DISABLE = 0;
static unsigned base_calls, sdk_calls, voltage_checks;
static uint8_t softdevice;
struct Power { unsigned DCDCEN; } power;
#define NRF_POWER (&power)
namespace mesh_nrf52 {
void softdeviceIsEnabled(uint8_t& enabled) { enabled = softdevice; }
}
void sd_power_dcdc_mode_set(int mode) {
assert(base_calls == 1 && softdevice && mode == NRF_POWER_DCDC_ENABLE);
++sdk_calls;
}
void pinMode(int, int) {}
void digitalWrite(int, int) {}
void delay(unsigned) {}
struct Bus { void setPins(int, int) {} void begin() {} } Wire;
struct Config {} power_config;
struct NRF52Board { void begin() { ++base_calls; } };
struct NRF52BoardDCDC : NRF52Board { void begin(); };
struct @BOARD@ : NRF52BoardDCDC {
void begin();
void checkBootVoltage(const Config*) {
++voltage_checks;
assert(base_calls == 1);
assert(softdevice ? sdk_calls == 1 : power.DCDCEN == 1);
}
};
@METHODS@
int main() {
for (softdevice = 0; softdevice < 2; ++softdevice) {
power.DCDCEN = base_calls = sdk_calls = voltage_checks = 0;
@BOARD@ board;
board.begin();
assert(base_calls == 1 && voltage_checks == 1);
assert(sdk_calls == softdevice);
assert(power.DCDCEN == (softdevice ? 0U : 1U));
}
}
'''
class Nrf52BoardRegulatorTests(unittest.TestCase):
def run_startup(self, filename, board, flags=()):
methods = body((ROOT / 'src/helpers/NRF52Board.cpp').read_text(),
'void NRF52BoardDCDC::begin()')
methods += body((ROOT / filename).read_text(), f'void {board}::begin()')
source = HARNESS.replace('@BOARD@', board).replace('@METHODS@', methods)
with tempfile.TemporaryDirectory(prefix='meshcore-board-regulator-') as tmp:
cpp, binary = Path(tmp) / 'test.cpp', Path(tmp) / 'test'
cpp.write_text(source, encoding='ascii')
built = subprocess.run([
os.environ.get('CXX', 'c++'), '-std=c++17', '-Wall', '-Wextra',
'-Werror', *flags, str(cpp), '-o', str(binary)],
capture_output=True, text=True, timeout=60)
self.assertEqual(built.returncode, 0, built.stdout + built.stderr)
result = subprocess.run([str(binary)], capture_output=True, text=True, timeout=10)
self.assertEqual(result.returncode, 0, result.stdout + result.stderr)
def test_rak4631_startup_uses_dcdc_before_voltage_check(self):
# Cover boot before BLE starts and an already-active SoftDevice. Also
# prove an obsolete downstream flag cannot silently force LDO again.
for flags in ((), ('-DRAK4631_COMPANION_FORCE_LDO=1',)):
with self.subTest(flags=flags):
self.run_startup('variants/rak4631/RAK4631Board.cpp', 'RAK4631Board', flags)
def test_rak_companion_profiles_do_not_force_ldo(self):
config = configparser.ConfigParser(interpolation=None)
config.read(ROOT / 'variants/rak4631/platformio.ini')
for role in ('usb', 'ble', 'ethernet', 'full'):
with self.subTest(role=role):
section = config[f'env:RAK_4631_companion_radio_{role}']
self.assertNotIn('RAK4631_COMPANION_FORCE_LDO', section['build_flags'])
self.assertEqual(config['env:RAK_4631_companion_radio_full']['extends'],
'env:RAK_4631_companion_radio_usb')
if __name__ == '__main__':
unittest.main()
+3 -17
View File
@@ -1,12 +1,9 @@
#include <Arduino.h>
#include <Wire.h>
#include "nrf_gpio.h"
#include "nrf_sdm.h"
#include "nrf_soc.h"
#include "RAK4631Board.h"
#include "target.h"
#include "../../src/helpers/nrf52/SoftDeviceState.h"
#include "../../src/helpers/nrf52/TerminalPeripheralShutdown.h"
#ifdef ETHERNET_ENABLED
@@ -82,21 +79,10 @@ void RAK4631Board::shutdownPeripherals() {
}
void RAK4631Board::begin() {
#ifdef RAK4631_COMPANION_FORCE_LDO
// Some RAK4631 battery/board combinations have proved unstable with the
// nRF52 DC/DC enabled. Explicitly select the LDO for companion firmware;
// merely skipping NRF52BoardDCDC::begin() would inherit any prior state.
NRF52Board::begin();
uint8_t sd_enabled = 0;
mesh_nrf52::softdeviceIsEnabled(sd_enabled);
if (sd_enabled) {
sd_power_dcdc_mode_set(NRF_POWER_DCDC_DISABLE);
} else {
NRF_POWER->DCDCEN = 0;
}
#else
// The RAK4630 module supports REG1 DC/DC in every role. The shared
// initializer selects the SDK API if SoftDevice is already running and
// the register otherwise, including Companion's pre-Bluetooth startup.
NRF52BoardDCDC::begin();
#endif
pinMode(PIN_VBAT_READ, INPUT);
#ifdef PIN_USER_BTN
pinMode(PIN_USER_BTN, INPUT_PULLUP);
-3
View File
@@ -419,7 +419,6 @@ board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld
board_upload.maximum_size = 712704
build_flags =
${rak4631.build_flags}
-D RAK4631_COMPANION_FORCE_LDO=1
-I examples/companion_radio/ui-new
-D PIN_USER_BTN=9
-D PIN_USER_BTN_ANA=31
@@ -446,7 +445,6 @@ build_unflags =
-D EXTRAFS=1
build_flags =
${rak4631.build_flags}
-D RAK4631_COMPANION_FORCE_LDO=1
-I examples/companion_radio/ui-new
-D PIN_USER_BTN=9
-D PIN_USER_BTN_ANA=31
@@ -495,7 +493,6 @@ board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld
board_upload.maximum_size = 712704
build_flags =
${rak4631.build_flags}
-D RAK4631_COMPANION_FORCE_LDO=1
-I examples/companion_radio/ui-new
-D PIN_USER_BTN=9
-D PIN_USER_BTN_ANA=31