8000 lte: detect modem in ffh/recovery mode · p3tr0/pycom-micropython-sigfox@4f07373 · GitHub
[go: up one dir, main page]

Skip to content

Commit 4f07373

Browse files
committed
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
1 parent e5a00fe commit 4f07373

File tree

3 files changed

+48
-6
lines changed

3 files changed

+48
-6
lines changed

esp32/lte/lteppp.c

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,35 @@ void lteppp_resume(void) {
444444
/******************************************************************************
445445
DEFINE PRIVATE FUNCTIONS
446446
******************************************************************************/
447+
bool trx_is_ok_or_error(){
448+
if (strstr(lteppp_trx_buffer, "ERROR\r\n") != NULL){
449+
// printf("ok\n");
450+
return true;
451+
} else if (strstr(lteppp_trx_buffer, "OK\r\n") != NULL) {
452+
// printf("error\n");
453+
return true;
454+
}
455+
return false;
456+
}
457+
458+
/** check whether modem is responding at 115200
459+
* this means it is in FFH or RECOVYER mode
460+
*/
461+
bool lteppp_check_ffh_mode(){
462+
uart_set_baudrate(LTE_UART_ID, 115200);
463+
uart_set_hw_flow_ctrl(LTE_UART_ID, UART_HW_FLOWCTRL_CTS_RTS, 64);
464+
uart_set_rts(LTE_UART_ID, true);
465+
466+
for ( uint8_t attempt = 0 ; attempt < 3 ; attempt++ ){
467+
lteppp_send_at_cmd("AT", LTE_PPP_BACK_OFF_TIME_MS);
468+
if ( trx_is_ok_or_error() ){
469+
// we could check for AT+SMOD / AT+BMOD to get more details
470+
return true;
471+
}
472+
}
473+
return false;
474+
}
475+
447476
static void TASK_LTE (void *pvParameters) {
448477
MSG("\n");
449478
bool sim_present;
@@ -510,9 +539,14 @@ static void TASK_LTE (void *pvParameters) {
510539
while(!lteppp_send_at_cmd("AT", LTE_RX_TIMEOUT_MIN_MS))
511540
{
512541
if (at_trials >= LTE_AT_CMD_TRIALS) {
513-
uart_set_hw_flow_ctrl(LTE_UART_ID, UART_HW_FLOWCTRL_DISABLE, 0);
514-
uart_set_rts(LTE_UART_ID, false);
542+
if ( lteppp_check_ffh_mode() ){
543+
lteppp_set_modem_conn_state(E_LTE_MODEM_RECOVERY);
544+
} else {
545+
uart_set_baudrate(LTE_UART_ID, MICROPY_LTE_UART_BAUDRATE);
546+
uart_set_hw_flow_ctrl(LTE_UART_ID, UART_HW_FLOWCTRL_DISABLE, 0);
547+
uart_set_rts(LTE_UART_ID, false);
515548
lteppp_set_modem_conn_state(E_LTE_MODEM_DISCONNECTED);
549+
}
516550
xSemaphoreGive(xLTE_modem_Conn_Sem);
517551
at_trials = 0;
518552
goto modem_init;

esp32/lte/lteppp.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ typedef enum {
6161
typedef enum {
6262
E_LTE_MODEM_CONNECTED = 0,
6363
E_LTE_MODEM_CONNECTING,
64-
E_LTE_MODEM_DISCONNECTED
64+
E_LTE_MODEM_DISCONNECTED,
65+
E_LTE_MODEM_RECOVERY
6566
} lte_modem_conn_state_t;
6667

6768
#ifdef LTE_DEBUG_BUFF

esp32/mods/modlte.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,13 @@ static mp_obj_t lte_init_helper(lte_obj_t *self, const mp_arg_val_t *args) {
463463
MP_THREAD_GIL_EXIT();
464464
xSemaphoreTake(xLTE_modem_Conn_Sem, portMAX_DELAY);
465465
MP_THREAD_GIL_ENTER();
466-
if (E_LTE_MODEM_DISCONNECTED == lteppp_get_modem_conn_state()) {
466+
lte_modem_conn_state_t modem_state = lteppp_get_modem_conn_state();
467+
if (E_LTE_MODEM_DISCONNECTED == modem_state) {
468+
xSemaphoreGive(xLTE_modem_Conn_Sem);
469+
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Couldn't start connection to Modem (modem_state=disconnected)"));
470+
} else if (E_LTE_MODEM_RECOVERY == modem_state){
467471
xSemaphoreGive(xLTE_modem_Conn_Sem);
468-
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Couldn't connect to Modem (modem_state=disconnected)"));
472+
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Couldn't start connection to Modem (modem_state=recovery). Perform a modem firmware update."));
469473
}
470474
break;
471475
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) {
479483
case E_LTE_MODEM_CONNECTED:
480484
//continue
481485
break;
486+
case E_LTE_MODEM_RECOVERY:
487+
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Couldn't connect to Modem (modem_state=recovery). Perform a modem firmware update."));
488+
break;
482489
default:
483-
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Couldn't connect to Modem (modem_state=default)"));
490+
nlr_raise(mp_obj_new_exception_msg(&mp_type_OSError, "Couldn't connect to Modem (modem_state - default)"));
484491
break;
485492
}
486493
lte_obj.cid = args[1].u_int;

0 commit comments

Comments
 (0)
0