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
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
  • Loading branch information
peter-pycom committed Dec 22, 2020
commit 4f07373df9a9994a757475ab08c6cd773a7e3e61
38 changes: 36 additions & 2 deletions esp32/lte/lteppp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion 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
13 changes: 10 additions & 3 deletions esp32/mods/modlte.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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;
Expand Down