mirror of
https://github.com/apache/nuttx.git
synced 2026-05-27 19:36:35 +08:00
boards/esp32/heltec_wifi_lora32: Add support to SX1276
This commit adds support to SX1276 transceiver on Heltec WiFi LoRa32 board. Signed-off-by: Alan C. Assis <acassis@gmail.com>
This commit is contained in:
committed by
Xiang Xiao
parent
e5a0c3e7d7
commit
e20d4912ff
@@ -0,0 +1,68 @@
|
|||||||
|
#
|
||||||
|
# This file is autogenerated: PLEASE DO NOT EDIT IT.
|
||||||
|
#
|
||||||
|
# You can use "make menuconfig" to make any modifications to the installed .config file.
|
||||||
|
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
|
||||||
|
# modifications.
|
||||||
|
#
|
||||||
|
# CONFIG_ARCH_LEDS is not set
|
||||||
|
# CONFIG_LPWAN_SX127X_LORA is not set
|
||||||
|
# CONFIG_NSH_ARGCAT is not set
|
||||||
|
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
|
||||||
|
CONFIG_ARCH="xtensa"
|
||||||
|
CONFIG_ARCH_BOARD="heltec_wifi_lora32"
|
||||||
|
CONFIG_ARCH_BOARD_COMMON=y
|
||||||
|
CONFIG_ARCH_BOARD_HELTEC_WIFI_LORA32=y
|
||||||
|
CONFIG_ARCH_CHIP="esp32"
|
||||||
|
CONFIG_ARCH_CHIP_ESP32=y
|
||||||
|
CONFIG_ARCH_CHIP_ESP32WROVER=y
|
||||||
|
CONFIG_ARCH_STACKDUMP=y
|
||||||
|
CONFIG_ARCH_XTENSA=y
|
||||||
|
CONFIG_BOARD_LOOPSPERMSEC=16717
|
||||||
|
CONFIG_BUILTIN=y
|
||||||
|
CONFIG_DEBUG_FEATURES=y
|
||||||
|
CONFIG_DEBUG_LIB=y
|
||||||
|
CONFIG_DRIVERS_LPWAN=y
|
||||||
|
CONFIG_DRIVERS_WIRELESS=y
|
||||||
|
CONFIG_ESP32_IGNORE_CHIP_REVISION_CHECK=y
|
||||||
|
CONFIG_ESP32_SPI2=y
|
||||||
|
CONFIG_ESP32_SPI2_CLKPIN=5
|
||||||
|
CONFIG_ESP32_SPI2_CSPIN=18
|
||||||
|
CONFIG_ESP32_SPI2_MISOPIN=19
|
||||||
|
CONFIG_ESP32_SPI2_MOSIPIN=27
|
||||||
|
CONFIG_ESP32_UART0=y
|
||||||
|
CONFIG_EXAMPLES_SX127X=y
|
||||||
|
CONFIG_EXAMPLES_SX127X_RFFREQ=915000000
|
||||||
|
CONFIG_EXAMPLES_SX127X_TXDATA=63
|
||||||
|
CONFIG_EXAMPLES_SX127X_TXPOWER=20
|
||||||
|
CONFIG_FS_PROCFS=y
|
||||||
|
CONFIG_HAVE_CXX=y
|
||||||
|
CONFIG_HAVE_CXXINITIALIZE=y
|
||||||
|
CONFIG_IDLETHREAD_STACKSIZE=3072
|
||||||
|
CONFIG_INIT_ENTRYPOINT="nsh_main"
|
||||||
|
CONFIG_INIT_STACKSIZE=3072
|
||||||
|
CONFIG_INTELHEX_BINARY=y
|
||||||
|
CONFIG_LINE_MAX=64
|
||||||
|
CONFIG_LPWAN_SX127X=y
|
||||||
|
CONFIG_LPWAN_SX127X_FSKOOK=y
|
||||||
|
CONFIG_LPWAN_SX127X_RFFREQ_DEFAULT=915000000
|
||||||
|
CONFIG_LPWAN_SX127X_RXSUPPORT=y
|
||||||
|
CONFIG_LPWAN_SX127X_TXPOWER_DEFAULT=20
|
||||||
|
CONFIG_LPWAN_SX127X_TXSUPPORT=y
|
||||||
|
CONFIG_MM_REGIONS=3
|
||||||
|
CONFIG_NSH_ARCHINIT=y
|
||||||
|
CONFIG_NSH_BUILTIN_APPS=y
|
||||||
|
CONFIG_NSH_FILEIOSIZE=512
|
||||||
|
CONFIG_NSH_READLINE=y
|
||||||
|
CONFIG_PREALLOC_TIMERS=4
|
||||||
|
CONFIG_RAM_SIZE=114688
|
||||||
|
CONFIG_RAM_START=0x20000000
|
||||||
|
CONFIG_RR_INTERVAL=200
|
||||||
|
CONFIG_SCHED_HPWORK=y
|
||||||
|
CONFIG_SCHED_WAITPID=y
|
||||||
|
CONFIG_START_DAY=6
|
||||||
|
CONFIG_START_MONTH=12
|
||||||
|
CONFIG_START_YEAR=2011
|
||||||
|
CONFIG_SYSLOG_BUFFER=y
|
||||||
|
CONFIG_SYSTEM_NSH=y
|
||||||
|
CONFIG_UART0_SERIAL_CONSOLE=y
|
||||||
@@ -26,6 +26,10 @@ ifeq ($(CONFIG_BOARDCTL),y)
|
|||||||
CSRCS += esp32_appinit.c
|
CSRCS += esp32_appinit.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_LPWAN_SX127X),y)
|
||||||
|
CSRCS += esp32_sx127x.c
|
||||||
|
endif
|
||||||
|
|
||||||
DEPPATH += --dep-path board
|
DEPPATH += --dep-path board
|
||||||
VPATH += :board
|
VPATH += :board
|
||||||
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board
|
CFLAGS += ${INCDIR_PREFIX}$(TOPDIR)$(DELIM)arch$(DELIM)$(CONFIG_ARCH)$(DELIM)src$(DELIM)board$(DELIM)board
|
||||||
|
|||||||
@@ -81,6 +81,16 @@ int esp32_bringup(void)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_LPWAN_SX127X
|
||||||
|
ret = esp32_lpwaninitialize();
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR,
|
||||||
|
"ERROR: Failed to initialize wireless driver: %d\n",
|
||||||
|
ret);
|
||||||
|
}
|
||||||
|
#endif /* CONFIG_LPWAN_SX127X */
|
||||||
|
|
||||||
/* If we got here then perhaps not all initialization was successful, but
|
/* If we got here then perhaps not all initialization was successful, but
|
||||||
* at least enough succeeded to bring-up NSH with perhaps reduced
|
* at least enough succeeded to bring-up NSH with perhaps reduced
|
||||||
* capabilities.
|
* capabilities.
|
||||||
|
|||||||
@@ -0,0 +1,229 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* boards/xtensa/esp32/heltec_wifi_lora32/src/esp32_sx127x.c
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership. The
|
||||||
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the
|
||||||
|
* License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <assert.h>
|
||||||
|
#include <debug.h>
|
||||||
|
|
||||||
|
#include <nuttx/board.h>
|
||||||
|
#include <nuttx/signal.h>
|
||||||
|
#include <nuttx/wireless/lpwan/sx127x.h>
|
||||||
|
#include <arch/board/board.h>
|
||||||
|
|
||||||
|
#include "esp32_gpio.h"
|
||||||
|
#include "esp32_spi.h"
|
||||||
|
#include "hardware/esp32_gpio_sigmap.h"
|
||||||
|
|
||||||
|
#include "heltec_wifi_lora32.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/* SX127X on SPI2 bus */
|
||||||
|
|
||||||
|
#define SX127X_SPI 2
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
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, void *arg);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
struct sx127x_lower_s lower =
|
||||||
|
{
|
||||||
|
.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, void *arg)
|
||||||
|
{
|
||||||
|
int irq = ESP32_PIN2IRQ(GPIO_SX127X_DIO0);
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
/* Make sure the interrupt is disabled */
|
||||||
|
|
||||||
|
esp32_gpioirqdisable(irq);
|
||||||
|
|
||||||
|
wlinfo("Attach DIO0 IRQ\n");
|
||||||
|
|
||||||
|
/* Attach to IRQ on pin connected to DIO0 */
|
||||||
|
|
||||||
|
ret = irq_attach(irq, isr, arg);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR, "ERROR: gpint_attach() failed: %d\n", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* IRQ on rising edge */
|
||||||
|
|
||||||
|
esp32_gpioirqenable(irq, RISING);
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: sx127x_chip_reset
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static void sx127x_chip_reset(void)
|
||||||
|
{
|
||||||
|
wlinfo("SX127X RESET\n");
|
||||||
|
|
||||||
|
/* Configure reset as output */
|
||||||
|
|
||||||
|
esp32_gpio_matrix_out(GPIO_SX127X_RESET, SIG_GPIO_OUT_IDX, 0, 0);
|
||||||
|
esp32_configgpio(GPIO_SX127X_RESET, OUTPUT_FUNCTION_3 | INPUT_FUNCTION_3);
|
||||||
|
|
||||||
|
/* Set pin to zero */
|
||||||
|
|
||||||
|
esp32_gpiowrite(GPIO_SX127X_RESET, 0);
|
||||||
|
|
||||||
|
/* Wait 1 ms */
|
||||||
|
|
||||||
|
nxsched_usleep(1000);
|
||||||
|
|
||||||
|
/* Set pin to high */
|
||||||
|
|
||||||
|
esp32_gpiowrite(GPIO_SX127X_RESET, 1);
|
||||||
|
|
||||||
|
/* Wait 10 ms */
|
||||||
|
|
||||||
|
nxsched_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
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int esp32_lpwaninitialize(void)
|
||||||
|
{
|
||||||
|
struct spi_dev_s *spidev;
|
||||||
|
int ret = OK;
|
||||||
|
|
||||||
|
wlinfo("Register the sx127x module\n");
|
||||||
|
|
||||||
|
/* Setup DIO0 */
|
||||||
|
|
||||||
|
esp32_configgpio(GPIO_SX127X_DIO0, INPUT_FUNCTION_3 | PULLDOWN);
|
||||||
|
|
||||||
|
/* Init SPI bus */
|
||||||
|
|
||||||
|
spidev = esp32_spibus_initialize(SX127X_SPI);
|
||||||
|
if (!spidev)
|
||||||
|
{
|
||||||
|
wlerr("ERROR: Failed to initialize SPI %d bus\n", SX127X_SPI);
|
||||||
|
ret = -ENODEV;
|
||||||
|
goto errout;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Initialize SX127X */
|
||||||
|
|
||||||
|
ret = sx127x_register(spidev, &lower);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
wlerr("ERROR: Failed to register sx127x\n");
|
||||||
|
goto errout;
|
||||||
|
}
|
||||||
|
|
||||||
|
errout:
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
@@ -37,6 +37,11 @@
|
|||||||
|
|
||||||
/* Heltec WiFi LoRa32 GPIOs *************************************************/
|
/* Heltec WiFi LoRa32 GPIOs *************************************************/
|
||||||
|
|
||||||
|
/* SX1276 pins */
|
||||||
|
|
||||||
|
#define GPIO_SX127X_RESET 14 /* RESET connected to IO14 */
|
||||||
|
#define GPIO_SX127X_DIO0 26 /* DIO0 connected to IO26 */
|
||||||
|
|
||||||
/* BOOT Button */
|
/* BOOT Button */
|
||||||
|
|
||||||
#define BUTTON_BOOT 0
|
#define BUTTON_BOOT 0
|
||||||
@@ -111,5 +116,24 @@
|
|||||||
|
|
||||||
int esp32_bringup(void);
|
int esp32_bringup(void);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32_lpwaninitialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize the SX127x driver
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) is returned on success; A negated errno value is returned
|
||||||
|
* to indicate the nature of any failure.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_LPWAN_SX127X
|
||||||
|
int esp32_lpwaninitialize(void);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* __ASSEMBLY__ */
|
#endif /* __ASSEMBLY__ */
|
||||||
#endif /* __BOARDS_XTENSA_ESP32_HELTEC_WIFI_LORA32_SRC_HELTEC_WIFI_LORA32_H */
|
#endif /* __BOARDS_XTENSA_ESP32_HELTEC_WIFI_LORA32_SRC_HELTEC_WIFI_LORA32_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user