From d503495189b7c49f4929947e5ac1a9f0f4113042 Mon Sep 17 00:00:00 2001 From: LukaB Date: Mon, 31 Jan 2022 08:34:07 +1300 Subject: [PATCH] Fix STM32 radio driver when bandwith is 0 A bug was detected when the uint8_t SUBGRF_GetFskBandwidthRegValue( uint32_t bandwidth ) is called and the bandwith argument has a value of 0. Comparing the code to the STMCubeWL 1.1 we can see that an if statement is missing to address the condition where bandwith is equal to 0. Added the if statement to the radio driver to account for this edge case. --- .../drivers/lora/TARGET_STM32WL/STM32WL_LoRaRadio.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/connectivity/drivers/lora/TARGET_STM32WL/STM32WL_LoRaRadio.cpp b/connectivity/drivers/lora/TARGET_STM32WL/STM32WL_LoRaRadio.cpp index fe5effcada..4962db7d70 100644 --- a/connectivity/drivers/lora/TARGET_STM32WL/STM32WL_LoRaRadio.cpp +++ b/connectivity/drivers/lora/TARGET_STM32WL/STM32WL_LoRaRadio.cpp @@ -868,6 +868,10 @@ uint8_t STM32WL_LoRaRadio::get_fsk_bw_reg_val(uint32_t bandwidth) { uint8_t i; + if (bandwidth == 0) { + return 0x1F; + } + for (i = 0; i < (sizeof(fsk_bandwidths) / sizeof(fsk_bw_t)) - 1; i++) { if ((bandwidth >= fsk_bandwidths[i].bandwidth) && (bandwidth < fsk_bandwidths[i + 1].bandwidth)) {