Lora-net / SWL2001

LoRa Basics Modem LoRaWAN stack
BSD 3-Clause Clear License
87 stars 50 forks source link

Relay tx and rx not setting antenna switch manually #49

Closed disruptivedesign closed 2 months ago

disruptivedesign commented 4 months ago

Hello, I am working on a port of this code for the STM32WL in a RAK3172. I have noticed that the following Tx and Rx functions in the new relay code do not explicitly set the antenna direction with the smtc_modem_hal_set_ant_switch() call.

https://github.com/Lora-net/SWL2001/blob/a7922d466b6031701e621667ccd0cc04db293fc3/lbm_lib/smtc_modem_core/lr1mac/src/relay/relay_rx/relay_rx.c#L1552 wor_ral_callback_start_tx wor_ral_callback_start_rx

In general the lr1_stack_mac_layer handles the Tx cases as follows: smtc_modem_hal_start_radio_tcxo( ); smtc_modem_hal_set_ant_switch( true ); SMTC_MODEM_HAL_PANIC_ON_FAILURE( ral_set_tx( &( rp->radio->ral ) ) == RAL_STATUS_OK );

In my testing if you break point at the ral_set_tx instances and inside the smtc_modem_hal_set_ant_switch you'll see that at least the very first Tx up during the join process will have the antenna in receive mode. Perhaps this is also the case in later transmits as well if there is a race condition between when the tx task is scheduled and when the antenna direction get set elsewhere.

lbm-team commented 3 months ago

Hi @disruptivedesign

This problem has been found by our team and it will be fixed in the next release.

Other functions are impacted ( wor_ral_callback_start_cad, relay_rxr_tx_launch_callback, wor_ral_callback_start_txand wor_ral_callback_start_rx) by the same issue.

In the mean time, you can call smtc_modem_hal_set_ant_switch after the TCXO startup function to choose the antenna direction.