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

Conversation

ccli8
Copy link
Contributor

@ccli8 ccli8 commented Aug 26, 2019

Description

This PR is a replacement for #11299. By adding configurations for reset pin polarity and reset assert time in ESP8266 driver, the original reset logic _rst_pin.rst_assert()/_rst_pin.rst_deassert() can extend to support power on/off control for the ESP8266 module. This is what #11299 wants to achieve.

This PR adds ESP8266 configurations:

  • Add configuration for reset pin polarity
  • Add configuration for reset assert time

Related PR

Replacement for #11299
Rely on #11288

Pull request type

[x] Fix
[ ] Refactor
[ ] Target update
[ ] Functionality change
[ ] Docs update
[ ] Test update
[ ] Breaking change

Reviewers

@michalpasztamobica

"help": "Polarity of RESET pin for the modem. [0/1]",
"value": 0
},
"rst-assert-time": {
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the time unit here? I suggest to call this rst-assert-time-us or something similar and adjust to whatever unit is needed in the code, for example ThisThread::sleep_for(MBED_CONF_ESP8266_RST_ASSERT_TIME_US/100);

If this is in system ticks, we can call it rst-assert-time-ticks.
@VeijoPesonen , any thoughts on this?

Copy link
Contributor

@VeijoPesonen VeijoPesonen Aug 26, 2019

Choose a reason for hiding this comment

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

I would like to know the reason why this needs to be made configurable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@VeijoPesonen rst-pin-polarity and rst-assert-time originally are to achieve what #11299 is at. Also restate on the top.

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 Change to rst-assert-time-us and adjust related code.

ThisThread::sleep_for(MBED_CONF_ESP8266_RST_ASSERT_TIME_US / 1000);

@michalpasztamobica
Copy link
Contributor

@ccli8 , would you also like to add a target override section for M2351, so that the configs you wanted to set are automatically available without modifications to mbed_app.json?

@@ -21,6 +21,14 @@
"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]",
"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).

@VeijoPesonen
Copy link
Contributor

@ccli8 The PR description should give the reason for these changes.

@ciarmcom ciarmcom requested review from michalpasztamobica and a team August 26, 2019 07:00
@ciarmcom
Copy link
Member

@ccli8, thank you for your changes.
@michalpasztamobica @ARMmbed/mbed-os-ipcore @ARMmbed/mbed-os-maintainers please review.

@ccli8 ccli8 force-pushed the nuvoton_esp8266_reset_config branch from 25fd174 to bd5704b Compare August 26, 2019 07:11
@ccli8
Copy link
Contributor Author

ccli8 commented Aug 26, 2019

would you also like to add a target override section for M2351, so that the configs you wanted to set are automatically available without modifications to mbed_app.json?

@michalpasztamobica Added. But M2351 is under target renaming. This PR must rely on #11288 for M2351 new target name confirmed.

"rst" : "PD_7",
"rts" : "PD_3",
"cts" : "PD_2",
"rst-pin-polarity" : "1"
Copy link
Contributor

Choose a reason for hiding this comment

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

Now that you didn't change the rst-assert-time-us configuration I second @VeijoPesonen 's remark - is this really necessary? If so - why not get the config for your target in here?
In general, I don't mind getting the module more configurable, but if the reset assertion time is a constant, it should stay that way.

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 Add rst-assert-time-us override for M2351. Its value follows our BSP sample code.

@ccli8 ccli8 force-pushed the nuvoton_esp8266_reset_config branch from bd5704b to 1864279 Compare August 26, 2019 07:39
@kjbracey
Copy link
Contributor

kjbracey commented Aug 26, 2019

Not a fan of this. Pin configurations are supposed to be program/run-time configurable.

And if there is an ESP8266 built-in to this target with custom wiring, then it should be using that run-time configuration to return an appropriately-configured ESP8266Interface object from its overriding WiFiInterface::get_default_target_instance. There shouldn't need to be any target knowledge in the ESP8266 driver itself.

},
"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.

@ciarmcom
Copy link
Member

@ccli8, thank you for your changes.
@michalpasztamobica @ARMmbed/mbed-os-ipcore @ARMmbed/mbed-os-maintainers please review.

@ccli8
Copy link
Contributor Author

ccli8 commented Aug 27, 2019

Create #11343 to replace this one

@ccli8
Copy link
Contributor Author

ccli8 commented Aug 29, 2019

Close via #11343

@ccli8 ccli8 closed this Aug 29, 2019
@cyliangtw cyliangtw deleted the nuvoton_esp8266_reset_config branch March 9, 2023 04:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants