feat(rak3401): cold-sleep RAK4631 onboard SX1262 on RAK13302 builds

A RAK4631 core paired with a RAK13302 leaves the core's own SX1262
powered but never initialized, idling in STDBY_RC for the life of the
board. Firmware cannot cut its supply -- P1.05 is the RF switch rail,
not the radio's -- so bring it up on its own pins just long enough to
issue a cold sleep, before std_init() repins SPI onto the RAK13302.

Gated behind RAK4631_ONBOARD_SX1262_SLEEP and exposed through seven
RAK_4631_13302_* envs, so RAK_3401_* artifacts are unchanged.

The sleep is issued regardless of what begin() returns: Module::init()
runs first, so SPI stays usable even if TCXO calibration fails. NSS is
then held high, since the SX1262 wakes on an NSS falling edge.

Verified on RAK19007 + RAK4631 + RAK13302: begin=0 sleep=0, RAK13302
init clean (device_errors=0x0000), TX and RX both confirmed. The
current saving itself is derived from the datasheet (600 uA STDBY_RC
-> 160 nA cold sleep) and is not measured.
This commit is contained in:
agessaman committed 2026-08-17 21:04:06 -07:00
1 parent 22bc13804c
commit 974564b89c
3 files changed
+173

No files matched your search

+33
View File
@@ -32,8 +32,41 @@ AutoDiscoverRTCClock rtc_clock(fallback_clock);
EnvironmentSensorManager sensors;
#endif
#ifdef RAK4631_ONBOARD_SX1262_SLEEP
// With a RAK13302 fitted the RAK4631's own SX1262 never gets initialized, so it
// sits in STDBY_RC drawing standby current for the life of the board. Firmware
// cannot cut its supply -- P1.05 is the RF switch rail, not the radio's -- so
// bring it up on its own pins just long enough to put it into cold sleep.
static void sleep_onboard_radio() {
pinMode(ONBOARD_LORA_ANT_SW, OUTPUT);
digitalWrite(ONBOARD_LORA_ANT_SW, LOW); // nothing downstream needs the RF switch
SPI.setPins(ONBOARD_LORA_MISO, ONBOARD_LORA_SCLK, ONBOARD_LORA_MOSI);
SPI.begin();
Module mod(ONBOARD_LORA_NSS, ONBOARD_LORA_DIO_1, ONBOARD_LORA_RESET, ONBOARD_LORA_BUSY, SPI);
SX1262 onboard(&mod);
// begin() resets the chip and leaves it in standby. A TCXO calibration failure
// still leaves SPI usable, so issue the sleep regardless of what it returns.
int status = onboard.begin(434.0f, 125.0f, 9, 7, RADIOLIB_SX126X_SYNC_WORD_PRIVATE,
0, 8, ONBOARD_LORA_TCXO_VOLTAGE, false);
int slept = onboard.sleep(false); // cold sleep: config discarded, RTC off
MESH_DEBUG_PRINTLN("onboard SX1262: begin=%d sleep=%d", status, slept);
SPI.end(); // release SPIM3 so std_init() can repin it onto the RAK13302
// The SX1262 wakes on an NSS falling edge, so keep NSS driven high from here on.
digitalWrite(ONBOARD_LORA_NSS, HIGH);
pinMode(ONBOARD_LORA_NSS, OUTPUT);
}
#endif
bool radio_init() {
rtc_clock.begin(Wire);
#ifdef RAK4631_ONBOARD_SX1262_SLEEP
sleep_onboard_radio();
#endif
return radio.std_init(&SPI);
}