Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.
Prev Previous commit
Next Next commit
lora buildflag and disable cleanly with pyeth
previously lora was only /not started/ with pyethernet enabled. but when user tries to use it, it crashes with a nasty looking error:
https://forum.pycom.io/topic/6176/pygate-assert-failed-error/2

with this change, lora can be fully excluded now and a user would get the much cleaner: ImportError: cannot import name LoRa
  • Loading branch information
peter-pycom committed Dec 22, 2020
commit 6c52763b1c30369173bc4769413e57b7cb9de15e
28 changes: 21 additions & 7 deletions esp32/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,19 @@ PYGATE_ENABLED ?= 0
# COAP is enabled by default
MOD_COAP_ENABLED ?= 1

# SIGFOX is enabled by default. It will only be built for supported boards.
# LORA is enabled by default for supported boards
ifeq ($(BOARD), $(filter $(BOARD), LOPY LOPY4 FIPY))
MOD_LORA_ENABLED ?= 1
else
MOD_LORA_ENABLED ?= 0
endif

# SIGFOX is enabled by default for supported boards
ifeq ($(BOARD), $(filter $(BOARD), SIPY LOPY4 FIPY))
MOD_SIGFOX_ENABLED ?= 1
else
MOD_SIGFOX_ENABLED ?= 0
endif

# Pybytes disabled by default
PYBYTES_ENABLED ?= 0
Expand All @@ -55,6 +66,7 @@ ifeq ($(VARIANT),PYGATE)
endif
PYBYTES_ENABLED=1
PYETH_ENABLED=1
MOD_LORA_ENABLED=0 # ETH and LORA are mutually exclusive
PYGATE_ENABLED=1
endif

Expand Down Expand Up @@ -156,19 +168,21 @@ ifeq ($(MOD_COAP_ENABLED), 1)
CFLAGS += -DMOD_COAP_ENABLED
endif

ifeq ($(MOD_LORA_ENABLED), 1)
$(info LORA Module Enabled)
CFLAGS += -DMOD_LORA_ENABLED
endif

ifeq ($(DIFF_UPDATE_ENABLED), 1)
$(info Differential Update Enabled)
CFLAGS += -DDIFF_UPDATE_ENABLED -DBZ_NO_STDIO
endif

ifeq ($(MOD_SIGFOX_ENABLED), 1)
$(info SIGFOX Module Enabled)

ifeq ($(BOARD), $(filter $(BOARD), SIPY LOPY4 FIPY))
CFLAGS += -DMOD_SIGFOX_ENABLED
LIBS += sigfox/modsigfox_$(BOARD).a -lsigfox
$(BUILD)/application.elf: sigfox/modsigfox_$(BOARD).a
endif
CFLAGS += -DMOD_SIGFOX_ENABLED
LIBS += sigfox/modsigfox_$(BOARD).a -lsigfox
$(BUILD)/application.elf: sigfox/modsigfox_$(BOARD).a
endif

ifeq ($(OPENTHREAD), on)
Expand Down
17 changes: 17 additions & 0 deletions esp32/application.mk
Original file line number Diff line number Diff line change
Expand Up @@ -388,13 +388,30 @@ BOOT_SRC_C = $(addprefix bootloader/,\
SFX_OBJ =

OBJ = $(PY_O)
ifeq ($(MOD_LORA_ENABLED), 1)

ifeq ($(BOARD), $(filter $(BOARD), LOPY FIPY))
OBJ += $(addprefix $(BUILD)/, $(APP_LORA_SRC_C:.c=.o) $(APP_LIB_LORA_SRC_C:.c=.o) $(APP_SX1272_SRC_C:.c=.o) $(APP_MODS_LORA_SRC_C:.c=.o))
endif

ifeq ($(BOARD), $(filter $(BOARD), LOPY4))
OBJ += $(addprefix $(BUILD)/, $(APP_LORA_SRC_C:.c=.o) $(APP_LIB_LORA_SRC_C:.c=.o) $(APP_SX1276_SRC_C:.c=.o) $(APP_MODS_LORA_SRC_C:.c=.o))
endif

endif

ifeq ($(MOD_SIGFOX_ENABLED), 1)

ifeq ($(BOARD), $(filter $(BOARD), LOPY FIPY))
OBJ += $(addprefix $(BUILD)/, $(APP_LORA_SRC_C:.c=.o) $(APP_LIB_LORA_SRC_C:.c=.o) $(APP_SX1272_SRC_C:.c=.o) $(APP_MODS_LORA_SRC_C:.c=.o))
endif

ifeq ($(BOARD), $(filter $(BOARD), LOPY4))
OBJ += $(addprefix $(BUILD)/, $(APP_LORA_SRC_C:.c=.o) $(APP_LIB_LORA_SRC_C:.c=.o) $(APP_SX1276_SRC_C:.c=.o) $(APP_MODS_LORA_SRC_C:.c=.o))
endif

endif

ifeq ($(MOD_SIGFOX_ENABLED), 1)
ifeq ($(BOARD), $(filter $(BOARD), SIPY))
OBJ += $(addprefix $(BUILD)/, $(APP_SIGFOX_MOD_SRC_C:.c=.o))
Expand Down
2 changes: 1 addition & 1 deletion esp32/mods/modmachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ STATIC mp_obj_t machine_sleep (uint n_args, const mp_obj_t *arg) {
}
#endif

#if defined(LOPY) || defined(LOPY4) || defined(FIPY)
#ifdef MOD_LORA_ENABLED
/* Send LoRa module to Sleep Mode */
modlora_sleep_module();
while(!modlora_is_module_sleep())
Expand Down
6 changes: 3 additions & 3 deletions esp32/mods/modnetwork.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ mp_obj_t mod_network_find_nic(const mod_network_socket_obj_t *s, const uint8_t *
mp_obj_t nic = MP_STATE_PORT(mod_network_nic_list).items[i];
// we want a raw network card
if (ip == NULL) {
#if defined (LOPY) || defined(LOPY4) || defined (FIPY)
#ifdef MOD_LORA_ENABLED
if (mp_obj_get_type(nic) == (mp_obj_type_t *)&mod_network_nic_type_lora && s->sock_base.u.u_param.domain == AF_LORA) {
return nic;
}
#endif
#endif
#if defined (SIPY) || defined (LOPY4) || defined (FIPY)
#if defined (MOD_SIGFOX_ENABLED)
if (mp_obj_get_type(nic) == (mp_obj_type_t *)&mod_network_nic_type_sigfox && s->sock_base.u.u_param.domain == AF_SIGFOX) {
Expand Down Expand Up @@ -371,7 +371,7 @@ STATIC const mp_map_elem_t mp_module_network_globals_table[] = {
#ifdef PYETH_ENABLED
{ MP_OBJ_NEW_QSTR(MP_QSTR_ETH), (mp_obj_t)&mod_network_nic_type_eth },
#endif
#if defined (LOPY) || defined(LOPY4) || defined (FIPY)
#ifdef MOD_LORA_ENABLED
{ MP_OBJ_NEW_QSTR(MP_QSTR_LoRa), (mp_obj_t)&mod_network_nic_type_lora },
#endif
#if defined (SIPY) || defined (LOPY4) || defined (FIPY)
Expand Down
8 changes: 4 additions & 4 deletions esp32/mods/modusocket.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ STATIC mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) {
mod_network_socket_obj_t *self = self_in;
int _errno;

#if defined (LOPY) || defined(LOPY4) || defined(FIPY)
#ifdef MOD_LORA_ENABLED
if (self->sock_base.nic_type == &mod_network_nic_type_lora) {
if (MP_OBJ_IS_INT(addr_in)) {
mp_uint_t port = mp_obj_get_int(addr_in);
Expand Down Expand Up @@ -301,7 +301,7 @@ STATIC mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) {
if (self->sock_base.nic_type->n_bind(self, ip, port, &_errno) != 0) {
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(_errno)));
}
#if defined (LOPY) || defined(LOPY4) || defined(FIPY)
#ifdef MOD_LORA_ENABLED
}
#endif
return mp_const_none;
Expand Down Expand Up @@ -521,7 +521,7 @@ STATIC mp_obj_t socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t addr_
uint8_t ip[MOD_USOCKET_IPV6_CHARS_MAX];
mp_uint_t port = 0;

#if defined (LOPY) || defined(LOPY4) || defined(FIPY)
#ifdef MOD_LORA_ENABLED
if (self->sock_base.nic_type == &mod_network_nic_type_lora) {
mp_obj_t *addr_items;
mp_obj_get_array_fixed_n(addr_in, 2, &addr_items);
Expand Down Expand Up @@ -579,7 +579,7 @@ STATIC mp_obj_t socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) {
vstr.buf[vstr.len] = '\0';
tuple[0] = mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
}
#if defined (LOPY) || defined(LOPY4) || defined(FIPY)
#ifdef MOD_LORA_ENABLED
// check if lora NIC and IP is not set (so Lora Raw or LoraWAN, but no Lora Mesh)
if (self->sock_base.nic_type == &mod_network_nic_type_lora) {
if (ip[0] == 0) {
Expand Down
22 changes: 6 additions & 16 deletions esp32/mptask.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,12 @@
#include "esp_log.h"
#include "mods/pybflash.h"

#if defined (LOPY) || defined (LOPY4) || defined (FIPY)
#ifdef MOD_LORA_ENABLED
#include "modlora.h"
#endif
#if defined (SIPY) || defined(LOPY4) || defined (FIPY)
#if defined (MOD_SIGFOX_ENABLED)
#ifdef MOD_SIGFOX_ENABLED
#include "sigfox/modsigfox.h"
#endif
#endif
#if defined (GPY) || defined (FIPY)
#include "modlte.h"
#endif
Expand Down Expand Up @@ -260,35 +258,27 @@ void TASK_Micropython (void *pvParameters) {
// Config Wifi as per Pycom config
mptask_config_wifi(false);
// these ones are special because they need uPy running and they launch tasks
#ifndef PYETH_ENABLED
// PyEth and LoRa module are both connected via SPI 3,
// so with PyEth enabled, we disable th LoRa module
#if defined(LOPY) || defined (LOPY4) || defined (FIPY)
#ifdef MOD_LORA_ENABLED
modlora_init0();
#endif
#if defined(SIPY) || defined(LOPY4) || defined (FIPY)
#if defined (MOD_SIGFOX_ENABLED)
#ifdef MOD_SIGFOX_ENABLED
modsigfox_init0();
#endif
#endif
#endif
}

// initialize the serial flash file system
mptask_init_sflash_filesystem();

#if defined(LOPY) || defined(SIPY) || defined (LOPY4) || defined(FIPY)
#if defined(MOD_LORA_ENABLED) || defined(MOD_SIGFOX_ENABLED)
// must be done after initializing the file system
mptask_update_lpwan_mac_address();
#endif

#if defined(SIPY) || defined(LOPY4) || defined(FIPY)
#if defined (MOD_SIGFOX_ENABLED)
#ifdef MOD_SIGFOX_ENABLED
sigfox_update_id();
sigfox_update_pac();
sigfox_update_private_key();
sigfox_update_public_key();
#endif
#endif

// append the flash paths to the system path
Expand Down