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

It takes 3-5 minutes to decide that a connection cannot be established #86

Open
balloob opened this issue Feb 3, 2023 · 5 comments
Open
Labels
bug Something isn't working

Comments

@balloob
Copy link
Contributor

balloob commented Feb 3, 2023

ESPLoader is initialized by calling main_fn. This function calls detect_chip, which in turn calls connect which triggers the connection sequence.

If a device requires the BOOT mode to be held down to start flashing, the connection will fail. Currently it takes 4-5 minutes on my machine before it raises the error Failed to connect with the device. This seems too long.

The default attempts number for connect is set to 7. This means that 7 times it tries the following:

  • Calls connect_attempt with esp32r0_delay set to false
  • Calls connect_attempt with esp32r0_delay set to true

main_fn allows passing in a mode that is passed down to connect_attempt. It is defined as type string, it defaults to default_reset. It can be set to no_reset to skip resetting the device inside connect_attempt. The resetting takes quite some time, with hardcoded sleeps. If esp32r0_delay is true, there is a call to sleep 2 seconds!

Because our connection runs connect_attempt twice for each attempt, we are trying to attempt to connect 14 times. That's already twice as many as the Python tool does by default.

Below a screenshot of the console logs. This is not a full single attempt (out of 7), as it cuts off the 2nd call to connect_attempt with esp32r0_delay set to true. The screenshot already spans 26 seconds. It has another 6 full attempts to go!

CleanShot 2023-02-02 at 23 05 48

Looking at esptool, it also resets between every attempt, but it uses different reset strategies that leverage different delays https://github.com/espressif/esptool/blob/master/esptool/loader.py#L567. The strategies are defined at https://github.com/espressif/esptool/blob/master/esptool/reset.py#L61. By default the sleep delay between RTS setting is 0.05 and 0.55 for a 2nd reset attempt. There are also calls to 0.1 and 0.2s sleeps. There definitely is never a 2s sleep 👀 Also there is no reference to what esp32r0_delay is, it's not in the Python tool.

Summary:

  • What is esp32r0_delay?
  • Why are we doing two connection attempts for each attempt, doubling the number of attempts what esptool does?
  • Are there ways we can speed this up further?
@balloob balloob changed the title It takes 3 minutes to decide that a connection cannot be established It takes 3-5 minutes to decide that a connection cannot be established Feb 3, 2023
@igrr
Copy link
Member

igrr commented Feb 3, 2023

What is esp32r0_delay?

espressif/esptool@2d72f56#diff-b035aa3701bf24cdb68151b147c0cfe693bbb1b27812a779f13d4255bdff1fc7L597

Agree that some delays here are probably excessive, we can speed this up.

@igrr igrr added the bug Something isn't working label Feb 3, 2023
@balloob
Copy link
Contributor Author

balloob commented Feb 4, 2023

If esptool has removed it, can we remove it too? Or maybe we can guard it for Windows users only based on the user agent string ?

@RushikeshPatange
Copy link
Contributor

@balloob, @igrr, and @brianignacio5, could you please provide any updates regarding this particular issue?

@brianignacio5
Copy link
Collaborator

Do we still have these issues ? @RushikeshPatange @balloob ?

@RushikeshPatange
Copy link
Contributor

RushikeshPatange commented Dec 6, 2023

Do we still have these issues ? @RushikeshPatange @balloob ?

@brianignacio5, I have used esptool-js (example) with following dev-kits:

  • ESP32-C3-MINI-1U
  • ESP32-WROOM-32

I encountered this issue while working with the ESP32-WROOM-32 DevKit. Sometimes it connected automatically, but most of the time it took too long to connect. I found a workaround: pressing the boot button on the DevKit allowed it to connect immediately. Maybe this issue is occurring because I'm using an older ESP32-WROOM-32, but don't know the actual cause.

ESP32-WROOM-32 Connection Screenshot: ( Stuck at connection )
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants