Skip to content

Commit e4018bd

Browse files
author
Teppo Järvelin
committed
Cellular: fix onboard modems powering failure
Don't call soft power on if device was already powered. Some modems need to wait before sending anything to modem after soft powering.
1 parent 0915097 commit e4018bd

File tree

5 files changed

+30
-10
lines changed

5 files changed

+30
-10
lines changed

features/cellular/framework/AT/AT_CellularContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ bool AT_CellularContext::set_new_context(int cid)
415415
strncpy(pdp_type_str, "IPV6", sizeof(pdp_type_str));
416416
pdp_type = IPV6_PDP_TYPE;
417417
} else if (modem_supports_ipv4) {
418-
strncpy(pdp_type_str, "IP", sizeof(pdp_type));
418+
strncpy(pdp_type_str, "IP", sizeof(pdp_type_str));
419419
pdp_type = IPV4_PDP_TYPE;
420420
} else {
421421
return false;

features/cellular/framework/device/CellularStateMachine.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
const int STM_STOPPED = -99;
4141
const int ACTIVE_PDP_CONTEXT = 0x01;
4242
const int ATTACHED_TO_NETWORK = 0x02;
43+
const int DEVICE_READY = 0x04;
4344

4445
namespace mbed {
4546

@@ -48,7 +49,7 @@ CellularStateMachine::CellularStateMachine(CellularDevice &device, events::Event
4849
_event_status_cb(0), _network(0), _queue(queue), _queue_thread(0), _sim_pin(0),
4950
_retry_count(0), _event_timeout(-1), _event_id(-1), _plmn(0), _command_success(false),
5051
_plmn_network_found(false), _is_retry(false), _cb_data(), _current_event(NSAPI_EVENT_CONNECTION_STATUS_CHANGE),
51-
_network_status(0)
52+
_status(0)
5253
{
5354
#if MBED_CONF_CELLULAR_RANDOM_MAX_START_DELAY == 0
5455
_start_time = 0;
@@ -84,7 +85,7 @@ void CellularStateMachine::reset()
8485
_event_id = -1;
8586
_plmn_network_found = false;
8687
_is_retry = false;
87-
_network_status = 0;
88+
_status = 0;
8889
_target_state = STATE_INIT;
8990
enter_to_state(STATE_INIT);
9091
}
@@ -112,7 +113,7 @@ bool CellularStateMachine::power_on()
112113
{
113114
_cb_data.error = _cellularDevice.hard_power_on();
114115
if (_cb_data.error != NSAPI_ERROR_OK) {
115-
tr_warn("Power on failed.");
116+
tr_warn("Hard power on failed.");
116117
return false;
117118
}
118119
return true;
@@ -177,7 +178,7 @@ bool CellularStateMachine::is_registered()
177178
}
178179

179180
_cb_data.status_data = status;
180-
return is_registered || _network_status;
181+
return is_registered || _status;
181182
}
182183

183184
bool CellularStateMachine::get_network_registration(CellularNetwork::RegistrationType type,
@@ -330,6 +331,7 @@ void CellularStateMachine::state_init()
330331
_cellularDevice.set_timeout(TIMEOUT_POWER_ON);
331332
tr_info("Start connecting (timeout %d s)", TIMEOUT_POWER_ON / 1000);
332333
_cb_data.error = _cellularDevice.is_ready();
334+
_status = _cb_data.error ? 0 : DEVICE_READY;
333335
if (_cb_data.error != NSAPI_ERROR_OK) {
334336
_event_timeout = _start_time;
335337
if (_start_time > 0) {
@@ -381,11 +383,15 @@ bool CellularStateMachine::device_ready()
381383
void CellularStateMachine::state_device_ready()
382384
{
383385
_cellularDevice.set_timeout(TIMEOUT_POWER_ON);
384-
_cb_data.error = _cellularDevice.soft_power_on();
386+
if (!(_status & DEVICE_READY)) {
387+
tr_debug("Device was not ready, calling soft_power_on()");
388+
_cb_data.error = _cellularDevice.soft_power_on();
389+
}
385390
if (_cb_data.error == NSAPI_ERROR_OK) {
386391
_cb_data.error = _cellularDevice.init();
387392
if (_cb_data.error == NSAPI_ERROR_OK) {
388393
if (device_ready()) {
394+
_status = 0;
389395
enter_to_state(STATE_SIM_PIN);
390396
}
391397
}
@@ -419,11 +425,11 @@ void CellularStateMachine::state_sim_pin()
419425

420426
if (_network->is_active_context()) { // check if context was already activated
421427
tr_debug("Active context found.");
422-
_network_status |= ACTIVE_PDP_CONTEXT;
428+
_status |= ACTIVE_PDP_CONTEXT;
423429
}
424430
CellularNetwork::AttachStatus status; // check if modem is already attached to a network
425431
if (_network->get_attach(status) == NSAPI_ERROR_OK && status == CellularNetwork::Attached) {
426-
_network_status |= ATTACHED_TO_NETWORK;
432+
_status |= ATTACHED_TO_NETWORK;
427433
tr_debug("Cellular already attached.");
428434
}
429435
if (_plmn) {
@@ -483,7 +489,7 @@ void CellularStateMachine::state_attaching()
483489
{
484490
_cellularDevice.set_timeout(TIMEOUT_CONNECT);
485491
tr_info("Attaching network (timeout %d s)", TIMEOUT_CONNECT / 1000);
486-
if (_network_status != ATTACHED_TO_NETWORK) {
492+
if (_status != ATTACHED_TO_NETWORK) {
487493
_cb_data.error = _network->set_attach();
488494
}
489495
if (_cb_data.error == NSAPI_ERROR_OK) {
@@ -724,6 +730,7 @@ void CellularStateMachine::device_ready_cb()
724730
_event_id = -1;
725731
if (device_ready()) {
726732
_is_retry = false;
733+
_status = 0;
727734
if (!check_is_target_reached()) {
728735
continue_from_state(STATE_SIM_PIN);
729736
}

features/cellular/framework/device/CellularStateMachine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ class CellularStateMachine {
183183
bool _is_retry;
184184
cell_callback_data_t _cb_data;
185185
nsapi_event_t _current_event;
186-
int _network_status; // Is there any active context or is modem attached to a network?
186+
int _status;
187187
PlatformMutex _mutex;
188188
};
189189

targets/TARGET_STM/TARGET_STM32F4/TARGET_MTB_MTS_DRAGONFLY/ONBOARD_TELIT_HE910.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include "cellular/onboard_modem_api.h"
2020
#include "UARTSerial.h"
2121
#include "ONBOARD_TELIT_HE910.h"
22+
#include "ThisThread.h"
23+
#include "CellularLog.h"
2224

2325
using namespace mbed;
2426

@@ -41,6 +43,8 @@ nsapi_error_t ONBOARD_TELIT_HE910::hard_power_off()
4143
nsapi_error_t ONBOARD_TELIT_HE910::soft_power_on()
4244
{
4345
::onboard_modem_power_up();
46+
// From Telit_xE910 Global form factor App note: It is mandatory to avoid sending data to the serial ports during the first 200ms of the module start-up.
47+
rtos::ThisThread::sleep_for(200);
4448
return NSAPI_ERROR_OK;
4549
}
4650

@@ -53,6 +57,12 @@ nsapi_error_t ONBOARD_TELIT_HE910::soft_power_off()
5357
CellularDevice *CellularDevice::get_target_default_instance()
5458
{
5559
static UARTSerial serial(MDMTXD, MDMRXD, 115200);
60+
#if DEVICE_SERIAL_FC
61+
if (MDMRTS != NC && MDMCTS != NC) {
62+
tr_debug("Modem flow control: RTS %d CTS %d", MDMRTS, MDMCTS);
63+
serial.set_flow_control(SerialBase::RTSCTS, MDMRTS, MDMCTS);
64+
}
65+
#endif
5666
static ONBOARD_TELIT_HE910 device(&serial);
5767
return &device;
5868
}

targets/TARGET_STM/TARGET_STM32F4/TARGET_MTS_DRAGONFLY_F411RE/ONBOARD_TELIT_HE910.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "cellular/onboard_modem_api.h"
2020
#include "UARTSerial.h"
2121
#include "ONBOARD_TELIT_HE910.h"
22+
#include "ThisThread.h"
2223
#include "CellularLog.h"
2324

2425
using namespace mbed;
@@ -42,6 +43,8 @@ nsapi_error_t ONBOARD_TELIT_HE910::hard_power_off()
4243
nsapi_error_t ONBOARD_TELIT_HE910::soft_power_on()
4344
{
4445
::onboard_modem_power_up();
46+
// From Telit_xE910 Global form factor App note: It is mandatory to avoid sending data to the serial ports during the first 200ms of the module start-up.
47+
rtos::ThisThread::sleep_for(200);
4548
return NSAPI_ERROR_OK;
4649
}
4750

0 commit comments

Comments
 (0)