mirror of
https://github.com/MarekZegare4/MeshCore-Solo.git
synced 2026-09-20 01:56:38 +00:00
fix(radio): init SX1262 at a safe power on boards with an external-PA curve
95e3cf26 raised LORA_TX_POWER to 30 for the GAT562 30S, but CustomSX1262 passed
it straight to RadioLib's begin(), whose setOutputPower() rejects anything over
22 dBm (ERR_INVALID_OUTPUT_POWER) -- so radio init would fail on that board.
With NUM_PA_POINTS/TX_GAIN_LORA defined, LORA_TX_POWER is a radiated power, not
a chip register value: init at register 0 and let RadioLibWrapper::setTxPower()
apply the real power through the curve right after (companion applyApc(),
repeater setTxPower at begin). Other boards are unchanged.
Verified by build (GAT562 30S companion + repeater, Heltec V3 repeater) and by
reading RadioLib's SX1262::checkOutputPower(); not tested on hardware.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -53,12 +53,22 @@ class CustomSX1262 : public SX1262 {
|
||||
if (spi) spi->begin(P_LORA_SCLK, P_LORA_MISO, P_LORA_MOSI);
|
||||
#endif
|
||||
#endif
|
||||
int status = begin(LORA_FREQ, LORA_BW, LORA_SF, cr, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 16, tcxo, useRegulatorLDO);
|
||||
#if defined(NUM_PA_POINTS) && defined(TX_GAIN_LORA)
|
||||
// With an external-PA gain curve LORA_TX_POWER is the *radiated* power (it
|
||||
// can exceed the SX1262's own 22 dBm ceiling, which makes begin() fail
|
||||
// with ERR_INVALID_OUTPUT_POWER), not a chip register value. Init at the
|
||||
// lowest register setting; RadioLibWrapper::setTxPower() applies the real
|
||||
// one through the curve once the radio is up.
|
||||
constexpr int8_t init_power = 0;
|
||||
#else
|
||||
constexpr int8_t init_power = LORA_TX_POWER;
|
||||
#endif
|
||||
int status = begin(LORA_FREQ, LORA_BW, LORA_SF, cr, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, init_power, 16, tcxo, useRegulatorLDO);
|
||||
// if radio init fails with -707/-706, try again with tcxo voltage set to 0.0f
|
||||
if (status == RADIOLIB_ERR_SPI_CMD_FAILED || status == RADIOLIB_ERR_SPI_CMD_INVALID) {
|
||||
MESH_DEBUG_PRINTLN("SX1262 init failed with error %d, retrying with TCXO at 0.0V", status);
|
||||
tcxo = 0.0f;
|
||||
status = begin(LORA_FREQ, LORA_BW, LORA_SF, cr, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, LORA_TX_POWER, 16, tcxo, useRegulatorLDO);
|
||||
status = begin(LORA_FREQ, LORA_BW, LORA_SF, cr, RADIOLIB_SX126X_SYNC_WORD_PRIVATE, init_power, 16, tcxo, useRegulatorLDO);
|
||||
}
|
||||
if (status != RADIOLIB_ERR_NONE) {
|
||||
Serial.print("ERROR: radio init failed: ");
|
||||
|
||||
Reference in New Issue
Block a user