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

ESP8266: Add configurations for reset control #11331

Closed
Closed
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
6 changes: 3 additions & 3 deletions components/wifi/esp8266-driver/ESP8266Interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ ESP8266Interface::ResetPin::ResetPin(PinName rst_pin) : _rst_pin(mbed::DigitalOu
void ESP8266Interface::ResetPin::rst_assert()
{
if (_rst_pin.is_connected()) {
_rst_pin = 0;
_rst_pin = MBED_CONF_ESP8266_RST_PIN_POLARITY;
tr_debug("HW reset asserted");
}
}
Expand All @@ -152,7 +152,7 @@ void ESP8266Interface::ResetPin::rst_deassert()
{
if (_rst_pin.is_connected()) {
// Notice that Pin7 CH_EN cannot be left floating if used as reset
_rst_pin = 1;
_rst_pin = !MBED_CONF_ESP8266_RST_PIN_POLARITY;
tr_debug("HW reset deasserted");
}
}
Expand Down Expand Up @@ -461,7 +461,7 @@ nsapi_error_t ESP8266Interface::_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
ThisThread::sleep_for(2); // Documentation says 200 us; need 2 ticks to get minimum 1 ms.
ThisThread::sleep_for(MBED_CONF_ESP8266_RST_ASSERT_TIME_US / 1000); // Documentation says 200 us; need 2 ticks to get minimum 1 ms.
_esp.flush();
_rst_pin.rst_deassert();
} else {
Expand Down
18 changes: 18 additions & 0 deletions components/wifi/esp8266-driver/mbed_lib.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
"help": "RESET pin for the modem, defaults to Not Connected",
"value": null
},
"rst-pin-polarity": {
"help": "Polarity of RESET pin for the modem. [0/1]",
"options": [0, 1],
"value": 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be useful to make use of the "options" field here to require either 0 or 1 as value here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@teetak01 Where can I reference "options" field?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@michalpasztamobica Thanks.
@teetak01 Use options for rst-pin-polarity.

Copy link
Contributor

@kjbracey kjbracey Aug 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0/1 isn't very meaningful. Have some reference to "active high" and/or "active low". CF UARTSerial::set_data_carrier_detect (although I see its doxygen comment is nonsense, sigh).

},
"rst-assert-time-us": {
"help": "Assert time of reset for the modem in us.",
"value": 2000
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this in microseconds, when it's really interpreted as "2 ticks", meaning "at least 1000us"? If this is going to be microseconds, then it should be set to 200, and the code should be rounding that up to 2 ticks: (us + 999) / 1000 + 1 = (us + 1999) / 1000.

But again, why is it configurable? Why would this differ between hardware? If the 3000 number for your target is correct, may as well always use it? (How many real microseconds is that supposed to represent? 2000?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Original code is 2 ms:

ThisThread::sleep_for(2);

So I change to:

ThisThread::sleep_for(MBED_CONF_ESP8266_RST_ASSERT_TIME_US / 1000);

where MBED_CONF_ESP8266_RST_ASSERT_TIME_US defaults to 2000 us.
But it seems the code doesn't follow the doc.

Configuring MBED_CONF_ESP8266_RST_ASSERT_TIME_US to 3000 for M2351 is for power on/off control. Its discussion starts from #11299.

Copy link
Contributor

@kjbracey kjbracey Aug 26, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, but the point is that it isn't trying to delay for 2000us. It's trying to delay for at least 200us. If you wanted a 2000us delay, it would have to wait for 3 ticks.

Using microseconds as the unit, strongly suggests you're fishing for some sort of microsecond precision, so I would immediately question the code as written - pointing out that sleep_for(time_us / 1000) may wait for only 1000us, not the 2000us specified. (Or worse, if 1500us was requested, it could wait for 0).

If this isn't really the ESP8266's reset pin, but a module power pin, then it would be better to add a new setting for the new pin, rather than hijack the code thinking that it's driving reset. That would be in line with what we're doing for all the cellular modems - one "soft" power line which is the device's own "button", and one "hard" which is a power control.

},
"debug": {
"help": "Enable debug logs. [true/false]",
"value": false
Expand Down Expand Up @@ -58,6 +67,15 @@
"NUCLEO_F411RE": {
"tx": "D8",
"rx": "D2"
},
"NUMAKER_PFM_M2351_CM": {
"tx" : "PD_1",
"rx" : "PD_0",
"rst" : "PD_7",
"rts" : "PD_3",
"cts" : "PD_2",
"rst-pin-polarity" : 1,
"rst-assert-time-us" : 3000
}
}
}