diff --git a/Ubiquitous/Nuttx/aiit_board/aiit-arm32-board/src/stm32_sx127x.c b/Ubiquitous/Nuttx/aiit_board/aiit-arm32-board/src/stm32_sx127x.c index 1659ec74d..cc5e7d653 100644 --- a/Ubiquitous/Nuttx/aiit_board/aiit-arm32-board/src/stm32_sx127x.c +++ b/Ubiquitous/Nuttx/aiit_board/aiit-arm32-board/src/stm32_sx127x.c @@ -143,7 +143,7 @@ static int sx127x_freq_select(uint32_t freq) /* Only HF supported (BAND3 - 860-930 MHz) */ - if (freq < SX127X_HFBAND_THR) + if (freq > SX127X_HFBAND_THR) { ret = -EINVAL; wlerr("LF band not supported\n"); diff --git a/Ubiquitous/Nuttx/app_match_nuttx/nuttx/drivers/wireless/lpwan/Kconfig b/Ubiquitous/Nuttx/app_match_nuttx/nuttx/drivers/wireless/lpwan/Kconfig new file mode 100644 index 000000000..842502894 --- /dev/null +++ b/Ubiquitous/Nuttx/app_match_nuttx/nuttx/drivers/wireless/lpwan/Kconfig @@ -0,0 +1,88 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +if DRIVERS_LPWAN + +config LPWAN_SX127X + bool "SX127X Low Power Long Range transceiver support" + default n + select SPI + select SCHED_HPWORK + ---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 20 + +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 1 + +config LPWAN_SX127X_RXSUPPORT + bool "SX127X RX support" + default y + +if LPWAN_SX127X_RXSUPPORT + +config LPWAN_SX127X_RXFIFO_LEN + int "SX127X RX FIFO length" + default 5 + +config LPWAN_SX127X_RXFIFO_DATA_LEN + int "SX127X RX FIFO data length" + default 256 + +endif #LPWAN_SX127X_RXSUPPORT + +config LPWAN_SX127X_TXSUPPORT + bool "SX127X TX support" + default y + +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 n + +endif # WL_SX127X + +endif # DRIVERS_LPWAN diff --git a/Ubiquitous/Nuttx/app_match_nuttx/nuttx/drivers/wireless/lpwan/sx127x/sx127x.c b/Ubiquitous/Nuttx/app_match_nuttx/nuttx/drivers/wireless/lpwan/sx127x/sx127x.c index f4cabca13..1ce9f8044 100644 --- a/Ubiquitous/Nuttx/app_match_nuttx/nuttx/drivers/wireless/lpwan/sx127x/sx127x.c +++ b/Ubiquitous/Nuttx/app_match_nuttx/nuttx/drivers/wireless/lpwan/sx127x/sx127x.c @@ -769,6 +769,36 @@ static int sx127x_open(FAR struct file *filep) goto errout; } + /* Set modulation */ + + wlinfo("Set modulation mode to %d\n", CONFIG_LPWAN_SX127X_MODULATION_DEFAULT); + ret = sx127x_modulation_set(dev, CONFIG_LPWAN_SX127X_MODULATION_DEFAULT); + if (ret < 0) + { + wlerr("modulation_set failed\n"); + goto errout; + } + + /* Set RF frequency */ + + wlinfo("Set frequency to %" PRId32 "\n", CONFIG_LPWAN_SX127X_RFFREQ_DEFAULT); + ret = sx127x_frequency_set(dev, CONFIG_LPWAN_SX127X_RFFREQ_DEFAULT); + if (ret < 0) + { + wlerr("failed to change frequency %d!\n", ret); + goto errout; + } + + /* Set TX power */ + + wlinfo("Set power to %d\n", CONFIG_LPWAN_SX127X_TXPOWER_DEFAULT); + ret = sx127x_power_set(dev, CONFIG_LPWAN_SX127X_TXPOWER_DEFAULT); + if (ret < 0) + { + wlerr("failed to change power %d!\n", ret); + goto errout; + } + dev->nopens++; errout: @@ -844,6 +874,13 @@ static ssize_t sx127x_read(FAR struct file *filep, FAR char *buffer, DEBUGASSERT(inode && inode->i_private); dev = (FAR struct sx127x_dev_s *)inode->i_private; + /* Set mode to RX */ + + wlinfo("Set opmode to %" PRId32 "\n", SX127X_OPMODE_RX); + sx127x_opmode_set(dev, SX127X_OPMODE_RX); + + sx127x_writeregbyte(dev, SX127X_LRM_IRQ, 8); + ret = nxsem_wait(&dev->dev_sem); if (ret < 0) { @@ -912,9 +949,10 @@ static ssize_t sx127x_write(FAR struct file *filep, FAR const char *buffer, sx127x_opmode_set(dev, SX127X_OPMODE_STANDBY); - /* Initialize TX mode */ sx127x_writeregbyte(dev, SX127X_LRM_IRQ, 8); + /* Initialize TX mode */ + ret = sx127x_opmode_init(dev, SX127X_OPMODE_TX); if (ret < 0) { @@ -940,6 +978,8 @@ static ssize_t sx127x_write(FAR struct file *filep, FAR const char *buffer, nxsem_wait(&dev->tx_sem); + sx127x_writeregbyte(dev, SX127X_LRM_IRQ, 8); + errout: /* Change mode to IDLE after transfer * NOTE: if sequencer for FSK/OOK is ON - this should be done automatically