Skip to content

Commit 2d6b63d

Browse files
author
Veijo Pesonen
committed
ESP8266: prevents doing reset twice in a row, unnecessary
1 parent 706dd39 commit 2d6b63d

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

components/wifi/esp8266-driver/ESP8266Interface.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -404,12 +404,7 @@ bool ESP8266Interface::_get_firmware_ok()
404404
nsapi_error_t ESP8266Interface::_init(void)
405405
{
406406
if (!_initialized) {
407-
_hw_reset();
408-
409-
if (!_esp.at_available()) {
410-
return NSAPI_ERROR_DEVICE_ERROR;
411-
}
412-
if (!_esp.reset()) {
407+
if (_reset() != NSAPI_ERROR_OK) {
413408
return NSAPI_ERROR_DEVICE_ERROR;
414409
}
415410
if (!_esp.echo_off()) {
@@ -436,7 +431,7 @@ nsapi_error_t ESP8266Interface::_init(void)
436431
return NSAPI_ERROR_OK;
437432
}
438433

439-
void ESP8266Interface::_hw_reset()
434+
nsapi_error_t ESP8266Interface::_reset()
440435
{
441436
if (_rst_pin.is_connected()) {
442437
_rst_pin.rst_assert();
@@ -445,7 +440,17 @@ void ESP8266Interface::_hw_reset()
445440
wait_ms(2); // Documentation says 200 us should have been enough, but experimentation shows that 1ms was not enough
446441
_esp.flush();
447442
_rst_pin.rst_deassert();
443+
} else {
444+
_esp.flush();
445+
if (!_esp.at_available()) {
446+
return NSAPI_ERROR_DEVICE_ERROR;
447+
}
448+
if (!_esp.reset()) {
449+
return NSAPI_ERROR_DEVICE_ERROR;
450+
}
448451
}
452+
453+
return _esp.at_available() ? NSAPI_ERROR_OK : NSAPI_ERROR_DEVICE_ERROR;
449454
}
450455

451456
struct esp8266_socket {

components/wifi/esp8266-driver/ESP8266Interface.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,10 @@ class ESP8266Interface : public NetworkStack, public WiFiInterface {
365365

366366
// Driver's state
367367
int _initialized;
368+
nsapi_error_t _connect_retval;
368369
bool _get_firmware_ok();
369370
nsapi_error_t _init(void);
370-
void _hw_reset();
371-
nsapi_error_t _connect_retval;
371+
nsapi_error_t _reset();
372372

373373
//sigio
374374
struct {

0 commit comments

Comments
 (0)