Merged in raiden00/nuttx_lora (pull request #829)

SX127X improvements

drivers/wireless/lpwan/sx127x/sx127x: add TX power configuration

drivers/wireless/lpwan/sx127x/sx127x: discard RX packets with unsupported length

drivers/wireless/lpwan/sx127x/sx127x: refactor some logic

drivers/wireless/lpwan/Kconfig: move some hardcoded sx127x configuration to Kconfig

drivers/wireless/lpwan/Kconfig: remove EXPERIMENTAL flag

configs/b-l072z-lrwan1/sx127x: board-specific sx127x configuration

configs/nucleo-f091rc/sx127x: board-specific sx127x configuration

configs/nucleo-l073rz/sx127x: board-specific sx127x configuration

LORA and FSK look fine but there is something missing for OOK and communication is not working yet.

Approved-by: Gregory Nutt <gnutt@nuttx.org>
This commit is contained in:
raiden00pl 2019-02-24 17:58:46 +00:00 committed by Gregory Nutt
parent 4653260388
commit 0523e8a1d0
8 changed files with 888 additions and 324 deletions

View File

@ -104,6 +104,16 @@
#define GPIO_SX127X_DIO0 (GPIO_INPUT | GPIO_FLOAT | GPIO_EXTI | \
GPIO_PORTB | GPIO_PIN4)
/* CMWX1ZZABZ-091 module antenna switch
* CRF1 - RX RFI HF - PA1
* CRF2 - TX RFO HF - PC2
* CRF3 - TX BOOST - PC1
*/
#define GPIO_SX127X_CRF1 (GPIO_SPEED_HIGH | GPIO_PORTA | GPIO_PIN1)
#define GPIO_SX127X_CRF2 (GPIO_SPEED_HIGH | GPIO_PORTC | GPIO_PIN2)
#define GPIO_SX127X_CRF3 (GPIO_SPEED_HIGH | GPIO_PORTC | GPIO_PIN1)
/****************************************************************************
* Public Data
****************************************************************************/

View File

@ -55,13 +55,6 @@
#include "b-l072z-lrwan1.h"
/* WARNING: SX1276 on my CMWX1ZZABZ-091 module suddenly stopped
* working (no SPI communication), so there might be a bug here,
* something is missing in the configuration or something else.
*/
#warning SX127X driver support for B-L072Z-LRWAN1 needs some additional verification!
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
@ -75,6 +68,9 @@
****************************************************************************/
static void sx127x_chip_reset(void);
static int sx127x_opmode_change(int opmode);
static int sx127x_freq_select(uint32_t freq);
static int sx127x_pa_select(bool enable);
static int sx127x_irq0_attach(xcpt_t isr, FAR void *arg);
/****************************************************************************
@ -83,24 +79,38 @@ static int sx127x_irq0_attach(xcpt_t isr, FAR void *arg);
struct sx127x_lower_s lower =
{
.irq0attach = sx127x_irq0_attach,
.reset = sx127x_chip_reset
.irq0attach = sx127x_irq0_attach,
.reset = sx127x_chip_reset,
.opmode_change = sx127x_opmode_change,
.freq_select = sx127x_freq_select,
.pa_select = sx127x_pa_select,
.pa_force = false
};
static bool g_high_power_output = false;
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: sx127x_irq0_attach
****************************************************************************/
static int sx127x_irq0_attach(xcpt_t isr, FAR void *arg)
{
wlinfo("Attach DIO0 IRQ\n");
/* IRQ on rising edge */
(void)stm32_gpiosetevent(GPIO_SX127X_DIO0, false, true, false, isr, arg);
(void)stm32_gpiosetevent(GPIO_SX127X_DIO0, true, false, false, isr, arg);
return OK;
}
/****************************************************************************
* Name: sx127x_chip_reset
****************************************************************************/
static void sx127x_chip_reset(void)
{
wlinfo("SX127X RESET\n");
@ -127,6 +137,119 @@ static void sx127x_chip_reset(void)
usleep(10000);
}
/****************************************************************************
* Name: sx127x_opmode_change
****************************************************************************/
static int sx127x_opmode_change(int opmode)
{
int ret = OK;
/* Configure antena switch outputs in SLEEP mode */
if (opmode == SX127X_OPMODE_SLEEP)
{
stm32_gpiowrite(GPIO_SX127X_CRF1, false);
stm32_gpiowrite(GPIO_SX127X_CRF2, false);
stm32_gpiowrite(GPIO_SX127X_CRF3, false);
stm32_configgpio(GPIO_SX127X_CRF1 | GPIO_ANALOG);
stm32_configgpio(GPIO_SX127X_CRF2 | GPIO_ANALOG);
stm32_configgpio(GPIO_SX127X_CRF3 | GPIO_ANALOG);
goto errout;
}
/* Configure antena switch outputs */
stm32_configgpio(GPIO_SX127X_CRF1 | GPIO_OUTPUT | GPIO_OUTPUT_CLEAR);
stm32_configgpio(GPIO_SX127X_CRF2 | GPIO_OUTPUT | GPIO_OUTPUT_CLEAR);
stm32_configgpio(GPIO_SX127X_CRF3 | GPIO_OUTPUT | GPIO_OUTPUT_CLEAR);
stm32_gpiowrite(GPIO_SX127X_CRF1, false);
stm32_gpiowrite(GPIO_SX127X_CRF2, false);
stm32_gpiowrite(GPIO_SX127X_CRF3, false);
switch (opmode)
{
case SX127X_OPMODE_STANDBY:
case SX127X_OPMODE_FSRX:
case SX127X_OPMODE_FSTX:
{
break;
}
case SX127X_OPMODE_TX:
{
/* Set TX RFO or TX BOOST */
if (g_high_power_output == true)
{
wlinfo("SET CRF3\n");
stm32_gpiowrite(GPIO_SX127X_CRF3, true);
}
else
{
wlinfo("SET CRF2\n");
stm32_gpiowrite(GPIO_SX127X_CRF2, true);
}
break;
}
case SX127X_OPMODE_RX:
case SX127X_OPMODE_RXSINGLE:
case SX127X_OPMODE_CAD:
{
/* Set antena RX */
wlinfo("SET CRF1\n");
stm32_gpiowrite(GPIO_SX127X_CRF1, true);
break;
}
default:
{
wlerr("ERROR: invalid mode %d\n", opmode);
ret = -EINVAL;
break;
}
}
errout:
return ret;
}
/****************************************************************************
* Name: sx127x_freq_select
****************************************************************************/
static int sx127x_freq_select(uint32_t freq)
{
int ret = OK;
/* Only HF supported (BAND3 - 860-930 MHz) */
if (freq < SX127X_HFBAND_THR)
{
ret = -EINVAL;
wlerr("LF band not supported\n");
}
return ret;
}
/****************************************************************************
* Name: sx127x_pa_select
****************************************************************************/
static int sx127x_pa_select(bool enable)
{
g_high_power_output = enable;
return OK;
}
/****************************************************************************
* Public Functions
****************************************************************************/

View File

@ -1,5 +1,6 @@
/****************************************************************************
* configs/nucleo-f091rc/src/stm32_sx127x.c
* This logic is specific for RFM98 modules (433MHz)
*
* Copyright (C) 2019 Gregory Nutt. All rights reserved.
* Authors: Mateusz Szafoni <raiden00@railab.me>
@ -68,6 +69,9 @@
****************************************************************************/
static void sx127x_chip_reset(void);
static int sx127x_opmode_change(int opmode);
static int sx127x_freq_select(uint32_t freq);
static int sx127x_pa_select(bool enable);
static int sx127x_irq0_attach(xcpt_t isr, FAR void *arg);
/****************************************************************************
@ -76,14 +80,22 @@ static int sx127x_irq0_attach(xcpt_t isr, FAR void *arg);
struct sx127x_lower_s lower =
{
.irq0attach = sx127x_irq0_attach,
.reset = sx127x_chip_reset
.irq0attach = sx127x_irq0_attach,
.reset = sx127x_chip_reset,
.opmode_change = sx127x_opmode_change,
.freq_select = sx127x_freq_select,
.pa_select = sx127x_pa_select,
.pa_force = true
};
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: sx127x_irq0_attach
****************************************************************************/
static int sx127x_irq0_attach(xcpt_t isr, FAR void *arg)
{
wlinfo("Attach DIO0 IRQ\n");
@ -94,6 +106,10 @@ static int sx127x_irq0_attach(xcpt_t isr, FAR void *arg)
return OK;
}
/****************************************************************************
* Name: sx127x_chip_reset
****************************************************************************/
static void sx127x_chip_reset(void)
{
wlinfo("SX127X RESET\n");
@ -120,6 +136,55 @@ static void sx127x_chip_reset(void)
usleep(10000);
}
/****************************************************************************
* Name: sx127x_opmode_change
****************************************************************************/
static int sx127x_opmode_change(int opmode)
{
/* Do nothing */
return OK;
}
/****************************************************************************
* Name: sx127x_freq_select
****************************************************************************/
static int sx127x_freq_select(uint32_t freq)
{
int ret = OK;
/* NOTE: this depends on your module version */
if (freq > SX127X_HFBAND_THR)
{
ret = -EINVAL;
wlerr("HF output not supported\n");
}
return ret;
}
/****************************************************************************
* Name: sx127x_pa_select
****************************************************************************/
static int sx127x_pa_select(bool enable)
{
int ret = OK;
/* Only PA_BOOST output connected to antenna */
if (enable == false)
{
ret = -EINVAL;
wlerr("Module supports only PA_BOOST pin, so PA_SELECT must be enabled!\n");
}
return ret;
}
/****************************************************************************
* Public Functions
****************************************************************************/

View File

@ -1,5 +1,6 @@
/****************************************************************************
* configs/nucleo-l073rz/src/stm32_sx127x.c
* This logic is specific for the RFM98 modules (433MHz)
*
* Copyright (C) 2019 Gregory Nutt. All rights reserved.
* Authors: Mateusz Szafoni <raiden00@railab.me>
@ -68,6 +69,9 @@
****************************************************************************/
static void sx127x_chip_reset(void);
static int sx127x_opmode_change(int opmode);
static int sx127x_freq_select(uint32_t freq);
static int sx127x_pa_select(bool enable);
static int sx127x_irq0_attach(xcpt_t isr, FAR void *arg);
/****************************************************************************
@ -76,14 +80,22 @@ static int sx127x_irq0_attach(xcpt_t isr, FAR void *arg);
struct sx127x_lower_s lower =
{
.irq0attach = sx127x_irq0_attach,
.reset = sx127x_chip_reset
.irq0attach = sx127x_irq0_attach,
.reset = sx127x_chip_reset,
.opmode_change = sx127x_opmode_change,
.freq_select = sx127x_freq_select,
.pa_select = sx127x_pa_select,
.pa_force = true
};
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: sx127x_irq0_attach
****************************************************************************/
static int sx127x_irq0_attach(xcpt_t isr, FAR void *arg)
{
wlinfo("Attach DIO0 IRQ\n");
@ -94,6 +106,10 @@ static int sx127x_irq0_attach(xcpt_t isr, FAR void *arg)
return OK;
}
/****************************************************************************
* Name: sx127x_chip_reset
****************************************************************************/
static void sx127x_chip_reset(void)
{
wlinfo("SX127X RESET\n");
@ -120,6 +136,55 @@ static void sx127x_chip_reset(void)
usleep(10000);
}
/****************************************************************************
* Name: sx127x_opmode_change
****************************************************************************/
static int sx127x_opmode_change(int opmode)
{
/* Do nothing */
return OK;
}
/****************************************************************************
* Name: sx127x_freq_select
****************************************************************************/
static int sx127x_freq_select(uint32_t freq)
{
int ret = OK;
/* NOTE: this depends on your module version */
if (freq > SX127X_HFBAND_THR)
{
ret = -EINVAL;
wlerr("HF band not supported\n");
}
return ret;
}
/****************************************************************************
* Name: sx127x_pa_select
****************************************************************************/
static int sx127x_pa_select(bool enable)
{
int ret = OK;
/* Only PA_BOOST output connected to antenna */
if (enable == false)
{
ret = -EINVAL;
wlerr("Module supports only PA_BOOST pin, so PA_SELECT must be enabled!\n");
}
return ret;
}
/****************************************************************************
* Public Functions
****************************************************************************/

View File

@ -9,12 +9,42 @@ config LPWAN_SX127X
bool "SX127X Low Power Long Range transceiver support"
default n
select SPI
depends on EXPERIMENTAL
---help---
This options adds driver support for the Samtech SX127X chip.
if LPWAN_SX127X
config LPWAN_SX127X_RFFREQ_DEFAULT
int "SX127X default RF frequency"
default 433000000
config LPWAN_SX127X_SPIFREQ
int "SX127X SPI frequency"
default 1000000
---help---
SX127X SPI frequency up to 10MHz
config LPWAN_SX127X_TXPOWER_DEFAULT
int "SX127X default TX power"
default 14
config LPWAN_SX127X_PREAMBLE_DEFAULT
int "SX127X default preamble length"
default 8
config LPWAN_SX127X_MODULATION_DEFAULT
int "SX127X default modulation scheme"
default 3 if LPWAN_SX127X_LORA
default 1 if LPWAN_SX127X_FSKOOK
range 1 3
---help---
1 - FSK, 2 - OOK, 3 - LORA
config LPWAN_SX127X_CRCON
int "SX127X CRC ON"
range 0 1
default 0
config LPWAN_SX127X_RXSUPPORT
bool "SX127X RX support"
default n
@ -39,26 +69,18 @@ config LPWAN_SX127X_LORA
bool "SX127X LORA support"
default y
if LPWAN_SX127X_LORA
config LPWAN_SX127X_LORA_IMPHEADER
int "SX127X LORA implicit header ON"
range 0 1
default 0
endif # LPWAN_SX127X_LORA
config LPWAN_SX127X_FSKOOK
bool "SX127X FSK/OOK support"
default y
choice
prompt "SX127X modulation default"
config LPWAN_SX127X_DEFAULT_LORA
bool "SX127X default LORA modualtion"
depends on LPWAN_SX127X_LORA
config LPWAN_SX127X_DEFAULT_FSK
bool "SX127X default FSK modulation"
depends on LPWAN_SX127X_FSKOOK
config LPWAN_SX127X_DEFAULT_OOK
bool "SX127X default OOK modulation"
depends on LPWAN_SX127X_FSKOOK
endchoice
default n
endif # WL_SX127X

File diff suppressed because it is too large Load Diff

View File

@ -342,7 +342,6 @@
/* FSK/OOK: Bit Rate setting */
#define SX127X_FOM_BITRATE_DEFAULT (0x1a0b)
#define SX127X_FOM_BITRATE_MAX (0xffff)
#define SX127X_FOM_BITRATE_MSB(v) ((v >> 8) & 0xff)
#define SX127X_FOM_BITRATE_LSB(v) ((v >> 0) & 0xff)
@ -359,14 +358,10 @@
#define SX127X_FOM_RXCFG_TRG_SHIFT (0) /* Bits 0-2: RX trigger */
#define SX127X_FOM_RXCFG_TRG_MASK (7 << SX127X_FOM_RXCFG_TRG_SHIFT)
# define SX127X_FOM_RXCFG_TRG_0 (0 << SX127X_FOM_RXCFG_TRG_SHIFT)
# define SX127X_FOM_RXCFG_TRG_1 (1 << SX127X_FOM_RXCFG_TRG_SHIFT)
# define SX127X_FOM_RXCFG_TRG_2 (2 << SX127X_FOM_RXCFG_TRG_SHIFT)
# define SX127X_FOM_RXCFG_TRG_3 (3 << SX127X_FOM_RXCFG_TRG_SHIFT)
# define SX127X_FOM_RXCFG_TRG_4 (4 << SX127X_FOM_RXCFG_TRG_SHIFT)
# define SX127X_FOM_RXCFG_TRG_5 (5 << SX127X_FOM_RXCFG_TRG_SHIFT)
# define SX127X_FOM_RXCFG_TRG_6 (6 << SX127X_FOM_RXCFG_TRG_SHIFT)
# define SX127X_FOM_RXCFG_TRG_7 (7 << SX127X_FOM_RXCFG_TRG_SHIFT)
# define SX127X_FOM_RXCFG_TRG_NONE (0 << SX127X_FOM_RXCFG_TRG_SHIFT) /* 000: */
# define SX127X_FOM_RXCFG_TRG_RSSI (1 << SX127X_FOM_RXCFG_TRG_SHIFT) /* 001: */
# define SX127X_FOM_RXCFG_TRG_PREDET (6 << SX127X_FOM_RXCFG_TRG_SHIFT) /* 110: */
# define SX127X_FOM_RXCFG_TRG_RSSIPREDET (7 << SX127X_FOM_RXCFG_TRG_SHIFT) /* 111: */
#define SX127X_FOM_RXCFG_AGCAUTOON (1 << 3) /* Bit 3: AGC auto ON */
#define SX127X_FOM_RXCFG_AFCAUTOON (1 << 4) /* Bit 4: AFC auto ON */
#define SX127X_FOM_RXCFG_RESRXWITHPLL (1 << 5) /* Bit 5: Restar RX with PLL lock */
@ -825,13 +820,6 @@
/* Constants ***************************************************************/
/* BAND3 (HF) -> 862(779) - 1020(960) MHz
* BAND2 (LF) -> 410 - 525(480) MHz
* BAND1 (LF) -> 137 - 175(160) MHz
*/
#define SX127X_HFBAND_THR (525000000)
/* FXOSC is 32 MHz */
#define SX127X_FXOSC (32000000)
@ -840,10 +828,6 @@
#define SX127X_FSTEP (SX127X_FXOSC/(2<<18))
/* Default RF carrier frequency is 434 MHz */
#define SX127X_FREQ_RF_DEFAULT (434000000)
/****************************************************************************
* Public Data Types
****************************************************************************/

View File

@ -51,6 +51,18 @@
/****************************************************************************
* Pre-Processor Declarations
****************************************************************************/
/* Constants to SX127X */
/* PA BOOST threshold power */
#define SX127X_PASELECT_POWER (14)
/* BAND3 (HF) -> 862(779) - 1020(960) MHz
* BAND2 (LF) -> 410 - 525(480) MHz
* BAND1 (LF) -> 137 - 175(160) MHz
*/
#define SX127X_HFBAND_THR (525000000)
/* IOCTL commands ***********************************************************/
@ -229,35 +241,59 @@ enum sx127x_lora_cr_e
LORA_CR_4d8 = 4
};
/* Only DIO0 interrupts supported for now
*
* DIO0 - RXREADY/TXREADY/CADREADY
* DIO1 - not supported yet
* DIO2 - not supported yet
* DIO3 - not supported yet
* DIO4 - not supported yet
* DIO5 - not supported yet
*/
/* Board-specific operations and configuration */
struct sx127x_lower_s
{
/* Attach DIO0 interrupt - RXREADY/TXREADY/CADREADY */
CODE int (*irq0attach)(xcpt_t handler, FAR void *arg);
#ifdef CONFIG_LPWAN_SX127X_DIO1
/* Not supported: Attach DIO1 interrupt */
CODE int (*irq1attach)(xcpt_t handler, FAR void *arg);
#endif
#ifdef CONFIG_LPWAN_SX127X_DIO2
/* Not supported: Attach DIO2 interrupt */
CODE int (*irq2attach)(xcpt_t handler, FAR void *arg);
#endif
#ifdef CONFIG_LPWAN_SX127X_DIO3
/* Not supported: Attach DIO3 interrupt */
CODE int (*irq3attach)(xcpt_t handler, FAR void *arg);
#endif
#ifdef CONFIG_LPWAN_SX127X_DIO4
/* Not supported: Attach DIO4 interrupt */
CODE int (*irq4attach)(xcpt_t handler, FAR void *arg);
#endif
#ifdef CONFIG_LPWAN_SX127X_DIO5
/* Not supported: Attach DIO5 interrupt */
CODE int (*irq5attach)(xcpt_t handler, FAR void *arg);
#endif
/* Reset radio module */
CODE void (*reset)(void);
/* Change radio operation mode */
CODE int (*opmode_change)(int opmode);
/* Change radio frequency */
CODE int (*freq_select)(uint32_t freq);
/* Set PA BOOST output */
CODE int (*pa_select)(bool enable);
/* Force PA BOOST output */
bool pa_force;
};
/****************************************************************************