Skip to content

Commit 0e00159

Browse files
Seppo Takaloadbridge
authored andcommitted
Flush ESP8266 serial input buffers after HW reset
1 parent 8a1964e commit 0e00159

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

components/wifi/esp8266-driver/ESP8266/ESP8266.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,13 @@ int8_t ESP8266::default_wifi_mode()
11141114
return 0;
11151115
}
11161116

1117+
void ESP8266::flush()
1118+
{
1119+
_smutex.lock();
1120+
_parser.flush();
1121+
_smutex.unlock();
1122+
}
1123+
11171124
bool ESP8266::set_default_wifi_mode(const int8_t mode)
11181125
{
11191126
_smutex.lock();

components/wifi/esp8266-driver/ESP8266/ESP8266.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,15 @@ class ESP8266 {
367367
*/
368368
void bg_process_oob(uint32_t timeout, bool all);
369369

370+
/**
371+
* Flush the serial port input buffers.
372+
*
373+
* If you do HW reset for ESP module, you should
374+
* flush the input buffers from existing responses
375+
* from the device.
376+
*/
377+
void flush();
378+
370379
static const int8_t WIFIMODE_STATION = 1;
371380
static const int8_t WIFIMODE_SOFTAP = 2;
372381
static const int8_t WIFIMODE_STATION_SOFTAP = 3;

components/wifi/esp8266-driver/ESP8266Interface.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,14 @@ nsapi_error_t ESP8266Interface::_init(void)
368368

369369
void ESP8266Interface::_hw_reset()
370370
{
371-
_rst_pin.rst_assert();
372-
// If you happen to use Pin7 CH_EN as reset pin, not needed otherwise
373-
// https://www.espressif.com/sites/default/files/documentation/esp8266_hardware_design_guidelines_en.pdf
374-
wait_ms(2); // Documentation says 200 us should have been enough, but experimentation shows that 1ms was not enough
375-
_rst_pin.rst_deassert();
371+
if (_rst_pin.is_connected()) {
372+
_rst_pin.rst_assert();
373+
// If you happen to use Pin7 CH_EN as reset pin, not needed otherwise
374+
// https://www.espressif.com/sites/default/files/documentation/esp8266_hardware_design_guidelines_en.pdf
375+
wait_ms(2); // Documentation says 200 us should have been enough, but experimentation shows that 1ms was not enough
376+
_esp.flush();
377+
_rst_pin.rst_deassert();
378+
}
376379
}
377380

378381
struct esp8266_socket {

0 commit comments

Comments
 (0)