Skip to content

Commit

Permalink
Merge pull request #14734 from jeromecoutant/PR_RFSWITCH
Browse files Browse the repository at this point in the history
STM32WL LORA: HW specific out of STM32WL_LoRaRadio class
  • Loading branch information
0xc0170 authored Jun 11, 2021
2 parents 86b85a3 + 777b273 commit 530d4be
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 63 deletions.
55 changes: 3 additions & 52 deletions connectivity/drivers/lora/TARGET_STM32WL/STM32WL_LoRaRadio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,16 +123,10 @@ static DigitalOut _rf_dbg_tx(MBED_CONF_STM32WL_LORA_DRIVER_DEBUG_TX, 0);
#endif


STM32WL_LoRaRadio::STM32WL_LoRaRadio(PinName rf_switch_ctrl1,
PinName rf_switch_ctrl2,
PinName rf_switch_ctrl3
)
:
_rf_switch_ctrl1(rf_switch_ctrl1, 0),
_rf_switch_ctrl2(rf_switch_ctrl2, 0),
_rf_switch_ctrl3(rf_switch_ctrl3, 0)

STM32WL_LoRaRadio::STM32WL_LoRaRadio()
{
set_antenna_switch(RBI_SWITCH_OFF);

_radio_events = NULL;
_image_calibrated = false;
_force_image_calibration = false;
Expand Down Expand Up @@ -481,49 +475,6 @@ void STM32WL_LoRaRadio::Radio_SMPS_Set(uint8_t level)
}
}

/**
* Sets up radio switch position according to the
* radio mode
*/
void STM32WL_LoRaRadio::set_antenna_switch(RBI_Switch_TypeDef state)
{
// here we got to do ifdef for changing controls
// as some pins might be NC
switch (state) {
case RBI_SWITCH_OFF: {
/* Turn off switch */
_rf_switch_ctrl3 = 0;
_rf_switch_ctrl1 = 0;
_rf_switch_ctrl2 = 0;
break;
}
case RBI_SWITCH_RX: {
/*Turns On in Rx Mode the RF Switch */
_rf_switch_ctrl3 = 1;
_rf_switch_ctrl1 = 1;
_rf_switch_ctrl2 = 0;
break;
}
case RBI_SWITCH_RFO_LP: {
/*Turns On in Tx Low Power the RF Switch */
_rf_switch_ctrl3 = 1;
_rf_switch_ctrl1 = 1;
_rf_switch_ctrl2 = 1;
break;
}
case RBI_SWITCH_RFO_HP: {
/*Turns On in Tx High Power the RF Switch */
_rf_switch_ctrl3 = 1;
_rf_switch_ctrl1 = 0;
_rf_switch_ctrl2 = 1;
break;
}
default:
break;
}
}
/* End STM32WL specific HW defs */

void STM32WL_LoRaRadio::calibrate_image(uint32_t freq)
{
uint8_t cal_freq[2];
Expand Down
14 changes: 3 additions & 11 deletions connectivity/drivers/lora/TARGET_STM32WL/STM32WL_LoRaRadio.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,14 @@ SPDX-License-Identifier: BSD-3-Clause
#define MAX_DATA_BUFFER_SIZE_STM32WL 255
#endif


extern void set_antenna_switch(RBI_Switch_TypeDef state);

class STM32WL_LoRaRadio : public LoRaRadio {

public:
STM32WL_LoRaRadio(PinName rf_switch_ctrl1 = MBED_CONF_STM32WL_LORA_DRIVER_RF_SWITCH_CTL1,
PinName rf_switch_ctrl2 = MBED_CONF_STM32WL_LORA_DRIVER_RF_SWITCH_CTL2,
PinName rf_switch_ctrl3 = MBED_CONF_STM32WL_LORA_DRIVER_RF_SWITCH_CTL3);
STM32WL_LoRaRadio();

virtual ~STM32WL_LoRaRadio();
~STM32WL_LoRaRadio();

/**
* Registers radio events with the Mbed LoRaWAN stack and
Expand Down Expand Up @@ -315,11 +313,6 @@ class STM32WL_LoRaRadio : public LoRaRadio {

private:

// Radio specific controls (TX/RX duplexer switch control)
mbed::DigitalOut _rf_switch_ctrl1;
mbed::DigitalOut _rf_switch_ctrl2;
mbed::DigitalOut _rf_switch_ctrl3;

// Access protection
PlatformMutex mutex;

Expand Down Expand Up @@ -369,7 +362,6 @@ class STM32WL_LoRaRadio : public LoRaRadio {
uint8_t SUBGRF_SetRfTxPower(int8_t power);
void SUBGRF_SetTxParams(uint8_t paSelect, int8_t power, radio_ramp_time_t rampTime);
void Radio_SMPS_Set(uint8_t level);
void set_antenna_switch(RBI_Switch_TypeDef state);
uint32_t RadioGetWakeupTime(void);


Expand Down
64 changes: 64 additions & 0 deletions connectivity/drivers/lora/TARGET_STM32WL/STM32WL_radio_driver.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/* mbed Microcontroller Library
* SPDX-License-Identifier: BSD-3-Clause
******************************************************************************
*
* Copyright (c) 2021 STMicroelectronics.
* All rights reserved.
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/

#include "STM32WL_radio_driver.h"
#include "drivers/DigitalOut.h"


/* Sets up radio switch position according to the radio mode */
/* This configuration is for NUCLEO_WL55JC */
/* But provided as __weak so it has to be overwritten to match each specicific HW board */
MBED_WEAK void set_antenna_switch(RBI_Switch_TypeDef state)
{

// Radio specific controls (TX/RX duplexer switch control)
mbed::DigitalOut _rf_switch_ctrl1(MBED_CONF_STM32WL_LORA_DRIVER_RF_SWITCH_CTL1);
mbed::DigitalOut _rf_switch_ctrl2(MBED_CONF_STM32WL_LORA_DRIVER_RF_SWITCH_CTL2);
mbed::DigitalOut _rf_switch_ctrl3(MBED_CONF_STM32WL_LORA_DRIVER_RF_SWITCH_CTL3);

switch (state) {
case RBI_SWITCH_OFF: {
/* Turn off switch */
_rf_switch_ctrl3 = 0;
_rf_switch_ctrl1 = 0;
_rf_switch_ctrl2 = 0;
break;
}
case RBI_SWITCH_RX: {
/*Turns On in Rx Mode the RF Switch */
_rf_switch_ctrl3 = 1;
_rf_switch_ctrl1 = 1;
_rf_switch_ctrl2 = 0;
break;
}
case RBI_SWITCH_RFO_LP: {
/*Turns On in Tx Low Power the RF Switch */
_rf_switch_ctrl3 = 1;
_rf_switch_ctrl1 = 1;
_rf_switch_ctrl2 = 1;
break;
}
case RBI_SWITCH_RFO_HP: {
/*Turns On in Tx High Power the RF Switch */
_rf_switch_ctrl3 = 1;
_rf_switch_ctrl1 = 0;
_rf_switch_ctrl2 = 1;
break;
}
default:
break;
}
}

0 comments on commit 530d4be

Please sign in to comment.