From 42e11ac9bd6603262d7b42f4ff373fce2ec7dc89 Mon Sep 17 00:00:00 2001 From: Charles Date: Mon, 25 Jul 2022 21:58:01 +0200 Subject: [PATCH] Allow to use LowPower fix as a parameter Allow to use TCXO Control Voltage and LowPower fix as a parameter leave current default value to avoid breaking changes astyle fix --- .../lora/TARGET_STM32WL/STM32WL_LoRaRadio.cpp | 14 ++++++-------- .../lora/TARGET_STM32WL/STM32WL_radio_driver.h | 15 ++++++++++++--- .../drivers/lora/TARGET_STM32WL/mbed_lib.json | 8 ++++++++ 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/connectivity/drivers/lora/TARGET_STM32WL/STM32WL_LoRaRadio.cpp b/connectivity/drivers/lora/TARGET_STM32WL/STM32WL_LoRaRadio.cpp index 4962db7d70..d3b62e7f95 100644 --- a/connectivity/drivers/lora/TARGET_STM32WL/STM32WL_LoRaRadio.cpp +++ b/connectivity/drivers/lora/TARGET_STM32WL/STM32WL_LoRaRadio.cpp @@ -55,6 +55,8 @@ uint8_t crystal_select = MBED_CONF_STM32WL_LORA_DRIVER_CRYSTAL_SELECT; uint8_t board_rf_switch_config = MBED_CONF_STM32WL_LORA_DRIVER_RF_SWITCH_CONFIG; +radio_TCXO_ctrl_voltage_t tcxo_ctrl = MBED_CONF_STM32WL_LORA_DRIVER_TCXO_CTRL; + static void SUBGHZ_Radio_IRQHandler(void); @@ -76,12 +78,6 @@ static uint8_t _active_modem; using namespace std::chrono; using namespace mbed; - -/** - * @brief voltage of vdd tcxo. - */ -#define TCXO_CTRL_VOLTAGE TCXO_CTRL_1_7V - /*! * FSK bandwidth definition */ @@ -466,7 +462,9 @@ void STM32WL_LoRaRadio::SUBGRF_SetTxParams(uint8_t paSelect, int8_t power, radio // if in mbed_app.json we have configured rf_switch_config in rfo_hp ONLY // so "stm32wl-lora-driver.rf_switch_config": "RBI_CONF_RFO_HP" // in this particular case it's not optimal settings for power<=20dBm - if (board_rf_switch_config == RBI_CONF_RFO_HP) { + // So if we set also rfo_hp_lpfix to 1 then optimize power + // See https://github.com/ARMmbed/mbed-os/pull/15017#issuecomment-1173455762 + if (board_rf_switch_config == RBI_CONF_RFO_HP && MBED_CONF_STM32WL_LORA_DRIVER_RF_RFO_HP_LPFIX == 1) { // See Section 5.1.2 of the following Application Note // https://www.st.com/resource/en/application_note/an5457-rf-matching-network-design-guide-for-stm32wl-series-stmicroelectronics.pdf if (power > 20) { @@ -633,7 +631,7 @@ void STM32WL_LoRaRadio::cold_start_wakeup() if (crystal_select == 1) { calibration_params_t calib_param; - SUBGRF_SetTcxoMode(TCXO_CTRL_VOLTAGE, MBED_CONF_STM32WL_LORA_DRIVER_RF_WAKEUP_TIME << 6); //100 ms + SUBGRF_SetTcxoMode(tcxo_ctrl, MBED_CONF_STM32WL_LORA_DRIVER_RF_WAKEUP_TIME << 6); //100 ms calib_param.value = 0x7F; write_opmode_command(RADIO_CALIBRATE, &calib_param.value, 1); diff --git a/connectivity/drivers/lora/TARGET_STM32WL/STM32WL_radio_driver.h b/connectivity/drivers/lora/TARGET_STM32WL/STM32WL_radio_driver.h index afcc82d878..fa8d61ee1a 100644 --- a/connectivity/drivers/lora/TARGET_STM32WL/STM32WL_radio_driver.h +++ b/connectivity/drivers/lora/TARGET_STM32WL/STM32WL_radio_driver.h @@ -17,9 +17,18 @@ #define RFO_HP 2 /* STM32WL Nucleo antenna switch defines */ -#define RBI_CONF_RFO_LP_HP 0 -#define RBI_CONF_RFO_LP 1 -#define RBI_CONF_RFO_HP 2 +#define RBI_CONF_RFO_LP_HP 0 +#define RBI_CONF_RFO_LP 1 +#define RBI_CONF_RFO_HP 2 +// Some boards such as LoRa-E5 and RAK3172 have only RFO_HP path wired +// thus, in EU868 mode, TX peak is 80mA (over consumption) +// We made a fix that decrease consumption according datasheet but +// since fix breaks HW machting network, transmit range may be lowered so +// it's depending on what you want to achieve, hi range or low consumption +// Setting RBI_CONF_RFO_HP_LPFIX decrease power according datasheet but can +// reduce range (long ones) due to bad HW macthing network on the both modules +// See https://github.com/ARMmbed/mbed-os/pull/15017#issuecomment-1173455762 +#define RBI_CONF_RFO_HP_LPFIX 3 typedef enum { RBI_SWITCH_OFF = 0, diff --git a/connectivity/drivers/lora/TARGET_STM32WL/mbed_lib.json b/connectivity/drivers/lora/TARGET_STM32WL/mbed_lib.json index f1ebdd18db..e8faccd63e 100644 --- a/connectivity/drivers/lora/TARGET_STM32WL/mbed_lib.json +++ b/connectivity/drivers/lora/TARGET_STM32WL/mbed_lib.json @@ -26,10 +26,18 @@ "help": "Default: Internal XO = 0, IS_TCXO_SUPPORTED = 1", "value": "IS_TCXO_SUPPORTED" }, + "tcxo_ctrl": { + "help": "TCXO Control voltage. Default: TCXO control TCXO_CTRL_1_7V (RAK3172SIP use TCXO_CTRL_3_0V)", + "value": "TCXO_CTRL_1_7V" + }, "rf_switch_config": { "help": "Default: RBI_CONF_RFO_LP_HP = 0, RBI_CONF_RFO_LP = 1, RBI_CONF_RFO_HP = 2", "value": "RBI_CONF_RFO_LP_HP" }, + "rf_rfo_hp_lpfix": { + "help": "Fix high power consumption when only RFO_HP is used on some boards. No fix = 0, Fix = 1", + "value": 1 + }, "rf_wakeup_time": { "help": "Radio maximum wakeup time (in ms)", "value": 10