Skip to content

Commit 170aea5

Browse files
authored
Merge pull request #15240 from OpenNuvoton/nuvoton_esp8266_flow_control_reconnect
ESP8266: Fix serial flow control inconsistency on reconnect
2 parents c37cd51 + 0d2de99 commit 170aea5

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

connectivity/drivers/wifi/esp8266-driver/ESP8266/ESP8266.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ struct ESP8266::fw_at_version ESP8266::at_version()
193193
return _at_v;
194194
}
195195

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

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

210212
#endif

connectivity/drivers/wifi/esp8266-driver/ESP8266/ESP8266.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,10 @@ class ESP8266 {
455455
/**
456456
* Stop board's and ESP8266's UART flow control
457457
*
458+
* @param board_only true to apply to board only, false to apply both
458459
* @return true if started
459460
*/
460-
bool stop_uart_hw_flow_ctrl();
461+
bool stop_uart_hw_flow_ctrl(bool board_only = false);
461462

462463
/*
463464
* From AT firmware v1.7.0.0 onwards enables TCP passive mode

connectivity/drivers/wifi/esp8266-driver/ESP8266Interface.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,8 +722,14 @@ bool ESP8266Interface::_get_firmware_ok()
722722
nsapi_error_t ESP8266Interface::_init(void)
723723
{
724724
if (!_initialized) {
725-
_pwr_pin.power_off();
726-
_pwr_pin.power_on();
725+
if (_pwr_pin.is_connected()) {
726+
_pwr_pin.power_off();
727+
_pwr_pin.power_on();
728+
/* Align board's serial flow control with ESP8266's, resetting to disabled on re-power or reset */
729+
if (!_esp.stop_uart_hw_flow_ctrl(true)) {
730+
return NSAPI_ERROR_DEVICE_ERROR;
731+
}
732+
}
727733

728734
if (_reset() != NSAPI_ERROR_OK) {
729735
return NSAPI_ERROR_DEVICE_ERROR;
@@ -780,6 +786,10 @@ nsapi_error_t ESP8266Interface::_reset()
780786
ThisThread::sleep_for(delay);
781787
_esp.flush();
782788
_rst_pin.rst_deassert();
789+
/* Align board's serial flow control with ESP8266's, resetting to disabled on re-power or reset */
790+
if (!_esp.stop_uart_hw_flow_ctrl(true)) {
791+
return NSAPI_ERROR_DEVICE_ERROR;
792+
}
783793
} else {
784794
_esp.flush();
785795
if (!_esp.at_available()) {

0 commit comments

Comments
 (0)