From 8a7dacf55d74392986c1c14e6f96b0381b7dfd59 Mon Sep 17 00:00:00 2001 From: liquidraver <504870+liquidraver@users.noreply.github.com> Date: Thu, 30 Apr 2026 20:52:21 +0200 Subject: [PATCH] increase sx1262 power to 140mA --- .../zephyr/0003-lora-sx126x-native.patch | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/zephcore/patches/zephyr/0003-lora-sx126x-native.patch b/zephcore/patches/zephyr/0003-lora-sx126x-native.patch index 910597d..c76f70c 100644 --- a/zephcore/patches/zephyr/0003-lora-sx126x-native.patch +++ b/zephcore/patches/zephyr/0003-lora-sx126x-native.patch @@ -1180,30 +1180,22 @@ index 9dbf3f26586..74d4ba120c8 100644 #endif /* ZEPHYR_DRIVERS_LORA_SX126X_SX126X_INTERNAL_H_ */ diff --git a/drivers/lora/native/sx126x/sx126x_hal.c b/drivers/lora/native/sx126x/sx126x_hal.c -index 34f7089584f..e2253cf8193 100644 +index 34f7089584f..c28f2659fce 100644 --- a/drivers/lora/native/sx126x/sx126x_hal.c +++ b/drivers/lora/native/sx126x/sx126x_hal.c -@@ -203,6 +203,14 @@ int sx126x_hal_configure_tx_params(const struct device *dev, int8_t power, - int8_t tx_power; - int ret; - -+ /* Save OCP register — SetPaConfig resets it to a chip default. */ -+ uint8_t ocp; -+ -+ ret = sx126x_hal_read_regs(dev, SX126X_REG_OCP, &ocp, 1); -+ if (ret < 0) { -+ return ret; -+ } -+ - if (config->is_sx1261) { - /* - * SX1261: Low power PA, up to +15 dBm -@@ -231,6 +239,12 @@ int sx126x_hal_configure_tx_params(const struct device *dev, int8_t power, +@@ -231,6 +231,19 @@ int sx126x_hal_configure_tx_params(const struct device *dev, int8_t power, tx_power = CLAMP(power, SX1262_MIN_POWER, SX1262_MAX_POWER); } -+ /* Restore OCP register after SetPaConfig. */ -+ ret = sx126x_hal_write_regs(dev, SX126X_REG_OCP, &ocp, 1); ++ /* SetPaConfig does not auto-update OCP on the standalone SX126x ++ * (cold-reset default is 60 mA / 0x18). The SX1262 high-power PA ++ * needs ~118 mA at +22 dBm, so OCP must be raised to 140 mA / 0x38 ++ * or the PA is current-limited and output drops to ~14-16 dBm. ++ * Mirrors what the STM32WL HAL does and what RadioLib's ++ * setCurrentLimit() programs on Arduino MeshCore. */ ++ uint8_t ocp_value = config->is_sx1261 ? 0x18 /* 60 mA */ ++ : 0x38 /* 140 mA */; ++ ret = sx126x_hal_write_regs(dev, SX126X_REG_OCP, &ocp_value, 1); + if (ret < 0) { + return ret; + }