Skip to content

ESP8266: Fix serial flow control inconsistency on reconnect #15240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions connectivity/drivers/wifi/esp8266-driver/ESP8266/ESP8266.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ struct ESP8266::fw_at_version ESP8266::at_version()
return _at_v;
}

bool ESP8266::stop_uart_hw_flow_ctrl(void)
bool ESP8266::stop_uart_hw_flow_ctrl(bool board_only)
{
bool done = true;
#if DEVICE_SERIAL_FC
Expand All @@ -202,9 +202,11 @@ bool ESP8266::stop_uart_hw_flow_ctrl(void)
// Stop board's flow control
_serial.set_flow_control(SerialBase::Disabled, _serial_rts, _serial_cts);

// Stop ESP8266's flow control
done = _parser.send("AT+UART_CUR=%u,8,1,0,0", MBED_CONF_ESP8266_SERIAL_BAUDRATE)
&& _parser.recv("OK\n");
if (!board_only) {
// Stop ESP8266's flow control
done = _parser.send("AT+UART_CUR=%u,8,1,0,0", MBED_CONF_ESP8266_SERIAL_BAUDRATE)
&& _parser.recv("OK\n");
}
}

#endif
Expand Down
3 changes: 2 additions & 1 deletion connectivity/drivers/wifi/esp8266-driver/ESP8266/ESP8266.h
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,10 @@ class ESP8266 {
/**
* Stop board's and ESP8266's UART flow control
*
* @param board_only true to apply to board only, false to apply both
* @return true if started
*/
bool stop_uart_hw_flow_ctrl();
bool stop_uart_hw_flow_ctrl(bool board_only = false);

/*
* From AT firmware v1.7.0.0 onwards enables TCP passive mode
Expand Down
14 changes: 12 additions & 2 deletions connectivity/drivers/wifi/esp8266-driver/ESP8266Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,8 +722,14 @@ bool ESP8266Interface::_get_firmware_ok()
nsapi_error_t ESP8266Interface::_init(void)
{
if (!_initialized) {
_pwr_pin.power_off();
_pwr_pin.power_on();
if (_pwr_pin.is_connected()) {
_pwr_pin.power_off();
_pwr_pin.power_on();
/* Align board's serial flow control with ESP8266's, resetting to disabled on re-power or reset */
if (!_esp.stop_uart_hw_flow_ctrl(true)) {
return NSAPI_ERROR_DEVICE_ERROR;
}
}

if (_reset() != NSAPI_ERROR_OK) {
return NSAPI_ERROR_DEVICE_ERROR;
Expand Down Expand Up @@ -780,6 +786,10 @@ nsapi_error_t ESP8266Interface::_reset()
ThisThread::sleep_for(delay);
_esp.flush();
_rst_pin.rst_deassert();
/* Align board's serial flow control with ESP8266's, resetting to disabled on re-power or reset */
if (!_esp.stop_uart_hw_flow_ctrl(true)) {
return NSAPI_ERROR_DEVICE_ERROR;
}
} else {
_esp.flush();
if (!_esp.at_available()) {
Expand Down