Skip to content
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

Flush ESP8266 serial input buffers after HW reset #9341

Merged
merged 1 commit into from
Jan 14, 2019
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
7 changes: 7 additions & 0 deletions components/wifi/esp8266-driver/ESP8266/ESP8266.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,13 @@ int8_t ESP8266::default_wifi_mode()
return 0;
}

void ESP8266::flush()
{
_smutex.lock();
_parser.flush();
_smutex.unlock();
}

bool ESP8266::set_default_wifi_mode(const int8_t mode)
{
_smutex.lock();
Expand Down
9 changes: 9 additions & 0 deletions components/wifi/esp8266-driver/ESP8266/ESP8266.h
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,15 @@ class ESP8266 {
*/
void bg_process_oob(uint32_t timeout, bool all);

/**
* Flush the serial port input buffers.
*
* If you do HW reset for ESP module, you should
* flush the input buffers from existing responses
* from the device.
*/
void flush();

static const int8_t WIFIMODE_STATION = 1;
static const int8_t WIFIMODE_SOFTAP = 2;
static const int8_t WIFIMODE_STATION_SOFTAP = 3;
Expand Down
13 changes: 8 additions & 5 deletions components/wifi/esp8266-driver/ESP8266Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -368,11 +368,14 @@ nsapi_error_t ESP8266Interface::_init(void)

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

struct esp8266_socket {
Expand Down