feat(radio): calibrate dual-profile preambles from live switch timing
This commit is contained in:
1 parent
8c7f4df1cd
commit
04697db82e
16 files changed
+508
-93
No files matched your search
@@ -805,10 +805,23 @@ timing, packet reception, and TX checks before claiming the 0.6 ms goal.
|
||||
the same 200 µs TCXO/fast-retune settings as the T1000-E variant. It never
|
||||
transmits, loads an identity, or writes saved settings. Its only frequencies
|
||||
are 909.5 and 909.75 MHz; the `mod`, `freq`, `both`, and `preamble` modes change
|
||||
SF7/SF8, frequency, both, or 32/48 preamble symbols respectively. A run adds
|
||||
eight warmup hops to the requested count and times the remainder with the
|
||||
nRF52840's 64 MHz cycle counter. A separate RSSI read checks that each resumed
|
||||
receiver responds after seven milliseconds of settling; it is outside timing.
|
||||
SF7/SF8, frequency, both, or 32/48 preamble symbols respectively. A run first
|
||||
times eight rapid startup-style hops (four in each direction), then the
|
||||
requested longer sample with 10 ms between hops. Results report each sample's
|
||||
mean/maximum and the production wrapper's 10%-guarded startup and final
|
||||
budgets. A separate RSSI read checks that each resumed receiver responds after
|
||||
seven milliseconds of settling; it is outside timing.
|
||||
|
||||
The [four-hop comparison](profile_switch_t1000_spotcheck_results.json) ran
|
||||
three 1,000-hop combined frequency/SF trials. The rapid eight-hop samples
|
||||
averaged 504.346 us and peaked at 507.156 us; the 3,000 later hops averaged
|
||||
502.907 us and peaked at 503.172 us. The firmware's startup allowance was
|
||||
547 us in all three trials and covered every later hop. The cycle-counter
|
||||
measurement includes a post-retune BUSY check that the firmware's `micros()`
|
||||
sample ends before, so its 10% allowance is not exactly 110% of the reported
|
||||
cycle-counter maximum. This validates four samples per direction on this
|
||||
T1000-E only, not on every LR1110 or GPIO-expander board. The exact original
|
||||
Full Companion application was restored after the test.
|
||||
|
||||
Build with `pio run -e profile_switch_t1000_lr1110`. Flash its application-only
|
||||
ZIP with serial DFU after verifying the board's unique USB serial number and
|
||||
|
||||
@@ -0,0 +1,105 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Compare four rapid RX hops per direction with a longer T1000-E switch run."""
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import time
|
||||
|
||||
import serial
|
||||
|
||||
|
||||
def read_reply(port, key, timeout, sequence=None):
|
||||
deadline = time.monotonic() + timeout
|
||||
while time.monotonic() < deadline:
|
||||
line = port.readline().decode("utf-8", errors="replace").strip()
|
||||
if not line.startswith("{"):
|
||||
continue
|
||||
reply = json.loads(line)
|
||||
if "error" in reply:
|
||||
raise RuntimeError(reply["error"])
|
||||
if key in reply and (sequence is None or reply[key] == sequence):
|
||||
return reply
|
||||
raise TimeoutError(f"No {key} reply from {port.port}")
|
||||
|
||||
|
||||
def aggregate(result, prefix):
|
||||
sides = [result[f"{prefix}to_primary"], result[f"{prefix}to_secondary"]]
|
||||
count = sum(side["n"] for side in sides)
|
||||
return {
|
||||
"n": count,
|
||||
"mean_us": sum(side["n"] * side["mean_us"] for side in sides) / count,
|
||||
"max_us": max(side["max_us"] for side in sides),
|
||||
}
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--port", required=True)
|
||||
parser.add_argument("--count", type=int, default=1000)
|
||||
parser.add_argument("--rounds", type=int, default=3)
|
||||
parser.add_argument("--mode", choices=("mod", "freq", "both", "preamble"), default="both")
|
||||
args = parser.parse_args()
|
||||
if not 16 <= args.count <= 1000 or not 1 <= args.rounds <= 20:
|
||||
parser.error("count must be 16..1000 and rounds 1..20")
|
||||
|
||||
port = serial.Serial()
|
||||
port.port = args.port
|
||||
port.baudrate = 115200
|
||||
port.timeout = 0.25
|
||||
port.write_timeout = 2
|
||||
port.rts = False
|
||||
port.dtr = True
|
||||
port.open()
|
||||
try:
|
||||
port.reset_input_buffer()
|
||||
port.write(b"info\n")
|
||||
info = read_reply(port, "bench", 5)
|
||||
if info.get("bench") != "t1000-lr1110-production-retune-v1" or not info.get("ready"):
|
||||
raise RuntimeError(f"Wrong or unready device: {info}")
|
||||
print(json.dumps(info), flush=True)
|
||||
last_sequence = info.get("last_sequence")
|
||||
if not isinstance(last_sequence, int) or not 0 <= last_sequence <= 0xFFFFFFFF:
|
||||
raise RuntimeError("Bench firmware must report its last_sequence; rebuild and flash it")
|
||||
if last_sequence + args.rounds > 0xFFFFFFFF:
|
||||
raise RuntimeError("Bench run sequence exhausted; reboot the bench firmware")
|
||||
trials = []
|
||||
for round_number in range(1, args.rounds + 1):
|
||||
sequence = last_sequence + round_number
|
||||
port.write(f"run {args.mode} {args.count} {sequence}\n".encode("ascii"))
|
||||
try:
|
||||
result = read_reply(port, "result", args.count * 0.05 + 20, sequence)
|
||||
except TimeoutError:
|
||||
port.write(f"result result {sequence}\n".encode("ascii"))
|
||||
result = read_reply(port, "result", 5, sequence)
|
||||
spot = aggregate(result, "spot_")
|
||||
long = aggregate(result, "")
|
||||
if (spot["n"] != 8 or long["n"] != args.count or not result["restored"]
|
||||
or any(result[k] for k in ("failures", "busy_timeouts", "rx_errors", "cache_errors", "rssi_errors"))):
|
||||
raise RuntimeError(f"Trial {round_number} failed validation: {result}")
|
||||
trial = {
|
||||
"round": round_number,
|
||||
"mode": args.mode,
|
||||
"spot": spot,
|
||||
"spot_budget_us": result["spot_budget_us"],
|
||||
"long": long,
|
||||
"long_budget_us": result["long_budget_us"],
|
||||
"spot_budget_covers_long_max": result["spot_budget_us"] >= long["max_us"],
|
||||
}
|
||||
trials.append(trial)
|
||||
print(json.dumps(trial), flush=True)
|
||||
summary = {
|
||||
"trials": len(trials),
|
||||
"total_long_hops": sum(t["long"]["n"] for t in trials),
|
||||
"spot_mean_us": sum(t["spot"]["mean_us"] for t in trials) / len(trials),
|
||||
"spot_max_us": max(t["spot"]["max_us"] for t in trials),
|
||||
"long_mean_us": sum(t["long"]["mean_us"] for t in trials) / len(trials),
|
||||
"long_max_us": max(t["long"]["max_us"] for t in trials),
|
||||
"spot_budget_covered_every_trial": all(t["spot_budget_covers_long_max"] for t in trials),
|
||||
}
|
||||
print(json.dumps({"summary": summary}), flush=True)
|
||||
finally:
|
||||
port.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -201,7 +201,7 @@ void run(const char* mode, unsigned count, uint32_t sequence) {
|
||||
chip.hilInjectRxTimeout = injectTimeoutNextRun;
|
||||
injectTimeoutNextRun = false;
|
||||
|
||||
Timing total[2];
|
||||
Timing spot[2], total[2];
|
||||
uint32_t failures = 0, busyDeferrals = 0, rxErrors = 0, cacheErrors = 0;
|
||||
uint32_t busyTimeouts = 0, rssiErrors = 0;
|
||||
const uint32_t rfBefore = radioHal.rfWrites;
|
||||
@@ -227,9 +227,10 @@ void run(const char* mode, unsigned count, uint32_t sequence) {
|
||||
const uint64_t packetCyclesBefore = chip.fastPacketCycles;
|
||||
const uint64_t setRxCyclesBefore = chip.fastSetRxCycles;
|
||||
unsigned completed = 0;
|
||||
uint32_t spotBudgetUs = 0;
|
||||
for (unsigned attempt = 0; completed < count + 8 && attempt < (count + 8) * 4; ++attempt) {
|
||||
if (!waitBusy()) { ++busyTimeouts; break; }
|
||||
delay(10); // Keep host I/O and dwell outside the measured retune.
|
||||
if (completed >= 8) delay(10); // The first eight hops match the rapid startup self-test.
|
||||
const uint8_t target = driver.receiveProfile() ^ 1;
|
||||
const uint32_t started = DWT->CYCCNT;
|
||||
const auto result = driver.hop(target);
|
||||
@@ -245,13 +246,19 @@ void run(const char* mode, unsigned count, uint32_t sequence) {
|
||||
if (chip.getSpreadingFactor() != (target && modulation ? 8 : 7)
|
||||
|| chip.getFreqMHz() != (target && frequency ? 909.75f : 909.5f)
|
||||
|| chip.preambleSymbols() != (target && preambleChange ? 48 : 32)) ++cacheErrors;
|
||||
delay(7); // RSSI needs a settled receiver; this is outside switch timing.
|
||||
float rssi = 0;
|
||||
if (chip.getRssiInst(&rssi) != RADIOLIB_ERR_NONE || !isfinite(rssi)
|
||||
|| rssi < -180.0f || rssi > 20.0f) ++rssiErrors;
|
||||
if (completed++ >= 8) total[target].add(elapsed);
|
||||
if (completed < 8) spot[target].add(elapsed);
|
||||
else {
|
||||
delay(7); // RSSI needs a settled receiver; this is outside switch timing.
|
||||
float rssi = 0;
|
||||
if (chip.getRssiInst(&rssi) != RADIOLIB_ERR_NONE || !isfinite(rssi)
|
||||
|| rssi < -180.0f || rssi > 20.0f) ++rssiErrors;
|
||||
total[target].add(elapsed);
|
||||
}
|
||||
++completed;
|
||||
if (completed == 8) spotBudgetUs = driver.profiles()->switchBudgetUs();
|
||||
}
|
||||
|
||||
const uint32_t longBudgetUs = driver.profiles()->switchBudgetUs();
|
||||
driver.profiles()->setSecondary({}, true);
|
||||
auto restored = driver.hop(0);
|
||||
for (unsigned retry = 0; restored == mesh::RadioParamApplyResult::BUSY && retry < 20; ++retry) {
|
||||
@@ -266,7 +273,8 @@ void run(const char* mode, unsigned count, uint32_t sequence) {
|
||||
"\"primary\":\"909.5,125,7,5\",\"secondary_freq_mhz\":%.2f,\"secondary_sf\":%u,"
|
||||
"\"secondary_preamble\":%u,"
|
||||
"\"tcxo_us\":%lu,\"spi_hz\":%lu,\"bulk_spi\":%s,"
|
||||
"\"requested\":%u,\"completed\":%u,\"primary_busy_deferrals\":%lu,"
|
||||
"\"requested\":%u,\"completed\":%u,\"spot_budget_us\":%lu,\"long_budget_us\":%lu,"
|
||||
"\"primary_busy_deferrals\":%lu,"
|
||||
"\"busy_deferrals\":%lu,\"drain_calls\":%lu,\"drained_packets\":%lu,"
|
||||
"\"busy_high_checks\":%lu,"
|
||||
"\"receiving_true_checks\":%lu,\"failures\":%lu,"
|
||||
@@ -278,13 +286,16 @@ void run(const char* mode, unsigned count, uint32_t sequence) {
|
||||
"\"standby_mean_us\":%.3f,\"apply_mean_us\":%.3f,\"receiving_check_mean_us\":%.3f,"
|
||||
"\"start_mode_mean_us\":%.3f,\"start_rx_mean_us\":%.3f,"
|
||||
"\"clear_mean_us\":%.3f,\"packet_mean_us\":%.3f,\"set_rx_mean_us\":%.3f,"
|
||||
"\"spot_to_primary\":{\"n\":%lu,\"min_us\":%.3f,\"mean_us\":%.3f,\"max_us\":%.3f},"
|
||||
"\"spot_to_secondary\":{\"n\":%lu,\"min_us\":%.3f,\"mean_us\":%.3f,\"max_us\":%.3f},"
|
||||
"\"to_primary\":{\"n\":%lu,\"min_us\":%.3f,\"mean_us\":%.3f,\"max_us\":%.3f},"
|
||||
"\"to_secondary\":{\"n\":%lu,\"min_us\":%.3f,\"mean_us\":%.3f,\"max_us\":%.3f}}\n",
|
||||
(unsigned long)sequence, mode, double(secondary.params.freq), unsigned(secondary.params.sf),
|
||||
unsigned(secondary.params.preamble),
|
||||
(unsigned long)configuredTcxoUs, (unsigned long)radioHal.spiHz,
|
||||
radioHal.bulkTransfer ? "true" : "false",
|
||||
count, completed, (unsigned long)primaryBusyDeferrals, (unsigned long)busyDeferrals,
|
||||
count, completed, (unsigned long)spotBudgetUs, (unsigned long)longBudgetUs,
|
||||
(unsigned long)primaryBusyDeferrals, (unsigned long)busyDeferrals,
|
||||
(unsigned long)drainCalls, (unsigned long)drainedPackets,
|
||||
(unsigned long)(driver.busyHighChecks - busyHighBefore),
|
||||
(unsigned long)(driver.receivingTrueChecks - receivingTrueBefore),
|
||||
@@ -320,6 +331,8 @@ void run(const char* mode, unsigned count, uint32_t sequence) {
|
||||
chip.getOptimizedProfileSwitches() == fastBefore ? 0.0
|
||||
: double(chip.fastSetRxCycles - setRxCyclesBefore) * 1000000.0
|
||||
/ (chip.getOptimizedProfileSwitches() - fastBefore) / SystemCoreClock,
|
||||
(unsigned long)spot[0].n, spot[0].minUs(), spot[0].meanUs(), spot[0].maxUs(),
|
||||
(unsigned long)spot[1].n, spot[1].minUs(), spot[1].meanUs(), spot[1].maxUs(),
|
||||
(unsigned long)total[0].n, total[0].minUs(), total[0].meanUs(), total[0].maxUs(),
|
||||
(unsigned long)total[1].n, total[1].minUs(), total[1].meanUs(), total[1].maxUs());
|
||||
}
|
||||
@@ -370,12 +383,13 @@ void loop() {
|
||||
"\"init_rc\":%d,\"board\":\"Seeed T1000-E LR1110\","
|
||||
"\"rx_frequencies_mhz\":[909.5,909.75],\"autonomous_tx\":false,\"tx_command\":false,"
|
||||
"\"sd_fwid\":%u,\"app_base\":%u,\"cycle_hz\":%lu,\"tcxo_us\":%lu,"
|
||||
"\"spi_hz\":%lu,\"bulk_spi\":%s}\n",
|
||||
"\"spi_hz\":%lu,\"bulk_spi\":%s,\"last_sequence\":%lu}\n",
|
||||
ready ? "true" : "false", initError,
|
||||
unsigned(*reinterpret_cast<volatile uint16_t*>(0x300c)),
|
||||
unsigned(*reinterpret_cast<volatile uint32_t*>(0x3008)),
|
||||
(unsigned long)SystemCoreClock, (unsigned long)configuredTcxoUs,
|
||||
(unsigned long)radioHal.spiHz, radioHal.bulkTransfer ? "true" : "false");
|
||||
(unsigned long)radioHal.spiHz, radioHal.bulkTransfer ? "true" : "false",
|
||||
(unsigned long)nextSequence);
|
||||
Serial.print(info);
|
||||
} else if (sscanf(line, "fs %u %c", &count, &trailing) == 1 && count <= 1) {
|
||||
chip.hilUseFsOnRetune = count;
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"schema": 1,
|
||||
"experiment": "startup_four_per_direction_vs_long_run",
|
||||
"board": "Seeed T1000-E LR1110",
|
||||
"base_commit": "79fe4362",
|
||||
"source": "working tree, including the radio2 self-test changes",
|
||||
"firmware": "profile_switch_t1000_lr1110",
|
||||
"settings": {
|
||||
"mode": "both",
|
||||
"primary": "909.5 MHz, 125 kHz, SF7, CR4/5",
|
||||
"secondary": "909.75 MHz, 125 kHz, SF8, CR4/5",
|
||||
"rx_only": true,
|
||||
"tcxo_us": 200,
|
||||
"spi_hz": 16000000,
|
||||
"bulk_spi": true,
|
||||
"spot_hops_per_direction": 4,
|
||||
"long_hops_per_trial": 1000,
|
||||
"trials": 3
|
||||
},
|
||||
"trial_results": [
|
||||
{"spot_mean_us": 504.096, "spot_max_us": 507.156, "spot_model_budget_us": 547,
|
||||
"long_mean_us": 502.9065, "long_max_us": 503.172, "long_model_budget_us": 547},
|
||||
{"spot_mean_us": 504.4395, "spot_max_us": 506.531, "spot_model_budget_us": 547,
|
||||
"long_mean_us": 502.9065, "long_max_us": 503.125, "long_model_budget_us": 547},
|
||||
{"spot_mean_us": 504.502, "spot_max_us": 506.469, "spot_model_budget_us": 547,
|
||||
"long_mean_us": 502.9065, "long_max_us": 503.125, "long_model_budget_us": 547}
|
||||
],
|
||||
"summary": {
|
||||
"spot_hops": 24,
|
||||
"long_hops": 3000,
|
||||
"spot_mean_us": 504.345833,
|
||||
"spot_max_us": 507.156,
|
||||
"long_mean_us": 502.9065,
|
||||
"long_max_us": 503.172,
|
||||
"spot_model_budget_us": 547,
|
||||
"budget_covers_long_max": true,
|
||||
"failures": 0,
|
||||
"busy_timeouts": 0,
|
||||
"rx_errors": 0,
|
||||
"cache_errors": 0,
|
||||
"rssi_errors": 0,
|
||||
"original_full_companion_restored": true
|
||||
},
|
||||
"timing_note": "Cycle-counter results include the post-retune BUSY-low check. The firmware's guarded budget comes from its shorter micros() RX-reentry interval, so it is not exactly 110% of the cycle-counter maximum. The first eight rapid hops omit the 10 ms dwell and 7 ms RSSI settle used by the long-run collector; both delays are outside measured retune time."
|
||||
}
|
||||
Reference in new issue
Block a user