From 94865e581dc967e91d51a279f3b8f888589fd7a7 Mon Sep 17 00:00:00 2001 From: gijsio <67470426+gijsio@users.noreply.github.com> Date: Fri, 27 Nov 2020 16:35:59 +0100 Subject: [PATCH 1/9] added micropython constant for manual antenna selection --- esp32/mods/modbt.c | 1 + esp32/mods/modwlan.c | 1 + 2 files changed, 2 insertions(+) diff --git a/esp32/mods/modbt.c b/esp32/mods/modbt.c index 99a79a6570..8b8ae40d1d 100644 --- a/esp32/mods/modbt.c +++ b/esp32/mods/modbt.c @@ -2268,6 +2268,7 @@ STATIC const mp_map_elem_t bt_locals_dict_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_CHAR_SUBSCRIBE_EVENT), MP_OBJ_NEW_SMALL_INT(MOD_BT_GATTS_SUBSCRIBE_EVT) }, // { MP_OBJ_NEW_QSTR(MP_QSTR_CHAR_INDICATE_EVENT), MP_OBJ_NEW_SMALL_INT(MOD_BT_GATTC_INDICATE_EVT) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_MAN_ANT), MP_OBJ_NEW_SMALL_INT(ANTENNA_TYPE_MANUAL) }, { MP_OBJ_NEW_QSTR(MP_QSTR_INT_ANT), MP_OBJ_NEW_SMALL_INT(ANTENNA_TYPE_INTERNAL) }, { MP_OBJ_NEW_QSTR(MP_QSTR_EXT_ANT), MP_OBJ_NEW_SMALL_INT(ANTENNA_TYPE_EXTERNAL) }, diff --git a/esp32/mods/modwlan.c b/esp32/mods/modwlan.c index 81efbd1818..55d5b793ea 100644 --- a/esp32/mods/modwlan.c +++ b/esp32/mods/modwlan.c @@ -2735,6 +2735,7 @@ STATIC const mp_map_elem_t wlan_locals_dict_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_WPA2_ENT), MP_OBJ_NEW_SMALL_INT(WIFI_AUTH_WPA2_ENTERPRISE) }, { MP_OBJ_NEW_QSTR(MP_QSTR_INT_ANT), MP_OBJ_NEW_SMALL_INT(ANTENNA_TYPE_INTERNAL) }, { MP_OBJ_NEW_QSTR(MP_QSTR_EXT_ANT), MP_OBJ_NEW_SMALL_INT(ANTENNA_TYPE_EXTERNAL) }, + { MP_OBJ_NEW_QSTR(MP_QSTR_MAN_ANT), MP_OBJ_NEW_SMALL_INT(ANTENNA_TYPE_MANUAL) }, { MP_OBJ_NEW_QSTR(MP_QSTR_HT20), MP_OBJ_NEW_SMALL_INT(WIFI_BW_HT20) }, { MP_OBJ_NEW_QSTR(MP_QSTR_HT40), MP_OBJ_NEW_SMALL_INT(WIFI_BW_HT40) }, { MP_OBJ_NEW_QSTR(MP_QSTR_PHY_11_B), MP_OBJ_NEW_SMALL_INT(WLAN_PHY_11_B) }, From 358085bda144a97d48a9dd6deccb2fe6eb3a91b7 Mon Sep 17 00:00:00 2001 From: Peter Putz Date: Thu, 22 Oct 2020 10:49:14 +0200 Subject: [PATCH 2/9] lte: fix core dump during machine.deepsleep() since 26adae2 it is possible that the lte task is not running. with this commit we can safely check the status, notably from modmachine.c machine_deepsleep() --- esp32/lte/lteppp.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/esp32/lte/lteppp.c b/esp32/lte/lteppp.c index ad7f70c28b..36deadbf9b 100644 --- a/esp32/lte/lteppp.c +++ b/esp32/lte/lteppp.c @@ -214,6 +214,10 @@ char* lteppp_get_log_buff(void) lte_modem_conn_state_t lteppp_modem_state(void) { lte_modem_conn_state_t state; + if (!xLTESem){ + // lte task hasn't been initialized yet, so we don't need to (and can't) protect this read + return lteppp_modem_conn_state; + } xSemaphoreTake(xLTESem, portMAX_DELAY); state = lteppp_modem_conn_state; xSemaphoreGive(xLTESem); @@ -382,6 +386,10 @@ bool lteppp_wait_at_rsp (const char *expected_rsp, uint32_t timeout, bool from_m lte_state_t lteppp_get_state(void) { lte_state_t state; + if (!xLTESem){ + // lte task hasn't been initialized yet, so we don't need to (and can't) protect this read + return lteppp_lte_state; + } xSemaphoreTake(xLTESem, portMAX_DELAY); state = lteppp_lte_state; xSemaphoreGive(xLTESem); From d4d65a5fa759b8ae139b5ce6fa659253c30796a6 Mon Sep 17 00:00:00 2001 From: Peter Putz Date: Mon, 21 Dec 2020 11:50:13 +0100 Subject: [PATCH 3/9] build: cleanup sigfox flags --- esp32/mods/moduos.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/esp32/mods/moduos.c b/esp32/mods/moduos.c index d928eaa37d..cb1b548e49 100644 --- a/esp32/mods/moduos.c +++ b/esp32/mods/moduos.c @@ -81,7 +81,7 @@ STATIC const qstr os_uname_info_fields[] = { #if defined(LOPY) || defined(LOPY4) || defined(FIPY) ,MP_QSTR_lorawan #endif -#if defined(SIPY) || defined(FIPY) || defined(LOPY4) +#ifdef MOD_SIGFOX_ENABLED ,MP_QSTR_sigfox #endif #if (VARIANT == PYBYTES) @@ -100,7 +100,7 @@ STATIC const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME #if defined(LOPY) || defined(LOPY4) || defined(FIPY) STATIC const MP_DEFINE_STR_OBJ(os_uname_info_lorawan_obj, LORAWAN_VERSION_NUMBER); #endif -#if defined(SIPY) || defined (LOPY4) || defined (FIPY) +#ifdef MOD_SIGFOX_ENABLED STATIC const MP_DEFINE_STR_OBJ(os_uname_info_sigfox_obj, SIGFOX_VERSION_NUMBER); #endif #if (VARIANT == PYBYTES) @@ -117,7 +117,7 @@ STATIC MP_DEFINE_ATTRTUPLE( #if defined(LOPY) || defined(LOPY4) || defined(FIPY) +1 #endif -#if defined(SIPY) || defined (LOPY4) || defined(FIPY) +#ifdef MOD_SIGFOX_ENABLED +1 #endif #if (VARIANT == PYBYTES) @@ -134,7 +134,7 @@ STATIC MP_DEFINE_ATTRTUPLE( #if defined(LOPY) || defined(LOPY4) || defined(FIPY) ,(mp_obj_t)&os_uname_info_lorawan_obj #endif -#if defined(SIPY) || defined (LOPY4) || defined(FIPY) +#ifdef MOD_SIGFOX_ENABLED ,(mp_obj_t)&os_uname_info_sigfox_obj #endif #if (VARIANT == PYBYTES) From 6c52763b1c30369173bc4769413e57b7cb9de15e Mon Sep 17 00:00:00 2001 From: Peter Putz Date: Mon, 21 Dec 2020 16:13:50 +0100 Subject: [PATCH 4/9] 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 --- esp32/Makefile | 28 +++++++++++++++++++++------- esp32/application.mk | 17 +++++++++++++++++ esp32/mods/modmachine.c | 2 +- esp32/mods/modnetwork.c | 6 +++--- esp32/mods/modusocket.c | 8 ++++---- esp32/mptask.c | 22 ++++++---------------- 6 files changed, 52 insertions(+), 31 deletions(-) diff --git a/esp32/Makefile b/esp32/Makefile index 10ca433cca..160ef46a5c 100644 --- a/esp32/Makefile +++ b/esp32/Makefile @@ -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 @@ -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 @@ -156,6 +168,11 @@ 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 @@ -163,12 +180,9 @@ 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) diff --git a/esp32/application.mk b/esp32/application.mk index 7fdd0c8256..2efb385f35 100644 --- a/esp32/application.mk +++ b/esp32/application.mk @@ -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)) diff --git a/esp32/mods/modmachine.c b/esp32/mods/modmachine.c index b5d07bfd3c..35aa69bfa6 100644 --- a/esp32/mods/modmachine.c +++ b/esp32/mods/modmachine.c @@ -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()) diff --git a/esp32/mods/modnetwork.c b/esp32/mods/modnetwork.c index ae96e8375e..26e52323b3 100644 --- a/esp32/mods/modnetwork.c +++ b/esp32/mods/modnetwork.c @@ -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) { @@ -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) diff --git a/esp32/mods/modusocket.c b/esp32/mods/modusocket.c index afb5daaee2..cd660932b2 100644 --- a/esp32/mods/modusocket.c +++ b/esp32/mods/modusocket.c @@ -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); @@ -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; @@ -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); @@ -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) { diff --git a/esp32/mptask.c b/esp32/mptask.c index 1e792db0d9..e5e89919d7 100644 --- a/esp32/mptask.c +++ b/esp32/mptask.c @@ -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 @@ -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 From e5a00fe43a3a486321da4aeebd74d7c329ccc090 Mon Sep 17 00:00:00 2001 From: Peter Putz Date: Fri, 28 Aug 2020 19:43:47 +0200 Subject: [PATCH 5/9] lte: refactor lteppp_get_modem_conn_state() no functional change, but make the code a little more readable by pulling the semaphore and edits into a function and use more intuitive fct names --- esp32/lte/lteppp.c | 39 ++++++++++++++++----------------------- esp32/lte/lteppp.h | 3 ++- esp32/mods/modlte.c | 6 +++--- esp32/mods/modmachine.c | 4 ++-- 4 files changed, 23 insertions(+), 29 deletions(-) diff --git a/esp32/lte/lteppp.c b/esp32/lte/lteppp.c index 36deadbf9b..2b0b2c30d3 100644 --- a/esp32/lte/lteppp.c +++ b/esp32/lte/lteppp.c @@ -174,7 +174,7 @@ void lteppp_init(void) { lteppp_pcb = pppapi_pppos_create(<eppp_netif, lteppp_output_callback, lteppp_status_cb, NULL); //wait on connecting modem until it is allowed - lteppp_modem_conn_state = E_LTE_MODEM_DISCONNECTED; + lteppp_set_modem_conn_state(E_LTE_MODEM_DISCONNECTED); xTaskCreatePinnedToCore(TASK_LTE, "LTE", LTE_TASK_STACK_SIZE / sizeof(StackType_t), NULL, LTE_TASK_PRIORITY, &xLTETaskHndl, 1); @@ -211,7 +211,7 @@ char* lteppp_get_log_buff(void) } #endif -lte_modem_conn_state_t lteppp_modem_state(void) +lte_modem_conn_state_t lteppp_get_modem_conn_state(void) { lte_modem_conn_state_t state; if (!xLTESem){ @@ -224,6 +224,13 @@ lte_modem_conn_state_t lteppp_modem_state(void) return state; } +void lteppp_set_modem_conn_state(lte_modem_conn_state_t state) +{ + xSemaphoreTake(xLTESem, portMAX_DELAY); + lteppp_modem_conn_state = state; + xSemaphoreGive(xLTESem); +} + void lteppp_set_state(lte_state_t state) { xSemaphoreTake(xLTESem, portMAX_DELAY); lteppp_lte_state = state; @@ -455,9 +462,7 @@ static void TASK_LTE (void *pvParameters) { { MSG("notif\n"); xSemaphoreTake(xLTE_modem_Conn_Sem, portMAX_DELAY); - xSemaphoreTake(xLTESem, portMAX_DELAY); - lteppp_modem_conn_state = E_LTE_MODEM_CONNECTING; - xSemaphoreGive(xLTESem); + lteppp_set_modem_conn_state(E_LTE_MODEM_CONNECTING); uart_set_rts(LTE_UART_ID, true); vTaskDelay(500/portTICK_PERIOD_MS); uart_set_hw_flow_ctrl(LTE_UART_ID, UART_HW_FLOWCTRL_CTS_RTS, 64); @@ -471,9 +476,7 @@ static void TASK_LTE (void *pvParameters) { if (at_trials >= LTE_AT_CMD_TRIALS) { uart_set_hw_flow_ctrl(LTE_UART_ID, UART_HW_FLOWCTRL_DISABLE, 0); uart_set_rts(LTE_UART_ID, false); - xSemaphoreTake(xLTESem, portMAX_DELAY); - lteppp_modem_conn_state = E_LTE_MODEM_DISCONNECTED; - xSemaphoreGive(xLTESem); + lteppp_set_modem_conn_state(E_LTE_MODEM_DISCONNECTED); xSemaphoreGive(xLTE_modem_Conn_Sem); at_trials = 0; goto modem_init; @@ -494,9 +497,7 @@ static void TASK_LTE (void *pvParameters) { if (at_trials >= LTE_AT_CMD_TRIALS) { uart_set_hw_flow_ctrl(LTE_UART_ID, UART_HW_FLOWCTRL_DISABLE, 0); uart_set_rts(LTE_UART_ID, false); - xSemaphoreTake(xLTESem, portMAX_DELAY); - lteppp_modem_conn_state = E_LTE_MODEM_DISCONNECTED; - xSemaphoreGive(xLTESem); + lteppp_set_modem_conn_state(E_LTE_MODEM_DISCONNECTED); xSemaphoreGive(xLTE_modem_Conn_Sem); at_trials = 0; goto modem_init; @@ -511,9 +512,7 @@ static void TASK_LTE (void *pvParameters) { if (at_trials >= LTE_AT_CMD_TRIALS) { uart_set_hw_flow_ctrl(LTE_UART_ID, UART_HW_FLOWCTRL_DISABLE, 0); uart_set_rts(LTE_UART_ID, false); - xSemaphoreTake(xLTESem, portMAX_DELAY); - lteppp_modem_conn_state = E_LTE_MODEM_DISCONNECTED; - xSemaphoreGive(xLTESem); + lteppp_set_modem_conn_state(E_LTE_MODEM_DISCONNECTED); xSemaphoreGive(xLTE_modem_Conn_Sem); at_trials = 0; goto modem_init; @@ -555,22 +554,16 @@ static void TASK_LTE (void *pvParameters) { { lteppp_send_at_cmd("AT+SQNIBRCFG=1,100", LTE_RX_TIMEOUT_MAX_MS); } - xSemaphoreTake(xLTESem, portMAX_DELAY); - lteppp_modem_conn_state = E_LTE_MODEM_CONNECTED; - xSemaphoreGive(xLTESem); + lteppp_set_modem_conn_state(E_LTE_MODEM_CONNECTED); xSemaphoreGive(xLTE_modem_Conn_Sem); MSG("forever\n"); lte_state_t state; for (;;) { vTaskDelay(LTE_TASK_PERIOD_MS); - xSemaphoreTake(xLTESem, portMAX_DELAY); - if(E_LTE_MODEM_DISCONNECTED == lteppp_modem_conn_state) - { - xSemaphoreGive(xLTESem); + if(lteppp_get_modem_conn_state() == E_LTE_MODEM_DISCONNECTED ){ // restart the task goto modem_init; } - xSemaphoreGive(xLTESem); state = lteppp_get_state(); if (xQueueReceive(xCmdQueue, lteppp_trx_buffer, 0)) { MSG("cmd\n"); @@ -868,7 +861,7 @@ static void lteppp_print_states(){ if (!xLTESem) return; static lte_modem_conn_state_t last_c = 0xff; - lte_modem_conn_state_t c = lteppp_modem_state(); + lte_modem_conn_state_t c = lteppp_get_modem_conn_state(); static lte_state_t last_s = 0xff; lte_state_t s = lteppp_get_state(); static bool last_u = false; diff --git a/esp32/lte/lteppp.h b/esp32/lte/lteppp.h index 8ca52c5d7b..289761b8c2 100644 --- a/esp32/lte/lteppp.h +++ b/esp32/lte/lteppp.h @@ -119,7 +119,8 @@ extern void lteppp_send_at_command (lte_task_cmd_data_t *cmd, lte_task_rsp_data_ extern bool lteppp_wait_at_rsp (const char *expected_rsp, uint32_t timeout, bool from_mp, void* data_rem); -lte_modem_conn_state_t lteppp_modem_state(void); +lte_modem_conn_state_t lteppp_get_modem_conn_state(void); +void lteppp_set_modem_conn_state(lte_modem_conn_state_t state); extern void connect_lte_uart (void); diff --git a/esp32/mods/modlte.c b/esp32/mods/modlte.c index 1372c679c8..ec6aabe8f1 100644 --- a/esp32/mods/modlte.c +++ b/esp32/mods/modlte.c @@ -454,7 +454,7 @@ static mp_obj_t lte_init_helper(lte_obj_t *self, const mp_arg_val_t *args) { //printf("All done since we were already initialised.\n"); return mp_const_none; } - modem_state = lteppp_modem_state(); + modem_state = lteppp_get_modem_conn_state(); switch(modem_state) { case E_LTE_MODEM_DISCONNECTED: @@ -463,7 +463,7 @@ static mp_obj_t lte_init_helper(lte_obj_t *self, const mp_arg_val_t *args) { MP_THREAD_GIL_EXIT(); xSemaphoreTake(xLTE_modem_Conn_Sem, portMAX_DELAY); MP_THREAD_GIL_ENTER(); - if (E_LTE_MODEM_DISCONNECTED == lteppp_modem_state()) { + if (E_LTE_MODEM_DISCONNECTED == lteppp_get_modem_conn_state()) { xSemaphoreGive(xLTE_modem_Conn_Sem); nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Couldn't connect to Modem (modem_state=disconnected)")); } @@ -471,7 +471,7 @@ static mp_obj_t lte_init_helper(lte_obj_t *self, const mp_arg_val_t *args) { case E_LTE_MODEM_CONNECTING: // Block till modem is connected xSemaphoreTake(xLTE_modem_Conn_Sem, portMAX_DELAY); - if (E_LTE_MODEM_DISCONNECTED == lteppp_modem_state()) { + if (E_LTE_MODEM_DISCONNECTED == lteppp_get_modem_conn_state()) { xSemaphoreGive(xLTE_modem_Conn_Sem); nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Couldn't connect to Modem (modem_state=connecting)")); } diff --git a/esp32/mods/modmachine.c b/esp32/mods/modmachine.c index 35aa69bfa6..28f4f4b9e0 100644 --- a/esp32/mods/modmachine.c +++ b/esp32/mods/modmachine.c @@ -405,7 +405,7 @@ STATIC mp_obj_t machine_sleep (uint n_args, const mp_obj_t *arg) { bool reconnect = false; #if defined(FIPY) || defined(GPY) - if (lteppp_modem_state() < E_LTE_MODEM_DISCONNECTED) { + if (lteppp_get_modem_conn_state() < E_LTE_MODEM_DISCONNECTED) { lteppp_deinit(); } #endif @@ -466,7 +466,7 @@ STATIC mp_obj_t machine_deepsleep (uint n_args, const mp_obj_t *arg) { modbt_deinit(false); wlan_deinit(NULL); #if defined(FIPY) || defined(GPY) - if (lteppp_modem_state() < E_LTE_MODEM_DISCONNECTED) { + if (lteppp_get_modem_conn_state() < E_LTE_MODEM_DISCONNECTED) { lteppp_deinit(); } #endif From 4f07373df9a9994a757475ab08c6cd773a7e3e61 Mon Sep 17 00:00:00 2001 From: Peter Putz Date: Fri, 28 Aug 2020 19:44:52 +0200 Subject: [PATCH 6/9] lte: detect modem in ffh/recovery mode when the LTE modem is in 'FFH' mode or in 'RECOVERY' mode, we can't use normal LTE functionality the modem is normally brought into this state if a user starts a modem firmware update, but it is not completed successfully the next logical step is to perform/finish the upgrade FFH and RECOVERY are using 115200 baud. normal "FFF" modem firmware mode uses 921600. So, when we do not get a response at 921600, but we do get a response at 115200, we advise the user to perform upgrade --- esp32/lte/lteppp.c | 38 ++++++++++++++++++++++++++++++++++++-- esp32/lte/lteppp.h | 3 ++- esp32/mods/modlte.c | 13 ++++++++++--- 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/esp32/lte/lteppp.c b/esp32/lte/lteppp.c index 2b0b2c30d3..01035c1d74 100644 --- a/esp32/lte/lteppp.c +++ b/esp32/lte/lteppp.c @@ -444,6 +444,35 @@ void lteppp_resume(void) { /****************************************************************************** DEFINE PRIVATE FUNCTIONS ******************************************************************************/ +bool trx_is_ok_or_error(){ + if (strstr(lteppp_trx_buffer, "ERROR\r\n") != NULL){ + // printf("ok\n"); + return true; + } else if (strstr(lteppp_trx_buffer, "OK\r\n") != NULL) { + // printf("error\n"); + return true; + } + return false; +} + +/** check whether modem is responding at 115200 + * this means it is in FFH or RECOVYER mode + */ +bool lteppp_check_ffh_mode(){ + uart_set_baudrate(LTE_UART_ID, 115200); + uart_set_hw_flow_ctrl(LTE_UART_ID, UART_HW_FLOWCTRL_CTS_RTS, 64); + uart_set_rts(LTE_UART_ID, true); + + for ( uint8_t attempt = 0 ; attempt < 3 ; attempt++ ){ + lteppp_send_at_cmd("AT", LTE_PPP_BACK_OFF_TIME_MS); + if ( trx_is_ok_or_error() ){ + // we could check for AT+SMOD / AT+BMOD to get more details + return true; + } + } + return false; +} + static void TASK_LTE (void *pvParameters) { MSG("\n"); bool sim_present; @@ -510,9 +539,14 @@ static void TASK_LTE (void *pvParameters) { while(!lteppp_send_at_cmd("AT", LTE_RX_TIMEOUT_MIN_MS)) { if (at_trials >= LTE_AT_CMD_TRIALS) { - uart_set_hw_flow_ctrl(LTE_UART_ID, UART_HW_FLOWCTRL_DISABLE, 0); - uart_set_rts(LTE_UART_ID, false); + if ( lteppp_check_ffh_mode() ){ + lteppp_set_modem_conn_state(E_LTE_MODEM_RECOVERY); + } else { + uart_set_baudrate(LTE_UART_ID, MICROPY_LTE_UART_BAUDRATE); + uart_set_hw_flow_ctrl(LTE_UART_ID, UART_HW_FLOWCTRL_DISABLE, 0); + uart_set_rts(LTE_UART_ID, false); lteppp_set_modem_conn_state(E_LTE_MODEM_DISCONNECTED); + } xSemaphoreGive(xLTE_modem_Conn_Sem); at_trials = 0; goto modem_init; diff --git a/esp32/lte/lteppp.h b/esp32/lte/lteppp.h index 289761b8c2..64b260e80e 100644 --- a/esp32/lte/lteppp.h +++ b/esp32/lte/lteppp.h @@ -61,7 +61,8 @@ typedef enum { typedef enum { E_LTE_MODEM_CONNECTED = 0, E_LTE_MODEM_CONNECTING, - E_LTE_MODEM_DISCONNECTED + E_LTE_MODEM_DISCONNECTED, + E_LTE_MODEM_RECOVERY } lte_modem_conn_state_t; #ifdef LTE_DEBUG_BUFF diff --git a/esp32/mods/modlte.c b/esp32/mods/modlte.c index ec6aabe8f1..b823883ef9 100644 --- a/esp32/mods/modlte.c +++ b/esp32/mods/modlte.c @@ -463,9 +463,13 @@ static mp_obj_t lte_init_helper(lte_obj_t *self, const mp_arg_val_t *args) { MP_THREAD_GIL_EXIT(); xSemaphoreTake(xLTE_modem_Conn_Sem, portMAX_DELAY); MP_THREAD_GIL_ENTER(); - if (E_LTE_MODEM_DISCONNECTED == lteppp_get_modem_conn_state()) { + lte_modem_conn_state_t modem_state = lteppp_get_modem_conn_state(); + if (E_LTE_MODEM_DISCONNECTED == modem_state) { + xSemaphoreGive(xLTE_modem_Conn_Sem); + nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Couldn't start connection to Modem (modem_state=disconnected)")); + } else if (E_LTE_MODEM_RECOVERY == modem_state){ xSemaphoreGive(xLTE_modem_Conn_Sem); - nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Couldn't connect to Modem (modem_state=disconnected)")); + nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Couldn't start connection to Modem (modem_state=recovery). Perform a modem firmware update.")); } break; case E_LTE_MODEM_CONNECTING: @@ -479,8 +483,11 @@ static mp_obj_t lte_init_helper(lte_obj_t *self, const mp_arg_val_t *args) { case E_LTE_MODEM_CONNECTED: //continue break; + case E_LTE_MODEM_RECOVERY: + nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Couldn't connect to Modem (modem_state=recovery). Perform a modem firmware update.")); + break; default: - nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Couldn't connect to Modem (modem_state=default)")); + nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Couldn't connect to Modem (modem_state - default)")); break; } lte_obj.cid = args[1].u_int; From 1cde92a684c3c3a95e6602096858f6fd87c0a229 Mon Sep 17 00:00:00 2001 From: gijsio <67470426+gijsio@users.noreply.github.com> Date: Fri, 4 Sep 2020 11:45:56 +0200 Subject: [PATCH 7/9] make pycom.rgbled() return the current color value --- esp32/mods/modpycom.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/esp32/mods/modpycom.c b/esp32/mods/modpycom.c index 44551e1e08..a4007622f0 100644 --- a/esp32/mods/modpycom.c +++ b/esp32/mods/modpycom.c @@ -156,22 +156,25 @@ STATIC mp_obj_t mod_pycom_heartbeat (mp_uint_t n_args, const mp_obj_t *args) { } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_pycom_heartbeat_obj, 0, 1, mod_pycom_heartbeat); -STATIC mp_obj_t mod_pycom_rgb_led (mp_obj_t o_color) { +STATIC mp_obj_t mod_pycom_rgb_led (mp_uint_t n_args, const mp_obj_t *args) { #ifndef RGB_LED_DISABLE if (mperror_is_heartbeat_enabled()) { nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, mpexception_os_request_not_possible)); } - - uint32_t color = mp_obj_get_int(o_color); - led_info.color.value = color; - led_set_color(&led_info, true, false); + if(n_args > 0){ + uint32_t color = mp_obj_get_int(args[0]); + led_info.color.value = color; + led_set_color(&led_info, true, false); + } else { + return mp_obj_new_int(led_info.color.value); + } #else nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "RGB Led Interface Disabled")); #endif return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_pycom_rgb_led_obj, mod_pycom_rgb_led); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_pycom_rgb_led_obj, 0,1,mod_pycom_rgb_led); STATIC mp_obj_t mod_pycom_ota_start (void) { if (!updater_start()) { From 07294854ac4b47d2af624bc868967bbbfcddf533 Mon Sep 17 00:00:00 2001 From: Roberto Colistete Jr Date: Thu, 6 Aug 2020 02:36:31 -0300 Subject: [PATCH 8/9] User C modules : enable in Makefile and application.mk --- esp32/Makefile | 1 + esp32/application.mk | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/esp32/Makefile b/esp32/Makefile index 160ef46a5c..5826d20992 100644 --- a/esp32/Makefile +++ b/esp32/Makefile @@ -133,6 +133,7 @@ CFLAGS_XTENSA_OPT = -Os CFLAGS_XTENSA_PSRAM = -mfix-esp32-psram-cache-issue CFLAGS = $(CFLAGS_XTENSA) $(CFLAGS_XTENSA_PSRAM) $(CFLAGS_XTENSA_OPT) -nostdlib -std=gnu99 -g3 -ggdb -fstrict-volatile-bitfields -Iboards/$(BOARD) +CFLAGS += $(CFLAGS_MOD) $(CFLAGS_EXTRA) CFLAGS_SIGFOX = $(CFLAGS_XTENSA) -O2 -nostdlib -std=gnu99 -g3 -ggdb -fstrict-volatile-bitfields -Iboards/$(BOARD) # Configure floating point support diff --git a/esp32/application.mk b/esp32/application.mk index 2efb385f35..299e96f87b 100644 --- a/esp32/application.mk +++ b/esp32/application.mk @@ -433,7 +433,7 @@ endif endif # ifeq ($(OPENTHREAD), on) OBJ += $(addprefix $(BUILD)/, $(APP_MAIN_SRC_C:.c=.o) $(APP_HAL_SRC_C:.c=.o) $(APP_LIB_SRC_C:.c=.o)) -OBJ += $(addprefix $(BUILD)/, $(APP_MODS_SRC_C:.c=.o) $(APP_STM_SRC_C:.c=.o)) +OBJ += $(addprefix $(BUILD)/, $(APP_MODS_SRC_C:.c=.o) $(APP_STM_SRC_C:.c=.o) $(SRC_MOD:.c=.o)) OBJ += $(addprefix $(BUILD)/, $(APP_FATFS_SRC_C:.c=.o) $(APP_LITTLEFS_SRC_C:.c=.o) $(APP_UTIL_SRC_C:.c=.o) $(APP_TELNET_SRC_C:.c=.o)) OBJ += $(addprefix $(BUILD)/, $(APP_FTP_SRC_C:.c=.o) $(APP_CAN_SRC_C:.c=.o)) ifeq ($(PYGATE_ENABLED), 1) @@ -453,7 +453,7 @@ OBJ += $(BUILD)/pins.o BOOT_OBJ = $(addprefix $(BUILD)/, $(BOOT_SRC_C:.c=.o)) # List of sources for qstr extraction -SRC_QSTR += $(APP_MODS_SRC_C) $(APP_UTIL_SRC_C) $(APP_STM_SRC_C) $(APP_LIB_SRC_C) +SRC_QSTR += $(APP_MODS_SRC_C) $(APP_UTIL_SRC_C) $(APP_STM_SRC_C) $(APP_LIB_SRC_C) $(SRC_MOD) ifeq ($(BOARD), $(filter $(BOARD), LOPY LOPY4 FIPY)) SRC_QSTR += $(APP_MODS_LORA_SRC_C) endif @@ -480,7 +480,7 @@ BOOT_LDFLAGS = $(LDFLAGS) -T esp32.bootloader.ld -T esp32.rom.ld -T esp32.periph # add the application linker script(s) APP_LDFLAGS += $(LDFLAGS) -T esp32_out.ld -T esp32.project.ld -T esp32.rom.ld -T esp32.peripherals.ld -T esp32.rom.libgcc.ld -T esp32.extram.bss.ld - +APP_LDFLAGS += $(LDFLAGS_MOD) # add the application specific CFLAGS CFLAGS += $(APP_INC) -DMICROPY_NLR_SETJMP=1 -DMBEDTLS_CONFIG_FILE='"mbedtls/esp_config.h"' -DHAVE_CONFIG_H -DESP_PLATFORM -DFFCONF_H=\"lib/oofatfs/ffconf.h\" -DWITH_POSIX CFLAGS_SIGFOX += $(APP_INC) -DMICROPY_NLR_SETJMP=1 -DMBEDTLS_CONFIG_FILE='"mbedtls/esp_config.h"' -DHAVE_CONFIG_H -DESP_PLATFORM From 5d463a5e8a1c6be70fb79694119cb865dcae5482 Mon Sep 17 00:00:00 2001 From: Peter Putz Date: Wed, 23 Dec 2020 10:13:16 +0100 Subject: [PATCH 9/9] version 1.20.2.r3 --- esp32/pycom_version.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/esp32/pycom_version.h b/esp32/pycom_version.h index 55b3ed1ca3..b85d758bb1 100644 --- a/esp32/pycom_version.h +++ b/esp32/pycom_version.h @@ -10,7 +10,7 @@ #ifndef VERSION_H_ #define VERSION_H_ -#define SW_VERSION_NUMBER "1.20.2.r2" +#define SW_VERSION_NUMBER "1.20.2.r3" #define LORAWAN_VERSION_NUMBER "1.0.2"