From a751b4c37784a8816fc04e35cd28d57c10df446c Mon Sep 17 00:00:00 2001 From: Olivier Booklage Date: Mon, 23 Nov 2026 21:20:43 +0100 Subject: [PATCH 1/2] fix(thinknode_m6): Free the I2C bus before probing the RTC A reset during an RTC read left SDA held low, and the RTC probe then hung every boot. Up to nine clock pulses release the bus. --- variants/thinknode_m6/ThinkNodeM6Board.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/variants/thinknode_m6/ThinkNodeM6Board.cpp b/variants/thinknode_m6/ThinkNodeM6Board.cpp index f83f274f96b..cde7e70d628 100644 --- a/variants/thinknode_m6/ThinkNodeM6Board.cpp +++ b/variants/thinknode_m6/ThinkNodeM6Board.cpp @@ -5,9 +5,28 @@ #include +// A reset in the middle of an RTC read can leave the RTC holding SDA low, +// and the RTC probe at boot then hangs forever. Up to nine clock pulses let +// it finish its byte and release the bus. +static void recoverI2cBus() { + pinMode(PIN_WIRE_SDA, INPUT_PULLUP); + pinMode(PIN_WIRE_SCL, INPUT_PULLUP); + MESH_DEBUG_PRINTLN("I2C at boot: SDA=%d SCL=%d", digitalRead(PIN_WIRE_SDA), digitalRead(PIN_WIRE_SCL)); + pinMode(PIN_WIRE_SCL, OUTPUT); + digitalWrite(PIN_WIRE_SCL, HIGH); + for (int i = 0; i < 9 && digitalRead(PIN_WIRE_SDA) == LOW; i++) { + digitalWrite(PIN_WIRE_SCL, LOW); + delayMicroseconds(5); + digitalWrite(PIN_WIRE_SCL, HIGH); + delayMicroseconds(5); + } + pinMode(PIN_WIRE_SCL, INPUT_PULLUP); +} + void ThinkNodeM6Board::begin() { NRF52Board::begin(); + recoverI2cBus(); Wire.begin(); #ifdef P_LORA_TX_LED From b4dd93dfe1737e1e36a55e2233ca6f898da1d7a3 Mon Sep 17 00:00:00 2001 From: Olivier Booklage Date: Mon, 23 Nov 2026 21:20:55 +0100 Subject: [PATCH 2/2] feat(thinknode_m6): Add a 90 s watchdog It resets the board when the main loop stops, as Meshtastic does on the M6. It pauses while the CPU sleeps. --- variants/thinknode_m6/ThinkNodeM6Board.cpp | 19 +++++++++++++++++++ variants/thinknode_m6/ThinkNodeM6Board.h | 3 +++ 2 files changed, 22 insertions(+) diff --git a/variants/thinknode_m6/ThinkNodeM6Board.cpp b/variants/thinknode_m6/ThinkNodeM6Board.cpp index cde7e70d628..f7e994b9353 100644 --- a/variants/thinknode_m6/ThinkNodeM6Board.cpp +++ b/variants/thinknode_m6/ThinkNodeM6Board.cpp @@ -23,9 +23,24 @@ static void recoverI2cBus() { pinMode(PIN_WIRE_SCL, INPUT_PULLUP); } +// Resets the board when loop() stops feeding it, for example on an I2C read +// that never ends. Like Meshtastic: 90 s, paused while the CPU sleeps or a +// debugger halts it. A pin reset stops it, a soft reset does not. +static void startWatchdog() { + if (NRF_WDT->RUNSTATUS) { + return; // still running after a soft reset, and locked until the next one + } + NRF_WDT->CONFIG = (WDT_CONFIG_SLEEP_Pause << WDT_CONFIG_SLEEP_Pos) + | (WDT_CONFIG_HALT_Pause << WDT_CONFIG_HALT_Pos); + NRF_WDT->CRV = M6_WATCHDOG_SECS * 32768; // counts the 32.768 kHz clock + NRF_WDT->RREN = WDT_RREN_RR0_Msk; + NRF_WDT->TASKS_START = 1; +} + void ThinkNodeM6Board::begin() { NRF52Board::begin(); + startWatchdog(); // first, so that a hang later in the boot is caught too recoverI2cBus(); Wire.begin(); @@ -40,6 +55,10 @@ void ThinkNodeM6Board::begin() { delay(10); // give sx1262 some time to power up } +void ThinkNodeM6Board::loop() { + NRF_WDT->RR[0] = WDT_RR_RR_Reload; // feed the watchdog +} + uint16_t ThinkNodeM6Board::getBattMilliVolts() { int adcvalue = 0; diff --git a/variants/thinknode_m6/ThinkNodeM6Board.h b/variants/thinknode_m6/ThinkNodeM6Board.h index 934794c9af4..1f273a74f17 100644 --- a/variants/thinknode_m6/ThinkNodeM6Board.h +++ b/variants/thinknode_m6/ThinkNodeM6Board.h @@ -12,6 +12,8 @@ #define PIN_VBAT_READ BATTERY_PIN #define REAL_VBAT_MV_PER_LSB (VBAT_DIVIDER_COMP * VBAT_MV_PER_LSB) +#define M6_WATCHDOG_SECS 90 + class ThinkNodeM6Board : public NRF52BoardDCDC { protected: #if NRF52_POWER_MANAGEMENT @@ -21,6 +23,7 @@ class ThinkNodeM6Board : public NRF52BoardDCDC { public: ThinkNodeM6Board() : NRF52Board("THINKNODE_M6_OTA") {} void begin(); + void loop() override; uint16_t getBattMilliVolts() override; #if defined(P_LORA_TX_LED)