@@ -1004,6 +1004,7 @@ int SaraNcpClient::waitReady(bool powerOn) {
10041004 return SYSTEM_ERROR_NONE;
10051005 }
10061006
1007+ static int waitReadyRetries = 0 ;
10071008 ModemState modemState = ModemState::Unknown;
10081009
10091010 // Just in case make sure that the voltage translator is on
@@ -1048,6 +1049,7 @@ int SaraNcpClient::waitReady(bool powerOn) {
10481049 skipAll (serial_.get ());
10491050 parser_.reset ();
10501051 parserError_ = 0 ;
1052+ waitReadyRetries = 0 ;
10511053 LOG (TRACE, " NCP ready to accept AT commands" );
10521054
10531055 auto r = initReady (modemState);
@@ -1065,6 +1067,10 @@ int SaraNcpClient::waitReady(bool powerOn) {
10651067 // Hard reset the modem
10661068 modemHardReset (true );
10671069 ncpState (NcpState::OFF);
1070+ if (++waitReadyRetries >= 10 ) {
1071+ waitReadyRetries = 10 ;
1072+ modemEmergencyHardReset ();
1073+ }
10681074
10691075 return SYSTEM_ERROR_INVALID_STATE;
10701076 }
@@ -2548,6 +2554,35 @@ int SaraNcpClient::modemHardReset(bool powerOff) {
25482554 return SYSTEM_ERROR_NONE;
25492555}
25502556
2557+ int SaraNcpClient::modemEmergencyHardReset () {
2558+ if (ncpId () != PLATFORM_NCP_SARA_R510) {
2559+ return SYSTEM_ERROR_NONE;
2560+ }
2561+
2562+ LOG (TRACE, " Emergency hardware shutdown the modem" );
2563+ const auto pwrState = modemPowerState ();
2564+ // We can only reset the modem in the powered state
2565+ if (!pwrState) {
2566+ LOG (ERROR, " Modem is not powered on!" );
2567+ return SYSTEM_ERROR_INVALID_STATE;
2568+ }
2569+
2570+ // Low held on power pin
2571+ HAL_GPIO_Write (UBPWR, 0 );
2572+ HAL_Delay_Milliseconds (500 );
2573+ // Low held on reset pin
2574+ HAL_GPIO_Write (UBRST, 0 );
2575+ // Release power pin after 23s (23.5)
2576+ HAL_Delay_Milliseconds (23000 );
2577+ HAL_GPIO_Write (UBPWR, 1 );
2578+ // Release reset pin after 1.5s (2s)
2579+ HAL_Delay_Milliseconds (2000 );
2580+ HAL_GPIO_Write (UBRST, 1 );
2581+
2582+ ncpPowerState (NcpPowerState::TRANSIENT_ON);
2583+ return SYSTEM_ERROR_NONE;
2584+ }
2585+
25512586bool SaraNcpClient::modemPowerState () const {
25522587 return HAL_GPIO_Read (UBVINT);
25532588}
0 commit comments