fix: TCXO XOSC_START_ERR handling, always apply config, register DIO1 ISR callback; TX proof of life confirmed by SDR

This commit is contained in:
Lars Nolden
2026-08-31 22:43:55 +02:00
parent 3b8547fb8a
commit f7c8614a3b
9 changed files with 283 additions and 14 deletions
+34 -8
View File
@@ -231,10 +231,22 @@ bool sx126x_init(sx126x_diag_t *diag)
read_regs(REG_SYNCWORD_0, verify, 2);
diag->spi_ok = (verify[0] == 0x54 && verify[1] == 0x3D);
// TCXO on DIO3 (1.8 V, ~4 ms), then recalibrate everything because
// enabling the TCXO invalidates the RC-based calibration.
// TCXO on DIO3 (1.8 V, ~4 ms). The first calibrate after enabling the
// TCXO latches a benign XOSC_START_ERR (the XOSC block briefly probes
// the crystal before DIO3 powers the TCXO). Correct sequence: enable,
// clear stale errors, force STDBY_XOSC (actually starts the TCXO),
// recalibrate, then judge the remaining error flags.
uint8_t tcxo[4] = {BOARD_TCXO_VOLTAGE_CODE, 0x00, 0x00, BOARD_TCXO_DELAY_STEPS};
cmd(OP_SET_DIO3_TCXO_CTRL, tcxo, 4);
cmd(OP_CLEAR_DEVICE_ERRORS, (uint8_t[]){0, 0}, 2);
uint8_t stdby_xosc = 0x01;
cmd(OP_SET_STANDBY, &stdby_xosc, 1);
vTaskDelay(pdMS_TO_TICKS(10));
busy_wait();
bool xosc_running = (((sx126x_get_status() >> 4) & 0x7) == 0x3);
cmd(OP_CLEAR_DEVICE_ERRORS, (uint8_t[]){0, 0}, 2);
uint8_t calib = 0x7F;
cmd(OP_CALIBRATE, &calib, 1);
vTaskDelay(pdMS_TO_TICKS(10));
@@ -242,9 +254,9 @@ bool sx126x_init(sx126x_diag_t *diag)
uint16_t errs = sx126x_get_device_errors();
diag->device_errors = errs;
// XOSC_START_ERR (bit 5) would indicate TCXO trouble
diag->tcxo_ok = ((errs & 0x20) == 0);
diag->tcxo_ok = xosc_running && ((errs & 0x20) == 0);
if (errs) cmd(OP_CLEAR_DEVICE_ERRORS, (uint8_t[]){0, 0}, 2);
cmd(OP_SET_STANDBY, &(uint8_t){0x00}, 1);
// DC-DC regulator (Heltec module has the inductor; RNode uses default LDO,
// but SX1262 modules from Heltec are DCDC-capable. Use DCDC for lower
@@ -312,11 +324,11 @@ bool sx126x_config_wmbus_c1(uint32_t freq_hz, uint8_t rx_payload_len)
ok &= cmd(OP_SET_BUFFER_BASE, (uint8_t[]){0x00, 0x00}, 2);
// IRQs on DIO1
uint16_t irqs = SX126X_IRQ_TX_DONE | SX126X_IRQ_RX_DONE | SX126X_IRQ_TIMEOUT;
// IRQs: enable ALL in the latch mask (diagnosis of missing TxDone/RxDone;
// flags only latch when enabled here), route all to DIO1.
uint8_t di[8] = {
irqs >> 8, irqs & 0xFF, // IRQ mask
irqs >> 8, irqs & 0xFF, // DIO1
0x03, 0xFF, // IRQ mask: all
0x02, 0x03, // DIO1: TxDone | RxDone | Timeout
0x00, 0x00, // DIO2 (RF switch)
0x00, 0x00, // DIO3 (TCXO)
};
@@ -445,6 +457,20 @@ uint16_t sx126x_get_device_errors(void)
if (!cmd_read(OP_GET_DEVICE_ERRORS, e, 2)) return 0xFFFF;
return ((uint16_t)e[0] << 8) | e[1];
}
bool sx126x_raw(uint8_t op, const uint8_t *args, size_t n_tx,
uint8_t *rx, size_t rx_len)
{
uint8_t tx[32] = {0}, rxb[32] = {0};
size_t total = 1 + n_tx;
if (rx_len > total) total = rx_len;
if (total > sizeof(tx)) return false;
tx[0] = op;
if (n_tx) memcpy(tx + 1, args, n_tx);
if (!xfer(tx, rxb, total)) return false;
if (rx && rx_len) memcpy(rx, rxb, rx_len);
return true;
}
uint8_t sx126x_get_status(void)
{