Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
Merge pull request #508 from pycom/Dev
Browse files Browse the repository at this point in the history
Release 1.20.2.r3
  • Loading branch information
Xykon authored Dec 23, 2020
2 parents 0da0e46 + 044dfea commit 7d80661
Show file tree
Hide file tree
Showing 14 changed files with 150 additions and 79 deletions.
29 changes: 22 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 @@ -121,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
Expand Down Expand Up @@ -156,19 +169,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
23 changes: 20 additions & 3 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 All @@ -416,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)
Expand All @@ -436,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
Expand All @@ -463,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
Expand Down
85 changes: 60 additions & 25 deletions esp32/lte/lteppp.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void lteppp_init(void) {
lteppp_pcb = pppapi_pppos_create(&lteppp_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);

Expand Down Expand Up @@ -211,15 +211,26 @@ 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){
// 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);
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;
Expand Down Expand Up @@ -382,6 +393,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);
Expand Down Expand Up @@ -429,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;
Expand All @@ -447,9 +491,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);
Expand All @@ -463,9 +505,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;
Expand All @@ -486,9 +526,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;
Expand All @@ -501,11 +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);
xSemaphoreTake(xLTESem, portMAX_DELAY);
lteppp_modem_conn_state = E_LTE_MODEM_DISCONNECTED;
xSemaphoreGive(xLTESem);
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;
Expand Down Expand Up @@ -547,22 +588,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");
Expand Down Expand Up @@ -860,7 +895,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;
Expand Down
6 changes: 4 additions & 2 deletions esp32/lte/lteppp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -119,7 +120,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);

Expand Down
1 change: 1 addition & 0 deletions esp32/mods/modbt.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) },

Expand Down
17 changes: 12 additions & 5 deletions esp32/mods/modlte.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -463,24 +463,31 @@ 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()) {
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 connect to Modem (modem_state=disconnected)"));
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 start connection to Modem (modem_state=recovery). Perform a modem firmware update."));
}
break;
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)"));
}
break;
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;
Expand Down
6 changes: 3 additions & 3 deletions esp32/mods/modmachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,12 @@ 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

#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 Expand Up @@ -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
Expand Down
Loading

0 comments on commit 7d80661

Please sign in to comment.