Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lora: Support RISC-V build, update to latest libtock-c and move to examples #432

Merged
merged 12 commits into from
Oct 25, 2024
Merged
6 changes: 3 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
[submodule "lvgl/lvgl"]
path = lvgl/lvgl
url = https://github.com/littlevgl/lvgl.git
[submodule "examples/lora/RadioLib"]
path = wip/lora/RadioLib
url = https://github.com/jgromes/RadioLib.git
[submodule "libopenthread/openthread"]
path = libopenthread/openthread
url = https://github.com/openthread/openthread.git
[submodule "RadioLib/RadioLib"]
path = RadioLib/RadioLib
url = https://github.com/jgromes/RadioLib.git
39 changes: 39 additions & 0 deletions RadioLib/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
LIBNAME := RadioLib

TOCK_USERLAND_BASE_DIR ?= ..

$(LIBNAME)_DIR := $(TOCK_USERLAND_BASE_DIR)/$(LIBNAME)

# We ideally want this:
# $(LIBNAME)_SRCS := \
# $($(LIBNAME)_DIR)/$(LIBNAME)/src/Module.cpp \
# $(wildcard $($(LIBNAME)_DIR)/$(LIBNAME)/src/*.cpp) \
# $(wildcard $($(LIBNAME)_DIR)/$(LIBNAME)/src/*/*.cpp) \
# $(wildcard $($(LIBNAME)_DIR)/$(LIBNAME)/src/*/*/*.cpp)
#
# But due to this in the GCC arm binary in the CI:
#
# ```
# (insn 179 178 46 8 (set (reg:SI 3 r3 [168])
# (mem/u/c:SI (plus:SI (reg:SI 12 ip [169])
# (unspec:SI [
# (symbol_ref/u:SI ("*.LC1") [flags 0x2])
# ] UNSPEC_PIC_SYM)) [0 S4 A32])) "../../../RadioLib/src/modules/LR11x0/LR11x0.cpp":638:16 929 {*thumb1_movsi_insn}
# (expr_list:REG_EQUAL (symbol_ref/u:SI ("*.LC1") [flags 0x2])
# (nil)))
# during RTL pass: postreload
# ../../../RadioLib/src/modules/LR11x0/LR11x0.cpp:650:1: internal compiler error: in extract_constrain_insn, at recog.c:2195
# ```
#
# we need to drop LR11x0
$(LIBNAME)_SRCS := \
$(wildcard $($(LIBNAME)_DIR)/$(LIBNAME)/src/*.cpp) \
$(wildcard $($(LIBNAME)_DIR)/$(LIBNAME)/src/utils/*.cpp) \
$(wildcard $($(LIBNAME)_DIR)/$(LIBNAME)/src/modules/C*/.cpp) \
$(wildcard $($(LIBNAME)_DIR)/$(LIBNAME)/src/modules/LL*/*.cpp) \
$(wildcard $($(LIBNAME)_DIR)/$(LIBNAME)/src/modules/RF*/*.cpp) \
$(wildcard $($(LIBNAME)_DIR)/$(LIBNAME)/src/modules/S*/*.cpp) \
$(wildcard $($(LIBNAME)_DIR)/$(LIBNAME)/src/modules/n*/*.cpp) \
$(wildcard $($(LIBNAME)_DIR)/$(LIBNAME)/src/protocols/*/*.cpp) \

include $(TOCK_USERLAND_BASE_DIR)/TockLibrary.mk
5 changes: 5 additions & 0 deletions RadioLib/Makefile.app
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Include the core RadioLib headers
override CPPFLAGS += -I$(TOCK_USERLAND_BASE_DIR)/RadioLib/RadioLib/src

# Include the Tock specific headers
override CPPFLAGS += -I$(TOCK_USERLAND_BASE_DIR)/RadioLib/RadioLib/examples/NonArduino/Tock
14 changes: 14 additions & 0 deletions RadioLib/Makefile.setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.PHONY: clean

TOCK_USERLAND_BASE_DIR ?= ../


all: $(TOCK_USERLAND_BASE_DIR)/RadioLib/RadioLib/README.md

clean::
rm -rf build

# confirm RadioLib git submodule is checked out.
$(TOCK_USERLAND_BASE_DIR)/RadioLib/RadioLib/README.md:
git submodule update --init -- $(TOCK_USERLAND_BASE_DIR)/RadioLib/RadioLib

1 change: 1 addition & 0 deletions RadioLib/RadioLib
Submodule RadioLib added at 954477
4 changes: 0 additions & 4 deletions TockLibrary.mk
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ $(call check_defined, LIBNAME)
$(call check_defined, $(LIBNAME)_DIR)
$(call check_defined, $(LIBNAME)_SRCS)

ifeq ($(strip $($(LIBNAME)_SRCS)),)
$(error Library "$(LIBNAME)" has no SRCS?)
endif

Comment on lines -32 to -35
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

@alistair23 alistair23 Jun 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically when running the formatter in the CI, the submodules aren't cloned. So no SRCs are found as there are no wildcards.

This avoids that error.

# directory for built output
$(LIBNAME)_BUILDDIR := $($(LIBNAME)_DIR)/build

Expand Down
11 changes: 11 additions & 0 deletions wip/lora/README.md → examples/lora/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,14 @@ RadioLib.
Note that the Makefiles will do this automatically when
you run `make` in a subdirectory, but if you want to do
it manually you can run the `build-RadioLib.sh` script.

### Building

To bulid any example just enter the directory and type

```shell
make
```

This will build RadioLib and then the example application for
both ARM and RISC-V architectures.
12 changes: 12 additions & 0 deletions examples/lora/sensor-receive/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Makefile for user application

# Specify this directory relative to the current application.
TOCK_USERLAND_BASE_DIR = ../../..

# Which files to compile.
CXX_SRCS := $(wildcard *.cc)

# Use the libtock-c Make system
EXTERN_LIBS += $(TOCK_USERLAND_BASE_DIR)/RadioLib

include $(TOCK_USERLAND_BASE_DIR)/AppMakefile.mk
36 changes: 36 additions & 0 deletions examples/lora/sensor-receive/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Sensor Receive
==============

This example builds an application to receiver sensor data.

## Example Output

The output should look something like this.

Note that if the receive example is started before the transmit you will get
-6 errors (RX_TIMEOUT) like below, as there is nothing to receive.

```
Apollo3 chip revision: B
Initialization complete. Entering main loop
[SX1261] Initialising Radio ...
success!
[SX1261] Receiving...
failed, code -6
failed, code -6
failed, code -6
failed, code -6
failed, code -6
failed, code -6
failed, code -6
failed, code -6
failed, code -6
failed, code -6
failed, code -6
failed, code -6
success!: Temp: 24047, Hum: 5966
success!: Temp: 24047, Hum: 5966
success!: Temp: 24047, Hum: 5966
success!: Temp: 24047, Hum: 5966
success!: Temp: 24047, Hum: 5966
```
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ int main(void) {
// Ensure there are no pending callbacks
yield_no_wait();

state = radio->receive((uint8_t*)buffer, BUFFER_LEN);
state = radio->receive(reinterpret_cast<uint8_t*> (buffer), BUFFER_LEN);

if (state == RADIOLIB_ERR_NONE) {
// the packet was successfully transmitted
Expand Down
12 changes: 12 additions & 0 deletions examples/lora/sensor-transmit/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Makefile for user application

# Specify this directory relative to the current application.
TOCK_USERLAND_BASE_DIR = ../../..

# Which files to compile.
CXX_SRCS := $(wildcard *.cc)

# Use the libtock-c Make system
EXTERN_LIBS += $(TOCK_USERLAND_BASE_DIR)/RadioLib

include $(TOCK_USERLAND_BASE_DIR)/AppMakefile.mk
19 changes: 19 additions & 0 deletions examples/lora/sensor-transmit/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Sensor Transmitter
==================

This example builds an application to transmit sensor data.

## Example Output

The output should look something like this

```
Apollo3 chip revision: B
Initialization complete. Entering main loop
[SX1261] Initialising Radio ...
success!
[SX1261] Transmitting 'Temp: 24047, Hum: 5966'
success!
[SX1261] Transmitting 'Temp: 24047, Hum: 5966'
success!
```
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#include "libtockHal.h"

// Include some libtock-c helpers
#include <sensors/humidity.h>
#include <sensors/temperature.h>
#include <libtock-sync/sensors/humidity.h>
#include <libtock-sync/sensors/temperature.h>

#define BUFFER_LEN 64

Expand Down Expand Up @@ -47,17 +47,17 @@ int main(void) {
}
printf("success!\r\n");

int temp = 0;
unsigned humi = 0;
int temp = 0;
int humi = 0;

// loop forever
for ( ;;) {
// Ensure there are no pending callbacks
yield_no_wait();

// Read some sensor data from the board
temperature_read_sync(&temp);
humidity_read_sync(&humi);
libtocksync_temperature_read(&temp);
libtocksync_humidity_read(&humi);

snprintf(buffer, BUFFER_LEN, "Temp: %d, Hum: %u", temp, humi);

Expand Down
1 change: 0 additions & 1 deletion wip/lora/RadioLib
Submodule RadioLib deleted from 0ef554
26 changes: 0 additions & 26 deletions wip/lora/build-RadioLib.sh

This file was deleted.

33 changes: 0 additions & 33 deletions wip/lora/sensor-receive/Makefile

This file was deleted.

4 changes: 0 additions & 4 deletions wip/lora/sensor-receive/README.md

This file was deleted.

33 changes: 0 additions & 33 deletions wip/lora/sensor-transmit/Makefile

This file was deleted.

4 changes: 0 additions & 4 deletions wip/lora/sensor-transmit/README.md

This file was deleted.

Loading