Fix constrained release target builds

This commit is contained in:
mikecarper committed 2026-07-21 08:58:32 -07:00
1 parent bda0722ad8
commit 6562d15a90
10 files changed
+155 -55

No files matched your search

+52 -20
View File
@@ -36,11 +36,14 @@ void Dispatcher::begin() {
_radio->begin();
prev_isrecv_mode = _radio->isInRecvMode();
last_radio_active_ms = _ms->getMillis();
last_watchdog_recovery = last_radio_active_ms;
const unsigned long now = _ms->getMillis();
last_observed_radio_irq = _radio->getLastRadioInterruptMillis();
radio_liveness.begin(last_radio_active_ms);
#ifdef RADIO_LIVENESS_SOFT_ONLY
last_radio_activity_ms = now;
#else
radio_liveness.begin(now);
nonrx_soft_recovery_attempted = false;
#endif
}
float Dispatcher::getAirtimeBudgetFactor() const {
@@ -140,8 +143,11 @@ void Dispatcher::loop() {
const unsigned long latest_irq = _radio->getLastRadioInterruptMillis();
if (latest_irq != 0 && latest_irq != last_observed_radio_irq) {
last_observed_radio_irq = latest_irq;
last_radio_active_ms = now;
#ifdef RADIO_LIVENESS_SOFT_ONLY
last_radio_activity_ms = now;
#else
radio_liveness.noteActivity(now);
#endif
}
// check for radio 'stuck' in mode other than Rx
@@ -150,21 +156,30 @@ void Dispatcher::loop() {
prev_isrecv_mode = is_recv;
if (!is_recv) {
radio_nonrx_start = now;
} else {
}
#ifndef RADIO_LIVENESS_SOFT_ONLY
else {
nonrx_soft_recovery_attempted = false;
}
#endif
}
bool recovered_this_loop = false;
if (!is_recv && outbound == NULL && now - radio_nonrx_start > 8000) {
_err_flags |= ERR_EVENT_STARTRX_TIMEOUT;
#ifdef RADIO_LIVENESS_SOFT_ONLY
MESH_DEBUG_PRINTLN("Radio watchdog: radio outside RX for %lu ms; soft recovery",
now - radio_nonrx_start);
if (_radio->recoverRadio(false)) {
last_radio_activity_ms = now;
recovered_this_loop = true;
}
#else
const bool hard = nonrx_soft_recovery_attempted;
MESH_DEBUG_PRINTLN("Radio watchdog: radio outside RX for %lu ms; %s recovery",
now - radio_nonrx_start, hard ? "hard" : "soft");
if (_radio->recoverRadio(hard)) {
last_watchdog_recovery = now;
recovered_this_loop = true;
}
if (_radio->recoverRadio(hard)) recovered_this_loop = true;
nonrx_soft_recovery_attempted = true;
#endif
radio_nonrx_start = now; // bounded retry cadence if recovery is unsupported
}
@@ -178,24 +193,35 @@ void Dispatcher::loop() {
const uint32_t configured_watchdog_ms = getRadioWatchdogMillis();
if (configured_watchdog_ms > 0) soft_liveness_ms = configured_watchdog_ms;
#endif
uint32_t hard_liveness_ms = RADIO_LIVENESS_HARD_MS;
if (soft_liveness_ms > hard_liveness_ms / 2) {
hard_liveness_ms = soft_liveness_ms <= 0x7FFFFFFFUL
? soft_liveness_ms * 2 : 0xFFFFFFFFUL;
}
if (is_recv && outbound == NULL && !recovered_this_loop) {
#ifdef RADIO_LIVENESS_SOFT_ONLY
if (soft_liveness_ms > 0 && now - last_radio_activity_ms >= soft_liveness_ms) {
_err_flags |= ERR_EVENT_RADIO_WATCHDOG;
MESH_DEBUG_PRINTLN("Radio watchdog: no hardware activity for %lu ms, state=%d, soft recovery",
now - last_radio_activity_ms, _radio->getRadioState());
_radio->recoverRadio(false);
// This radio has no independently resettable RF peripheral. Retry its
// only safe recovery at the soft interval until IRQ/TX/RX proves life.
last_radio_activity_ms = now;
}
#else
uint32_t hard_liveness_ms = RADIO_LIVENESS_HARD_MS;
if (soft_liveness_ms > hard_liveness_ms / 2) {
hard_liveness_ms = soft_liveness_ms <= 0x7FFFFFFFUL
? soft_liveness_ms * 2 : 0xFFFFFFFFUL;
}
const RadioRecoveryAction action = radio_liveness.poll(
now, soft_liveness_ms, hard_liveness_ms);
if (action != RadioRecoveryAction::NONE) {
const bool hard = action == RadioRecoveryAction::HARD;
_err_flags |= ERR_EVENT_RADIO_WATCHDOG;
MESH_DEBUG_PRINTLN("Radio watchdog: no hardware activity for %lu ms, state=%d, %s recovery",
now - last_radio_active_ms, _radio->getRadioState(),
now - radio_liveness.lastActivity(), _radio->getRadioState(),
hard ? "hard" : "soft");
const bool recovered = _radio->recoverRadio(hard);
if (recovered) last_watchdog_recovery = now;
if (hard) radio_liveness.noteHardRecoveryResult(now, recovered);
}
#endif
}
if (outbound) { // waiting for outbound send to be completed
@@ -221,8 +247,11 @@ void Dispatcher::loop() {
}
_radio->onSendFinished();
last_radio_active_ms = _ms->getMillis(); // TX success → radio is alive
radio_liveness.noteActivity(last_radio_active_ms);
#ifdef RADIO_LIVENESS_SOFT_ONLY
last_radio_activity_ms = _ms->getMillis(); // TX success -> radio is alive
#else
radio_liveness.noteActivity(_ms->getMillis()); // TX success -> radio is alive
#endif
restoreOutboundTxOverrides();
logTx(outbound, 2 + outbound->getPathByteLen() + outbound->payload_len);
onSendComplete(outbound);
@@ -348,8 +377,11 @@ void Dispatcher::checkRecv() {
uint8_t raw[MAX_TRANS_UNIT+1];
int len = _radio->recvRaw(raw, MAX_TRANS_UNIT);
if (len > 0) {
last_radio_active_ms = _ms->getMillis();
radio_liveness.noteActivity(last_radio_active_ms);
#ifdef RADIO_LIVENESS_SOFT_ONLY
last_radio_activity_ms = _ms->getMillis();
#else
radio_liveness.noteActivity(_ms->getMillis());
#endif
logRxRaw(_radio->getLastSNR(), _radio->getLastRSSI(), raw, len);
pkt = _mgr->allocNew();
+13 -5
View File
@@ -4,7 +4,9 @@
#include <Identity.h>
#include <Packet.h>
#include <Utils.h>
#include <helpers/RadioLivenessTracker.h>
#ifndef RADIO_LIVENESS_SOFT_ONLY
#include <helpers/RadioLivenessTracker.h>
#endif
#include <string.h>
namespace mesh {
@@ -220,10 +222,12 @@ typedef uint32_t DispatcherAction;
class Dispatcher {
Packet* outbound; // current outbound packet
unsigned long outbound_expiry, outbound_start, total_air_time, rx_air_time;
unsigned long last_watchdog_recovery;
unsigned long last_radio_active_ms; // updated on any TX or RX event; used by watchdog
unsigned long last_observed_radio_irq;
#ifdef RADIO_LIVENESS_SOFT_ONLY
unsigned long last_radio_activity_ms;
#else
RadioLivenessTracker radio_liveness;
#endif
uint16_t outbound_restore_preamble_len;
uint8_t outbound_restore_cr;
unsigned long next_tx_time;
@@ -231,7 +235,9 @@ class Dispatcher {
unsigned long radio_nonrx_start;
unsigned long next_floor_calib_time, next_agc_reset_time;
bool prev_isrecv_mode;
#ifndef RADIO_LIVENESS_SOFT_ONLY
bool nonrx_soft_recovery_attempted;
#endif
uint32_t n_sent_flood, n_sent_direct;
uint32_t n_recv_flood, n_recv_direct;
unsigned long tx_budget_ms;
@@ -265,10 +271,12 @@ protected:
tx_budget_ms = 0;
last_budget_update = 0;
duty_cycle_window_ms = 3600000;
last_watchdog_recovery = 0;
last_radio_active_ms = 0;
last_observed_radio_irq = 0;
#ifdef RADIO_LIVENESS_SOFT_ONLY
last_radio_activity_ms = 0;
#else
nonrx_soft_recovery_attempted = false;
#endif
}
virtual DispatcherAction onRecvPacket(Packet* pkt) = 0;
+12 -13
View File
@@ -2,7 +2,7 @@
#include <stdint.h>
// AUTO-GENERATED by tools/mota/gen_targets.py — do not edit by hand.
// 543 OTA-capable PlatformIO envs. Maps target_id (= sha2-256:4 of the env name, LE uint32)
// 542 OTA-capable PlatformIO envs. Maps target_id (= sha2-256:4 of the env name, LE uint32)
// to the human-readable env name, so a node/tool can name a target seen over the air WITHOUT
// transmitting the string in the .mota / LoRa protocol. Regenerate when the OTA env set changes.
@@ -20,7 +20,7 @@ inline const char* ota_target_env_name(uint32_t target_id) {
{ 0xacb599d5, "GAT562_30S_Mesh_Kit_companion_radio_ble" },
{ 0x82d3b273, "GAT562_30S_Mesh_Kit_companion_radio_usb" },
{ 0xe96a6af8, "GAT562_30S_Mesh_Kit_kiss_modem" },
{ 0x70d8478d, "GAT562_30S_Mesh_Kit_repeater" },
{ 0x180bbe1f, "GAT562_30S_Mesh_Kit_repeater_lora_ota_no_external_sensors" },
{ 0xf9986af5, "GAT562_30S_Mesh_Kit_room_server" },
{ 0x98519a1d, "GAT562_Mesh_EVB_Pro_kiss_modem" },
{ 0x06b71719, "GAT562_Mesh_EVB_Pro_repeater" },
@@ -28,7 +28,7 @@ inline const char* ota_target_env_name(uint32_t target_id) {
{ 0x4fa88992, "GAT562_Mesh_Tracker_Pro_companion_radio_ble" },
{ 0xcd6604d0, "GAT562_Mesh_Tracker_Pro_companion_radio_usb" },
{ 0xc54ea258, "GAT562_Mesh_Tracker_Pro_kiss_modem" },
{ 0x0b3985a8, "GAT562_Mesh_Tracker_Pro_repeater" },
{ 0x217958b4, "GAT562_Mesh_Tracker_Pro_repeater_lora_ota_no_external_sensors" },
{ 0x03d9704a, "GAT562_Mesh_Tracker_Pro_room_server" },
{ 0x8456f753, "GAT562_Mesh_Watch13_companion_radio_ble" },
{ 0xc8104197, "GAT562_Mesh_Watch13_kiss_modem" },
@@ -80,15 +80,15 @@ inline const char* ota_target_env_name(uint32_t target_id) {
{ 0x3fbb1498, "Heltec_t096_companion_radio_usb_femoff" },
{ 0x42b0818c, "Heltec_t096_companion_radio_usb_femon" },
{ 0x80dc72a9, "Heltec_t096_kiss_modem" },
{ 0x5d3180ae, "Heltec_t096_repeater" },
{ 0x0f67c768, "Heltec_t096_repeater_bridge_rs232" },
{ 0xafeed10c, "Heltec_t096_repeater_bridge_rs232_lora_ota_no_external_sensors" },
{ 0x98411ac6, "Heltec_t096_repeater_lora_ota_no_external_sensors" },
{ 0xa14d9f4a, "Heltec_t096_room_server" },
{ 0x6494fda0, "Heltec_t096_sensor" },
{ 0x32bcdd14, "Heltec_t114_companion_radio_ble" },
{ 0xfe937f14, "Heltec_t114_companion_radio_usb" },
{ 0x5b9b1933, "Heltec_t114_kiss_modem" },
{ 0x191f3545, "Heltec_t114_repeater" },
{ 0x1b4399de, "Heltec_t114_repeater_bridge_rs232" },
{ 0xf7e47568, "Heltec_t114_repeater_lora_ota_no_external_sensors" },
{ 0xb1153422, "Heltec_t114_room_server" },
{ 0x075ca3f9, "Heltec_t114_without_display_companion_radio_ble" },
{ 0x2f9f8e7d, "Heltec_t114_without_display_companion_radio_usb" },
@@ -103,7 +103,7 @@ inline const char* ota_target_env_name(uint32_t target_id) {
{ 0x836e5931, "Heltec_T190_repeater_observer_mqtt" },
{ 0x0f1767cd, "Heltec_T190_room_server_" },
{ 0x57172fcc, "Heltec_T190_room_server_observer_mqtt" },
{ 0x85edccd3, "Heltec_t1_repeater" },
{ 0xa529b4f5, "Heltec_t1_repeater_lora_ota_no_external_sensors" },
{ 0x85a8c944, "Heltec_tower_v2_repeater" },
{ 0xb16009a0, "heltec_tracker_v2_companion_radio_ble_femoff" },
{ 0xdc780e80, "heltec_tracker_v2_companion_radio_ble_femon" },
@@ -379,16 +379,15 @@ inline const char* ota_target_env_name(uint32_t target_id) {
{ 0xf1e7cadb, "RAK_3112_room_server_observer_mqtt" },
{ 0xced7e127, "RAK_3112_sensor" },
{ 0x6925aaf0, "RAK_3112_terminal_chat" },
{ 0x94c5555a, "RAK_3401_repeater" },
{ 0x2fa509c1, "RAK_3401_repeater_lora_ota_no_external_sensors" },
{ 0x9f4d58ac, "RAK_4631_companion_radio_ble" },
{ 0x7a55dec3, "RAK_4631_companion_radio_ethernet" },
{ 0x48d3b5d4, "RAK_4631_companion_radio_usb" },
{ 0x14e6965d, "RAK_4631_kiss_modem" },
{ 0x22ea8497, "RAK_4631_repeater_bridge_rs232_serial1" },
{ 0x21bae522, "RAK_4631_repeater_bridge_rs232_serial2" },
{ 0x76f3c984, "RAK_4631_repeater_bridge_rs232_serial1_lora_ota_no_external_sensors" },
{ 0x41e33a97, "RAK_4631_repeater_bridge_rs232_serial2_lora_ota_no_external_sensors" },
{ 0x29a0da19, "RAK_4631_repeater_lora_ota_no_external_sensors" },
{ 0x626d80ed, "RAK_4631_room_server" },
{ 0x8b1d6850, "RAK_4631_sensor" },
{ 0x8a6dc63b, "RAK_4631_room_server_lora_ota_no_external_sensors" },
{ 0xf1d3c5a8, "RAK_4631_terminal_chat" },
{ 0xc6d55752, "RAK_WisMesh_Tag_companion_radio_ble" },
{ 0x60683191, "RAK_WisMesh_Tag_companion_radio_usb" },
@@ -514,7 +513,7 @@ inline const char* ota_target_env_name(uint32_t target_id) {
{ 0x475a2a6a, "WioTrackerL1_companion_radio_ble" },
{ 0xf4175d2c, "WioTrackerL1_companion_radio_usb" },
{ 0x3d831006, "WioTrackerL1_kiss_modem" },
{ 0x556eb1bc, "WioTrackerL1_repeater" },
{ 0xb67370b3, "WioTrackerL1_repeater_lora_ota_no_external_sensors" },
{ 0x0c689b90, "WioTrackerL1_room_server" },
{ 0x91eac424, "WioTrackerL1Eink_companion_radio_ble" },
{ 0x7a84a8c4, "WioTrackerL1Eink_kiss_modem" },
+12
View File
@@ -251,6 +251,17 @@ bool RadioLibWrapper::recoverRadio(bool hard) {
const uint8_t base_state = state & ~STATE_INT_READY;
if ((state & STATE_INT_READY) != 0 || base_state == STATE_TX_WAIT) return false;
#ifdef RADIO_LIVENESS_SOFT_ONLY
// STM32WL integrates the radio into the MCU and has no independent reset.
// Keep its useful recovery path without linking unreachable deep-reset and
// escalation machinery into flash-constrained builds.
(void)hard;
if (isReceivingPacket()) return false;
n_wd_soft++;
MESH_DEBUG_PRINTLN("RadioLibWrapper: liveness watchdog: soft AGC/RX re-arm");
resetAGC();
return true;
#else
const bool busy = isChipBusy();
if (!busy && isReceivingPacket()) return false;
@@ -276,6 +287,7 @@ bool RadioLibWrapper::recoverRadio(bool hard) {
MESH_DEBUG_PRINTLN("RadioLibWrapper: liveness watchdog: soft AGC/RX re-arm");
resetAGC();
return true;
#endif
}
void RadioLibWrapper::rxPsWatchdogCheck() {
@@ -60,6 +60,7 @@ build_src_filter = ${LilyGo_TLora_V2_1_1_6.build_src_filter}
+<../examples/simple_repeater>
build_flags =
${LilyGo_TLora_V2_1_1_6.build_flags}
-UENV_INCLUDE_BME680 ; retain BME280 and other sensors while keeping the real OTA image in-slot
-D ADVERT_NAME='"TLora-V2.1-1.6 Repeater"'
-D ADVERT_LAT=0.0
-D ADVERT_LON=0.0
+5
View File
@@ -20,11 +20,15 @@ lib_deps = ${stm32_base.lib_deps}
[env:wio-e5-mini_repeater]
extends = lora_e5_mini
board_upload.maximum_size = 245760 ; 240 KiB app, 16 KiB LittleFS
build_unflags = -Os
build_flags = ${lora_e5_mini.build_flags}
-Oz ; GCC 12's strongest size profile preserves the deployed 16 KiB filesystem boundary
-flto
-fno-inline-small-functions ; reduce flash without moving the deployed filesystem boundary
-fipa-pta
-fno-semantic-interposition
-D RADIO_LIVENESS_SOFT_ONLY=1 ; integrated STM32WL has no separate radio-reset pin
-D WIO_E5_MINI_NO_EXTERNAL_SENSORS=1 ; the dedicated sensor env retains BME280 support
-D LFS_FLASH_TOTAL_SIZE=16384
-D MESH_ENABLE_RECENT_REPEATERS=1
-D LORA_TX_POWER=22
@@ -33,6 +37,7 @@ build_flags = ${lora_e5_mini.build_flags}
-D MAX_NEIGHBOURS=50
build_src_filter = ${lora_e5_mini.build_src_filter}
+<../examples/simple_repeater/*.cpp>
lib_deps = ${stm32_base.lib_deps}
[env:wio-e5-mini_sensor]
extends = lora_e5_mini
+11 -3
View File
@@ -18,7 +18,11 @@ static const Module::RfSwitchMode_t rfswitch_table[] = {
};
VolatileRTCClock rtc_clock;
WIOE5SensorManager sensors;
#ifdef WIO_E5_MINI_NO_EXTERNAL_SENSORS
SensorManager sensors;
#else
WIOE5SensorManager sensors;
#endif
#ifdef DISPLAY_CLASS
NullDisplayDriver display;
@@ -29,7 +33,9 @@ WIOE5SensorManager sensors;
#endif
bool radio_init() {
#ifndef WIO_E5_MINI_NO_EXTERNAL_SENSORS
Wire.begin();
#endif
radio.setRfSwitchTable(rfswitch_pins, rfswitch_table);
@@ -55,7 +61,8 @@ mesh::LocalIdentity radio_new_identity() {
return mesh::LocalIdentity(&rng); // create new random identity
}
bool WIOE5SensorManager::querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) {
#ifndef WIO_E5_MINI_NO_EXTERNAL_SENSORS
bool WIOE5SensorManager::querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) {
if (!has_bme) return false;
float temp(NAN), hum(NAN), pres(NAN);
@@ -76,4 +83,5 @@ bool WIOE5SensorManager::begin() {
has_bme = bme.begin();
return has_bme;
}
}
#endif
+23 -12
View File
@@ -11,8 +11,10 @@
#include "NullDisplayDriver.h"
#endif
#include <BME280I2C.h>
#include <Wire.h>
#ifndef WIO_E5_MINI_NO_EXTERNAL_SENSORS
#include <BME280I2C.h>
#include <Wire.h>
#endif
#ifdef DISPLAY_CLASS
extern NullDisplayDriver display;
@@ -38,24 +40,33 @@ public:
for (int i=0; i<8;i++) {
raw += analogRead(PIN_A3);
}
return ((double)raw) * 1.73 * 5 * 1000 / 8 / 4096;
// 1.73 * 5 V over eight 12-bit samples is raw * 8650 / 32768.
// Fixed-point math avoids pulling double-precision helpers into this
// flash-constrained STM32WL build; the half-divisor rounds to nearest.
return (uint16_t)((raw * 8650UL + 16384UL) >> 15);
}
};
class WIOE5SensorManager : public SensorManager {
BME280I2C bme;
bool has_bme = false;
#ifndef WIO_E5_MINI_NO_EXTERNAL_SENSORS
class WIOE5SensorManager : public SensorManager {
BME280I2C bme;
bool has_bme = false;
public:
WIOE5SensorManager() {}
bool begin() override;
bool querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) override;
};
public:
WIOE5SensorManager() {}
bool begin() override;
bool querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) override;
};
#endif
extern WIOE5Board board;
extern WRAPPER_CLASS radio_driver;
extern VolatileRTCClock rtc_clock;
extern WIOE5SensorManager sensors;
#ifdef WIO_E5_MINI_NO_EXTERNAL_SENSORS
extern SensorManager sensors;
#else
extern WIOE5SensorManager sensors;
#endif
bool radio_init();
mesh::LocalIdentity radio_new_identity();
+22
View File
@@ -32,6 +32,8 @@ build_src_filter = ${WioTrackerL1.build_src_filter}
+<../examples/simple_repeater>
build_flags =
${WioTrackerL1.build_flags}
-UENABLE_OTA
-D DISABLE_LORA_OTA=1 ; Full external-sensor build exceeds the in-place OTA ceiling
-D ADVERT_NAME='"WioTrackerL1 Repeater"'
-D ADMIN_PASSWORD='"password"'
-D MAX_NEIGHBOURS=50
@@ -43,6 +45,26 @@ build_flags =
lib_deps = ${WioTrackerL1.lib_deps}
adafruit/RTClib @ ^2.1.3
; Explicit lean alternative to the full-sensor, non-OTA repeater above.
[env:WioTrackerL1_repeater_lora_ota_no_external_sensors]
extends = WioTrackerL1
build_src_filter = ${WioTrackerL1.build_src_filter}
+<../examples/simple_repeater>
build_flags =
${WioTrackerL1.build_flags}
${nrf52_no_external_sensors.build_flags}
-D ADVERT_NAME='"WioTrackerL1 Repeater"'
-D ADMIN_PASSWORD='"password"'
-D MAX_NEIGHBOURS=50
-D DISPLAY_CLASS=SH1106Display
-D ENV_PIN_SDA=PIN_WIRE1_SDA
-D ENV_PIN_SCL=PIN_WIRE1_SCL
lib_deps =
${nrf52_lora_ota.lib_deps}
adafruit/Adafruit SH110X @ ^2.1.13
adafruit/Adafruit GFX Library @ ^1.12.1
adafruit/RTClib @ ^2.1.3
[env:WioTrackerL1_room_server]
extends = WioTrackerL1
build_src_filter = ${WioTrackerL1.build_src_filter}
+4 -2
View File
@@ -1,7 +1,10 @@
#include <Arduino.h>
#include "target.h"
#include <helpers/ArduinoHelpers.h>
#include <helpers/sensors/MicroNMEALocationProvider.h>
#ifdef ENV_INCLUDE_GPS
#include <helpers/sensors/MicroNMEALocationProvider.h>
#endif
WioTrackerL1Board board;
@@ -37,4 +40,3 @@ mesh::LocalIdentity radio_new_identity() {
RadioNoiseListener rng(radio);
return mesh::LocalIdentity(&rng); // create new random identity
}