[STM32WL] Fixed output power for modules without LP (#798)

pull/801/head
jgromes 2023-07-16 15:50:26 +02:00
rodzic 65a43dbd13
commit 76ac7d3dad
8 zmienionych plików z 86 dodań i 16 usunięć

Wyświetl plik

@ -19,11 +19,28 @@
// no need to configure pins, signals are routed to the radio internally
STM32WLx radio = new STM32WLx_Module();
// set RF switch configuration for Nucleo WL55JC1
// NOTE: other boards may be different!
// Some boards may not have either LP or HP.
// For those, do not set the LP/HP entry in the table.
static const uint32_t rfswitch_pins[] =
{PC3, PC4, PC5};
static const Module::RfSwitchMode_t rfswitch_table[] = {
{STM32WLx::MODE_IDLE, {LOW, LOW, LOW}},
{STM32WLx::MODE_RX, {HIGH, HIGH, LOW}},
{STM32WLx::MODE_TX_LP, {HIGH, HIGH, HIGH}},
{STM32WLx::MODE_TX_HP, {HIGH, LOW, HIGH}},
END_OF_MODE_TABLE,
};
void setup() {
Serial.begin(9600);
// initialize STM32WLx with default settings
// set RF switch control configuration
// this has to be done prior to calling begin()
radio.setRfSwitchTable(rfswitch_pins, rfswitch_table);
// initialize STM32WLx with default settings, except frequency
Serial.print(F("[STM32WLx] Initializing ... "));
int state = radio.begin(868.0);
if (state == RADIOLIB_ERR_NONE) {

Wyświetl plik

@ -19,11 +19,28 @@
// no need to configure pins, signals are routed to the radio internally
STM32WLx radio = new STM32WLx_Module();
// set RF switch configuration for Nucleo WL55JC1
// NOTE: other boards may be different!
// Some boards may not have either LP or HP.
// For those, do not set the LP/HP entry in the table.
static const uint32_t rfswitch_pins[] =
{PC3, PC4, PC5};
static const Module::RfSwitchMode_t rfswitch_table[] = {
{STM32WLx::MODE_IDLE, {LOW, LOW, LOW}},
{STM32WLx::MODE_RX, {HIGH, HIGH, LOW}},
{STM32WLx::MODE_TX_LP, {HIGH, HIGH, HIGH}},
{STM32WLx::MODE_TX_HP, {HIGH, LOW, HIGH}},
END_OF_MODE_TABLE,
};
void setup() {
Serial.begin(9600);
// initialize STM32WLx with default settings
// set RF switch control configuration
// this has to be done prior to calling begin()
radio.setRfSwitchTable(rfswitch_pins, rfswitch_table);
// initialize STM32WLx with default settings, except frequency
Serial.print(F("[STM32WLx] Initializing ... "));
int state = radio.begin(868.0);
if (state == RADIOLIB_ERR_NONE) {

Wyświetl plik

@ -37,6 +37,8 @@ STM32WLx radio = new STM32WLx_Module();
// set RF switch configuration for Nucleo WL55JC1
// NOTE: other boards may be different!
// Some boards may not have either LP or HP.
// For those, do not set the LP/HP entry in the table.
static const uint32_t rfswitch_pins[] =
{PC3, PC4, PC5};
static const Module::RfSwitchMode_t rfswitch_table[] = {

Wyświetl plik

@ -31,6 +31,8 @@ STM32WLx radio = new STM32WLx_Module();
// set RF switch configuration for Nucleo WL55JC1
// NOTE: other boards may be different!
// Some boards may not have either LP or HP.
// For those, do not set the LP/HP entry in the table.
static const uint32_t rfswitch_pins[] =
{PC3, PC4, PC5};
static const Module::RfSwitchMode_t rfswitch_table[] = {

Wyświetl plik

@ -32,6 +32,8 @@ STM32WLx radio = new STM32WLx_Module();
// set RF switch configuration for Nucleo WL55JC1
// NOTE: other boards may be different!
// Some boards may not have either LP or HP.
// For those, do not set the LP/HP entry in the table.
static const uint32_t rfswitch_pins[] =
{PC3, PC4, PC5};
static const Module::RfSwitchMode_t rfswitch_table[] = {

Wyświetl plik

@ -23,6 +23,8 @@ STM32WLx radio = new STM32WLx_Module();
// set RF switch configuration for Nucleo WL55JC1
// NOTE: other boards may be different!
// Some boards may not have either LP or HP.
// For those, do not set the LP/HP entry in the table.
static const uint32_t rfswitch_pins[] =
{PC3, PC4, PC5};
static const Module::RfSwitchMode_t rfswitch_table[] = {

Wyświetl plik

@ -44,21 +44,48 @@ int16_t STM32WLx::setOutputPower(int8_t power) {
int16_t state = readRegister(RADIOLIB_SX126X_REG_OCP_CONFIGURATION, &ocp, 1);
RADIOLIB_ASSERT(state);
// Use HP only if available and needed for the requested power
// check the user did not request power output that is not possible
bool hp_supported = this->mod->findRfSwitchMode(MODE_TX_HP);
bool use_hp = power > 14 && hp_supported;
// set PA config.
if(use_hp) {
RADIOLIB_CHECK_RANGE(power, -9, 22, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
state = SX126x::setPaConfig(0x04, 0x00, 0x07); // HP output up to 22dBm
this->txMode = MODE_TX_HP;
} else {
RADIOLIB_CHECK_RANGE(power, -17, 14, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
state = SX126x::setPaConfig(0x04, 0x01, 0x00); // LP output up to 14dBm
this->txMode = MODE_TX_LP;
bool lp_supported = this->mod->findRfSwitchMode(MODE_TX_LP);
if((!lp_supported && (power < -9)) || (!hp_supported && (power > 14))) {
// LP not supported but requested power is below HP low bound or
// HP not supported but requested power is above LP high bound
return(RADIOLIB_ERR_INVALID_OUTPUT_POWER);
}
// set PA config based on which PAs are supported
bool use_hp = false;
if(hp_supported && lp_supported) {
// both PAs supported, use HP when above 14 dBm
if(power > 14) {
RADIOLIB_CHECK_RANGE(power, -9, 22, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
state = SX126x::setPaConfig(0x04, 0x00, 0x07); // HP output up to 22dBm
this->txMode = MODE_TX_HP;
use_hp = true;
} else {
RADIOLIB_CHECK_RANGE(power, -17, 14, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
state = SX126x::setPaConfig(0x04, 0x01, 0x00); // LP output up to 14dBm
this->txMode = MODE_TX_LP;
}
} else if(!hp_supported && lp_supported) {
// only LP supported
RADIOLIB_CHECK_RANGE(power, -17, 14, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
state = SX126x::setPaConfig(0x04, 0x01, 0x00);
this->txMode = MODE_TX_LP;
} else if(hp_supported && !lp_supported) {
// only HP supported
RADIOLIB_CHECK_RANGE(power, -9, 22, RADIOLIB_ERR_INVALID_OUTPUT_POWER);
state = SX126x::setPaConfig(0x04, 0x00, 0x07);
this->txMode = MODE_TX_HP;
use_hp = true;
} else {
// neither PA is supported
return(RADIOLIB_ERR_INVALID_OUTPUT_POWER);
}
RADIOLIB_ASSERT(state);
// Apply workaround for HP only
state = SX126x::fixPaClamping(use_hp);

Wyświetl plik

@ -82,7 +82,8 @@ class STM32WLx : public SX1262 {
LP is preferred and supports -17 to +14dBm. When a higher power is
requested (or the LP amplifier is marked as unavailable using
setRfSwitchTable()), HP is used, which supports -9 to +22dBm.
setRfSwitchTable()), HP is used, which supports -9 to +22dBm. If the LP is marked as unavailable,
HP output will be used instead.
\param power Output power to be set in dBm.