8000 lora buildflag and disable cleanly with pyeth · disquva/pycom-micropython-sigfox@6c52763 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6c52763

Browse files
committed
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
1 parent d4d65a5 commit 6c52763

File tree

6 files changed

+52
-31
lines changed

6 files changed

+52
-31
lines changed

esp32/Makefile

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,19 @@ PYGATE_ENABLED ?= 0
3232
# COAP is enabled by default
3333
MOD_COAP_ENABLED ?= 1
3434

35-
# SIGFOX is enabled by default. It will only be built for supported boards.
35+
# LORA is enabled by default for supported boards
36+
ifeq ($(BOARD), $(filter $(BOARD), LOPY LOPY4 FIPY))
37+
MOD_LORA_ENABLED ?= 1
38+
else
39+
MOD_LORA_ENABLED ?= 0
40+
endif
41+
42+
# SIGFOX is enabled by default for supported boards
10000 43+
ifeq ($(BOARD), $(filter $(BOARD), SIPY LOPY4 FIPY))
3644
MOD_SIGFOX_ENABLED ?= 1
45+
else
46+
MOD_SIGFOX_ENABLED ?= 0
47+
endif
3748

3849
# Pybytes disabled by default
3950
PYBYTES_ENABLED ?= 0
@@ -55,6 +66,7 @@ ifeq ($(VARIANT),PYGATE)
5566
endif
5667
PYBYTES_ENABLED=1
5768
PYETH_ENABLED=1
69+
MOD_LORA_ENABLED=0 # ETH and LORA are mutually exclusive
5870
PYGATE_ENABLED=1
5971
endif
6072

@@ -156,19 +168,21 @@ ifeq ($(MOD_COAP_ENABLED), 1)
156168
CFLAGS += -DMOD_COAP_ENABLED
157169
endif
158170

171+
ifeq ($(MOD_LORA_ENABLED), 1)
172+
$(info LORA Module Enabled)
173+
CFLAGS += -DMOD_LORA_ENABLED
174+
endif
175+
159176
ifeq ($(DIFF_UPDATE_ENABLED), 1)
160177
$(info Differential Update Enabled)
161178
CFLAGS += -DDIFF_UPDATE_ENABLED -DBZ_NO_STDIO
162179
endif
163180

164181
ifeq ($(MOD_SIGFOX_ENABLED), 1)
165182
$(info SIGFOX Module Enabled)
166-
167-
ifeq ($(BOARD), $(filter $(BOARD), SIPY LOPY4 FIPY))
168-
CFLAGS += -DMOD_SIGFOX_ENABLED
169-
LIBS += sigfox/modsigfox_$(BOARD).a -lsigfox
170-
$(BUILD)/application.elf: sigfox/modsigfox_$(BOARD).a
171-
endif
183+
CFLAGS += -DMOD_SIGFOX_ENABLED
184+
LIBS += sigfox/modsigfox_$(BOARD).a -lsigfox
185+
$(BUILD)/application.elf: sigfox/modsigfox_$(BOARD).a
172186
endif
173187

174188
ifeq ($(OPENTHREAD), on)

esp32/application.mk

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,13 +388,30 @@ BOOT_SRC_C = $(addprefix bootloader/,\
388388
SFX_OBJ =
389389

390390
OBJ = $(PY_O)
391+
ifeq ($(MOD_LORA_ENABLED), 1)
392+
393+
ifeq ($(BOARD), $(filter $(BOARD), LOPY FIPY))
394+
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))
395+
endif
396+
397+
ifeq ($(BOARD), $(filter $(BOARD), LOPY4))
398+
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))
399+
endif
400+
401+
endif
402+
403+
ifeq ($(MOD_SIGFOX_ENABLED), 1)
404+
391405
ifeq ($(BOARD), $(filter $(BOARD), LOPY FIPY))
392406
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))
393407
endif
408+
394409
ifeq ($(BOARD), $(filter $(BOARD), LOPY4))
395410
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))
396411
endif
397412

413+
endif
414+
398415
ifeq ($(MOD_SIGFOX_ENABLED), 1)
399416
ifeq ($(BOARD), $(filter $(BOARD), SIPY))
400417
OBJ += $(addprefix $(BUILD)/, $(APP_SIGFOX_MOD_SRC_C:.c=.o))

esp32/mods/modmachine.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ STATIC mp_obj_t machine_sleep (uint n_args, const mp_obj_t *arg) {
410410
}
411411
#endif
412412

413-
#if defined(LOPY) || defined(LOPY4) || defined(FIPY)
413+
#ifdef MOD_LORA_ENABLED
414414
/* Send LoRa module to Sleep Mode */
415415
modlora_sleep_module();
416416
while(!modlora_is_module_sleep())

esp32/mods/modnetwork.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,11 @@ mp_obj_t mod_network_find_nic(const mod_network_socket_obj_t *s, const uint8_t *
112112
mp_obj_t nic = MP_STATE_PORT(mod_network_nic_list).items[i];
113113
// we want a raw network card
114114
if (ip == NULL) {
115-
#if defined (LOPY) || defined(LOPY4) || defined (FIPY)
115+
#ifdef MOD_LORA_ENABLED
116116
if (mp_obj_get_type(nic) == (mp_obj_type_t *)&mod_network_nic_type_lora && s->sock_base.u.u_param.domain == AF_LORA) {
117117
return nic;
118118
}
119-
#endif
119+
#endif
120120
#if defined (SIPY) || defined (LOPY4) || defined (FIPY)
121121
#if defined (MOD_SIGFOX_ENABLED)
122122
if (mp_obj_get_type(nic) == (mp_obj_type_t *)&mod_network_nic_type_sigfox && s->sock_base.u.u_param.domain == AF_SIGFOX) {
@@ -371,7 +371,7 @@ STATIC const mp_map_elem_t mp_module_network_globals_table[] = {
371371
#ifdef PYETH_ENABLED
372372
{ MP_OBJ_NEW_QSTR(MP_QSTR_ETH), (mp_obj_t)&mod_network_nic_type_eth },
373373
#endif
374-
#if defined (LOPY) || defined(LOPY4) || defined (FIPY)
374+
#ifdef MOD_LORA_ENABLED
375375
{ MP_OBJ_NEW_QSTR(MP_QSTR_LoRa), (mp_obj_t)&mod_network_nic_type_lora },
376376
#endif
377377
#if defined (SIPY) || defined (LOPY4) || defined (FIPY)

esp32/mods/modusocket.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ STATIC mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) {
272272
mod_network_socket_obj_t *self = self_in;
273273
int _errno;
274274

275-
#if defined (LOPY) || defined(LOPY4) || defined(FIPY)
275+
#ifdef MOD_LORA_ENABLED
276276
if (self->sock_base.nic_type == &mod_network_nic_type_lora) {
277277
if (MP_OBJ_IS_INT(addr_in)) {
278278
mp_uint_t port = mp_obj_get_int(addr_in);
@@ -301,7 +301,7 @@ STATIC mp_obj_t socket_bind(mp_obj_t self_in, mp_obj_t addr_in) {
301301
if (self->sock_base.nic_type->n_bind(self, ip, port, &_errno) != 0) {
302302
nlr_raise(mp_obj_new_exception_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(_errno)));
303303
}
304-
#if defined (LOPY) || defined(LOPY4) || defined(FIPY)
304+
#ifdef MOD_LORA_ENABLED
305305
}
306306
#endif
307307
return mp_const_none;
@@ -521,7 +521,7 @@ STATIC mp_obj_t socket_sendto(mp_obj_t self_in, mp_obj_t data_in, mp_obj_t addr_
521521
uint8_t ip[MOD_USOCKET_IPV6_CHARS_MAX];
522522
mp_uint_t port = 0;
523523

524-
#if defined (LOPY) || defined(LOPY4) || defined(FIPY)
524+
#ifdef MOD_LORA_ENABLED
525525
if (self->sock_base.nic_type == &mod_network_nic_type_lora) {
526526
mp_obj_t *addr_items;
527527
mp_obj_get_array_fixed_n(addr_in, 2, &addr_items);
@@ -579,7 +579,7 @@ STATIC mp_obj_t socket_recvfrom(mp_obj_t self_in, mp_obj_t len_in) {
579579
vstr.buf[vstr.len] = '\0';
580580
tuple[0] = mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
581581
}
582-
#if defined (LOPY) || defined(LOPY4) || defined(FIPY)
582+
#ifdef MOD_LORA_ENABLED
583583
// check if lora NIC and IP is not set (so Lora Raw or LoraWAN, but no Lora Mesh)
584584
if (self->sock_base.nic_type == &mod_network_nic_type_lora) {
585585
if (ip[0] == 0) {

esp32/mptask.c

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,12 @@
5252
#include "esp_log.h"
5353
#include "mods/pybflash.h"
5454

55-
#if defined (LOPY) || defined (LOPY4) || defined (FIPY)
55+
#ifdef MOD_LORA_ENABLED
5656
#include "modlora.h"
5757
#endif
58-
#if defined (SIPY) || defined(LOPY4) || defined (FIPY)
59-
#if defined (MOD_SIGFOX_ENABLED)
58+
#ifdef MOD_SIGFOX_ENABLED
6059
#include "sigfox/modsigfox.h"
6160
#endif
62-
#endif
6361
#if defined (GPY) || defined (FIPY)
6462
#include "modlte.h"
6563
#endif
@@ -260,35 +258,27 @@ void TASK_Micropython (void *pvParameters) {
260258
// Config Wifi as per Pycom config
261259
mptask_config_wifi(false);
262260
// these ones are special because they need uPy running and they launch tasks
263-
#ifndef PYETH_ENABLED
264-
// PyEth and LoRa module are both connected via SPI 3,
265-
// so with PyEth enabled, we disable th LoRa module
266-
#if defined(LOPY) || defined (LOPY4) || defined (FIPY)
261+
#ifdef MOD_LORA_ENABLED
267262
modlora_init0();
268263
#endif
269-
#if defined(SIPY) || defined(LOPY4) || defined (FIPY)
270-
#if defined (MOD_SIGFOX_ENABLED)
264+
#ifdef MOD_SIGFOX_ENABLED
271265
modsigfox_init0();
272-
#endif
273-
#endif
274266
#endif
275267
}
276268

277269
// initialize the serial flash file system
278270
mptask_init_sflash_filesystem();
279271

280-
#if defined(LOPY) || defined(SIPY) || defined (LOPY4) || defined(FIPY)
272+
#if defined(MOD_LORA_ENABLED) || defined(MOD_SIGFOX_ENABLED)
281273
// must be done after initializing the file system
282274
mptask_update_lpwan_mac_address();
283275
#endif
284276

285-
#if defined(SIPY) || defined(LOPY4) || defined(FIPY)
286-
#if defined (MOD_SIGFOX_ENABLED)
277+
#ifdef MOD_SIGFOX_ENABLED
287278
sigfox_update_id();
288279
sigfox_update_pac();
289280
sigfox_update_private_key();
290281
sigfox_update_public_key();
291-
#endif
292282
#endif
293283

294284
// append the flash paths to the system path

0 commit comments

Comments
 (0)
0