Skip to content

Commit a48215d

Browse files
committed
v3.2.0
* Added support for SX1301AP2 reference design (with FPGA and additional SX1272). When a FPGA is detected at startup, the HAL automatically adapt SPI communication requests (using SPI header or not). * Added util_spectral_scan diagnostic tool to scan the spectral band in background, where the LoRa gateway operates. (can only be used with SX1301AP2 or similar design). By default it uses the same SPI device as the one used by the HAL, but it can be changed depending on the hardware architecture on which it is used. * Removed SPI FTDI support due to lack of performances to properly handle heavy packet traffic. Only native SPI suage is recommended. * HAL: added a check that SX1301 firmwares have been properly loaded at startup.
1 parent ef01a45 commit a48215d

File tree

26 files changed

+1934
-813
lines changed

26 files changed

+1934
-813
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ all:
1212
$(MAKE) all -e -C util_spi_stress
1313
$(MAKE) all -e -C util_tx_test
1414
$(MAKE) all -e -C util_tx_continuous
15+
$(MAKE) all -e -C util_spectral_scan
1516

1617
clean:
1718
$(MAKE) clean -e -C libloragw
1819
$(MAKE) clean -e -C util_pkt_logger
1920
$(MAKE) clean -e -C util_spi_stress
2021
$(MAKE) clean -e -C util_tx_test
2122
$(MAKE) clean -e -C util_tx_continuous
23+
$(MAKE) clean -e -C util_spectral_scan
2224

2325
### EOF

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
3.1.0
1+
3.2.0

libloragw/Makefile

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,9 @@ AR := $(CROSS_COMPILE)ar
1212

1313
CFLAGS := -O2 -Wall -Wextra -std=c99 -Iinc -I.
1414

15-
### library.cfg configuration file processing
16-
17-
ifeq ($(CFG_SPI),native)
18-
CFG_SPI_MSG := Linux native SPI driver
19-
CFG_SPI_OPT := CFG_SPI_NATIVE
20-
else ifeq ($(CFG_SPI),ftdi)
21-
CFG_SPI_MSG := FTDI SPI-over-USB bridge using libmpsse/libftdi/libusb
22-
CFG_SPI_OPT := CFG_SPI_FTDI
23-
else
24-
$(error No SPI physical layer selected, check ../target.cfg file.)
25-
endif
26-
2715
### linking options
2816

29-
ifeq ($(CFG_SPI),native)
30-
LIBS := -lloragw -lrt -lm
31-
else ifeq ($(CFG_SPI),ftdi)
32-
LIBS := -lloragw -lrt -lmpsse -lm
33-
endif
17+
LIBS := -lloragw -lrt -lm
3418

3519
### general build targets
3620

@@ -53,9 +37,6 @@ inc/config.h: ../VERSION library.cfg
5337
# Release version
5438
@echo "Release version : $(LIBLORAGW_VERSION)"
5539
@echo " #define LIBLORAGW_VERSION "\"$(LIBLORAGW_VERSION)\""" >> $@
56-
# SPI interface
57-
@echo "SPI interface : $(CFG_SPI_MSG)"
58-
@echo " #define $(CFG_SPI_OPT) 1" >> $@
5940
# Debug options
6041
@echo " #define DEBUG_AUX $(DEBUG_AUX)" >> $@
6142
@echo " #define DEBUG_SPI $(DEBUG_SPI)" >> $@
@@ -72,13 +53,8 @@ inc/config.h: ../VERSION library.cfg
7253
obj/loragw_aux.o: src/loragw_aux.c inc/loragw_aux.h inc/config.h
7354
$(CC) -c $(CFLAGS) $< -o $@
7455

75-
ifeq ($(CFG_SPI),native)
7656
obj/loragw_spi.o: src/loragw_spi.native.c inc/loragw_spi.h inc/config.h
7757
$(CC) -c $(CFLAGS) $< -o $@
78-
else ifeq ($(CFG_SPI),ftdi)
79-
obj/loragw_spi.o: src/loragw_spi.ftdi.c inc/loragw_spi.h inc/config.h
80-
$(CC) -c $(CFLAGS) $< -o $@
81-
endif
8258

8359
obj/loragw_reg.o: src/loragw_reg.c inc/loragw_reg.h inc/loragw_spi.h inc/config.h
8460
$(CC) -c $(CFLAGS) $< -o $@
@@ -91,11 +67,7 @@ obj/loragw_gps.o: src/loragw_gps.c inc/loragw_gps.h inc/config.h
9167

9268
### static library
9369

94-
ifeq ($(CFG_SPI),native)
95-
libloragw.a: obj/loragw_hal.o obj/loragw_gps.o obj/loragw_reg.o obj/loragw_spi.o obj/loragw_aux.o
96-
else ifeq ($(CFG_SPI),ftdi)
9770
libloragw.a: obj/loragw_hal.o obj/loragw_gps.o obj/loragw_reg.o obj/loragw_spi.o obj/loragw_aux.o
98-
endif
9971
$(AR) rcs $@ $^
10072

10173
### test programs

libloragw/inc/loragw_spi.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ Maintainer: Sylvain Miermont
3535
#define LGW_SPI_ERROR -1
3636
#define LGW_BURST_CHUNK 1024
3737

38+
#define LGW_SPI_MUX_MODE0 0x0 /* No FPGA */
39+
#define LGW_SPI_MUX_MODE1 0x1 /* FPGA, with spi mux header */
40+
41+
#define LGW_SPI_MUX_TARGET_SX1301 0x0
42+
#define LGW_SPI_MUX_TARGET_FPGA 0x1
43+
#define LGW_SPI_MUX_TARGET_EEPROM 0x2
44+
#define LGW_SPI_MUX_TARGET_SX1272 0x3
45+
3846
/* -------------------------------------------------------------------------- */
3947
/* --- PUBLIC FUNCTIONS PROTOTYPES ------------------------------------------ */
4048

@@ -61,7 +69,7 @@ int lgw_spi_close(void *spi_target);
6169
@param data data byte to write
6270
@return status of register operation (LGW_SPI_SUCCESS/LGW_SPI_ERROR)
6371
*/
64-
int lgw_spi_w(void *spi_target, uint8_t address, uint8_t data);
72+
int lgw_spi_w(void *spi_target, uint8_t spi_mux_mode, uint8_t spi_mux_target, uint8_t address, uint8_t data);
6573

6674
/**
6775
@brief LoRa concentrator SPI single-byte read
@@ -70,7 +78,7 @@ int lgw_spi_w(void *spi_target, uint8_t address, uint8_t data);
7078
@param data data byte to write
7179
@return status of register operation (LGW_SPI_SUCCESS/LGW_SPI_ERROR)
7280
*/
73-
int lgw_spi_r(void *spi_target, uint8_t address, uint8_t *data);
81+
int lgw_spi_r(void *spi_target, uint8_t spi_mux_mode, uint8_t spi_mux_target, uint8_t address, uint8_t *data);
7482

7583
/**
7684
@brief LoRa concentrator SPI burst (multiple-byte) write
@@ -80,7 +88,7 @@ int lgw_spi_r(void *spi_target, uint8_t address, uint8_t *data);
8088
@param size size of the transfer, in byte(s)
8189
@return status of register operation (LGW_SPI_SUCCESS/LGW_SPI_ERROR)
8290
*/
83-
int lgw_spi_wb(void *spi_target, uint8_t address, uint8_t *data, uint16_t size);
91+
int lgw_spi_wb(void *spi_target, uint8_t spi_mux_mode, uint8_t spi_mux_target, uint8_t address, uint8_t *data, uint16_t size);
8492

8593
/**
8694
@brief LoRa concentrator SPI burst (multiple-byte) read
@@ -90,7 +98,7 @@ int lgw_spi_wb(void *spi_target, uint8_t address, uint8_t *data, uint16_t size);
9098
@param size size of the transfer, in byte(s)
9199
@return status of register operation (LGW_SPI_SUCCESS/LGW_SPI_ERROR)
92100
*/
93-
int lgw_spi_rb(void *spi_target, uint8_t address, uint8_t *data, uint16_t size);
101+
int lgw_spi_rb(void *spi_target, uint8_t spi_mux_mode, uint8_t spi_mux_target, uint8_t address, uint8_t *data, uint16_t size);
94102

95103
#endif
96104

libloragw/install_ftdi.txt

Lines changed: 0 additions & 46 deletions
This file was deleted.

libloragw/library.cfg

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
# That file will be included in the Makefile files that have hardware dependencies
22

3-
### SPI interface to the concentrator ###
4-
# Accepted values:
5-
# native Linux native SPI driver (RECOMMENDED).
6-
# Note: check the value of /dev/spidevX.X defined in source code
7-
# to ensure the right device will be opened on your platform.
8-
# ftdi FTDI SPI-over-USB bridge using libmpsse/libftdi/libusb
9-
10-
CFG_SPI= native
11-
123
### Debug options ###
134
# Set the DEBUG_* to 1 to activate debug mode in individual modules.
145
# Warning: that makes the module *very verbose*, do not use for production

libloragw/readme.md

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,6 @@ For embedded platforms, the function could be rewritten using hardware timers.
177177
All modules use a fprintf(stderr,...) function to display debug diagnostic
178178
messages if the DEBUG_xxx is set to 1 in library.cfg
179179

180-
The other settings available in library.cfg are:
181-
182-
* CFG_SPI configures how the link between the host and the concentrator chip
183-
is done. It is highly recommended to use native SPI instead of FTDI when possible
184-
for permormance reasons.
185-
Note: when using native SPI on linux host, ensure that the /dev/spidevX.X
186-
which is to be opened on your host is the same as the one defined in
187-
libloragw/src/loragw_spi.native.c
188-
189180
### 3.3. Building procedures ###
190181

191182
For cross-compilation set the CROSS_COMPILE variable in the Makefile with the
@@ -199,16 +190,7 @@ and the *.c source files.
199190
The library.cfg is also used directly to select the proper set of dynamic
200191
libraries to be linked with.
201192

202-
### 3.4. Dynamic libraries requirements ###
203-
204-
Depending on config, SPI module needs LibMPSSE to access the FTDI SPI-over-USB
205-
bridge. Please read install_ftdi.txt for installation instructions.
206-
207-
The code was tested with version 1.3 of LibMPSSE:
208-
http://libmpsse.googlecode.com/files/libmpsse-1.3.tar.gz
209-
SHA1 Checksum: 1b994a23b118f83144261e3e786c43df74a81cd5
210-
211-
### 3.5. Export ###
193+
### 3.4. Export ###
212194

213195
Once build, to use that library on another system, you need to export the
214196
following files :
@@ -232,7 +214,7 @@ hardware (IP and/or silicon revision).
232214

233215
This code has been written for:
234216

235-
* Semtech SX1301 chip (or FPGA equivalent)
217+
* Semtech SX1301 chip
236218
* Semtech SX1257 or SX1255 I/Q transceivers
237219

238220
The library will not work if there is a mismatch between the hardware version
@@ -246,11 +228,9 @@ are platform-dependant.
246228
The functions must be rewritten depending on the SPI bridge you use:
247229

248230
* SPI master matched to the Linux SPI device driver (provided)
249-
* SPI over USB using FTDI components (provided)
231+
* SPI over USB using FTDI components (not provided)
250232
* native SPI using a microcontroller peripheral (not provided)
251233

252-
Edit library.cfg to chose which SPI physical interface you want to use.
253-
254234
You can use the test program test_loragw_spi to check with a logic analyser
255235
that the SPI communication is working
256236

libloragw/src/loragw_hal.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,8 @@ F_register(24bit) = F_rf (Hz) / F_step(Hz)
114114
const uint8_t ifmod_config[LGW_IF_CHAIN_NB] = LGW_IFMODEM_CONFIG;
115115
const uint32_t rf_rx_bandwidth[LGW_RF_CHAIN_NB] = LGW_RF_RX_BANDWIDTH;
116116

117-
/* Strings for version (and options) identification */
118-
119-
#if (CFG_SPI_NATIVE == 1)
120-
#define CFG_SPI_STR "native"
121-
#elif (CFG_SPI_FTDI == 1)
122-
#define CFG_SPI_STR "ftdi"
123-
#else
124-
#define CFG_SPI_STR "spi?"
125-
#endif
126-
127117
/* Version string, used to identify the library version/options once compiled */
128-
const char lgw_version_string[] = "Version: " LIBLORAGW_VERSION "; Options: " CFG_SPI_STR ";";
118+
const char lgw_version_string[] = "Version: " LIBLORAGW_VERSION ";";
129119

130120
/* -------------------------------------------------------------------------- */
131121
/* --- PRIVATE VARIABLES ---------------------------------------------------- */
@@ -212,6 +202,8 @@ void lgw_constant_adjust(void);
212202
int load_firmware(uint8_t target, uint8_t *firmware, uint16_t size) {
213203
int reg_rst;
214204
int reg_sel;
205+
uint8_t fw_check[8192];
206+
int32_t dummy;
215207

216208
/* check parameters */
217209
CHECK_NULL(firmware);
@@ -244,6 +236,14 @@ int load_firmware(uint8_t target, uint8_t *firmware, uint16_t size) {
244236
/* write the program in one burst */
245237
lgw_reg_wb(LGW_MCU_PROM_DATA, firmware, size);
246238

239+
/* Read back firmware code for check */
240+
lgw_reg_r( LGW_MCU_PROM_DATA, &dummy ); /* bug workaround */
241+
lgw_reg_rb( LGW_MCU_PROM_DATA, fw_check, size );
242+
if (memcmp(firmware, fw_check, size) != 0) {
243+
printf ("ERROR: Failed to load fw %d\n", (int)target);
244+
return -1;
245+
}
246+
247247
/* give back control of the MCU program ram to the MCU */
248248
lgw_reg_w(reg_sel, 1);
249249

0 commit comments

Comments
 (0)