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 sketch upload fails with Failed to connect to ESP8266: Timed out waiting for packet header #7050

Closed
4 of 6 tasks
Twilight-Logic opened this issue Jan 31, 2020 · 10 comments

Comments

@Twilight-Logic
Copy link

Twilight-Logic commented Jan 31, 2020

Basic Infos

  • This issue complies with the issue POLICY doc.
  • I have read the documentation at readthedocs and the issue is not addressed there.
  • I have tested that the issue is present in current master branch (aka latest git).
  • I have searched the issue tracker for a similar issue.
  • If there is a stack dump, I have decoded it.
  • I have filled out all fields below.

Platform

  • Hardware: NodeMCU ESP8266
  • Core Version: [2.6.3]
  • Development Env: [Arduino IDE]
  • Operating System: [Ubuntu|Mint]

Settings in IDE

  • Module: [Generic ESP8266 Module]
  • Flash Mode: [Arduino IDE]
  • Flash Size: [4MB]
  • lwip Variant: [don't know]
  • Reset Method: [???]
  • Flash Frequency: [don't know]
  • CPU Frequency: [don't know]
  • Upload Using: [SERIAL]
  • Upload Speed: [115200)

Problem Description

When I upload a sketch using the Arduino IDE, with library version 2.6.0 or later I get the following error:

esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header

The problem does not occur when library version 2.5.2 is used, or when the upload is perfomed manually. I have tested 2.6.0, 2.6.3 and 3.0 with the following command:

./esptool.py --port /dev/ttyUSB2 write_flash 0x000000 mybinary.bin

I also substituted 3.0 for 2.6.3 in the Arduino library directory, but this did not help. The problem has been reported to me by others, including Windows users, trying to upload to an ESP8266, although the errors tend to vary somewhat..

Full output:

esptool.py v2.7
Serial port /dev/ttyUSB2
Connecting....
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: cc:50:e3:55:db:52
Uploading stub...
Running stub...
Stub running...
Manufacturer: 20
Device: 4016
Detected flash size: 4MB
Hard resetting via RTS pin...
esptool.py v2.7
Serial port /dev/ttyUSB2
Connecting........_____....._____....._____....._____....._____....._____....._____
Traceback (most recent call last):
  File "/home/johnc/.arduino15/packages/esp8266/hardware/esp8266/2.6.0/tools/upload.py", line 25, in <module>
    esptool.main(fakeargs)
  File "/home/johnc/.arduino15/packages/esp8266/hardware/esp8266/2.6.0/tools/esptool/esptool.py", line 2841, in main
    esp.connect(args.before)
  File "/home/johnc/.arduino15/packages/esp8266/hardware/esp8266/2.6.0/tools/esptool/esptool.py", line 483, in connect
    raise FatalError('Failed to connect to %s: %s' % (self.CHIP_NAME, last_error))
esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header
esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header

Warning: file /home/johnc/.arduino15/packages/esp8266/tools/python/3.7.2-post1/python links to an absolute path /usr/bin/python

Note the hard reset after detecting the flash size? This does not happen when esptool.py is run manually from the command line or with library version 2.5.2.

@hasenradball
Copy link
Contributor

Hello,
I use Core 2.6.3 on Win10, ubuntu and Mac. Everything is working fine.
I Hand in the past similar probs like you and the root cause was a wrong boards.txt file.
If you use a core 2.6.3 you should use the boards.txt from this core.
Maybe you can douple check this.

@Twilight-Logic
Copy link
Author

Twilight-Logic commented Feb 1, 2020

Thanks for your reply. The boards.txt file will be whatever the Arduino IDE Boards Manager has installed. I have not made any manual changes. The ESP8266 library was installed using the Boards Manager in Arduino IDE. In the Additional Boards Manager URL's field in preferences I have used the following URL, which can be found in a number of online references:

http://arduino.esp8266.com/stable/package_esp8266com_index.json

One assumes when installing support for a particular board, that the IDE Boards Manager will perform the necessary actions to install the correct resources. I can confirm that during the installation process, the version number directory (which on my computer is located at /home/user/.arduino15/packages/esp8266/hardware/esp8266/x.x.x - where x.x.x represents the version number, e.g. 2.6.3) gets deleted and then re-created with the version number corresponding to whatever version of the ESP8266 library has been selected to be installed. It would therefore seem that the complete library, including the boards.txt file, is getting updated during the install process.

Since there is no indication of version within the boards.txt file, whether the supplied file correctly corresponds with the ESP8266 library version I could not say.

@JAndrassy
Copy link
Contributor

the first run of esptool is successful. (this is for the erase, but it only prints informations, because you have Sketch only selected). but then the reset takes too long and the chip doesn't go into flashing mode.
is something connected to io 0, io 2, io 15, EN or reset pin?

@Twilight-Logic
Copy link
Author

Twilight-Logic commented Feb 1, 2020

No, only the USB cable is connected. Nothing attached to the GPIO pins.

After some further investigation I might be able to shed some more light on the matter. Looking at the output in the Arduino IDE after the upload, it shows that the following command line is being used to upload the binary code:

$ python upload.py --chip esp8266 --port /dev/ttyUSB0 --baud 115200 --before no_reset --after soft_reset write_flash 0x0 AR488-wifi.bin

Note that for clarity I have removed the full path to the python and tools directory in the esp8266 library hierarchy and simply ran the above from ~/.arduino15/packages/esp8266/hardware/esp8266/2.6.3/tools. This results in the same error condition. Since the error output showed an unexpected reset at the start of the upload, I ran the command again but without the '--before no_reset' parameter:

$ python upload.py --chip esp8266 --port /dev/ttyUSB0 --baud 115200 --before no_reset --after soft_reset write_flash 0x0 AR488-wifi.bin

This time the upload worked so the problem appears to be associated with the use of this parameter which is not used in the version 2.5.2 call:

python upload.py --chip esp8266 --port /dev/ttyUSB0 --baud 115200 --trace version --end --chip esp8266 --port /dev/ttyUSB0 --baud 115200 --trace write_flash 0x0 /tmp/arduino_build_299222/AR488-wifi.ino.bin --end

Although references to the '--before no_reset' parameter appear in both 2.5.2 and 2.6.3 versions of esptool.py, they only start appearing in boards.txt.py file from version 2.6.0 onwards.

Version 2.5.2:

$ grep -n "no_reset" boards.txt.py

Version 2.6.0:

$ grep -n "no_reset" boards.txt.py
303:            ( '.menu.ResetMethod.v1.upload.resetmethod', '--before no_reset --after soft_reset' ),
1014:        ( '.menu.ResetMethod.ck.upload.resetmethod', '--before no_reset --after soft_reset' ),
1019:        ( '.menu.ResetMethod.nodtr_nosync.upload.resetmethod', '--before no_reset_no_sync --after soft_reset' ),
1025:        ( '.upload.resetmethod', '--before no_reset --after soft_reset' ),
1033:        ( '.upload.resetmethod', '--before no_reset --after soft_reset' ),
1041:        ( '.upload.resetmethod', '--before no_reset_no_sync --after soft_reset' ),

Version 2.6.3:

$ grep -n "no_reset" boards.txt.py
305:            ( '.menu.ResetMethod.v1.upload.resetmethod', '--before no_reset --after soft_reset' ),
1017:        ( '.menu.ResetMethod.ck.upload.resetmethod', '--before no_reset --after soft_reset' ),
1022:        ( '.menu.ResetMethod.nodtr_nosync.upload.resetmethod', '--before no_reset_no_sync --after soft_reset' ),
1028:        ( '.upload.resetmethod', '--before no_reset --after soft_reset' ),
1036:        ( '.upload.resetmethod', '--before no_reset --after soft_reset' ),
1044:        ( '.upload.resetmethod', '--before no_reset_no_sync --after soft_reset' ),

Might this provide some clue?

@JAndrassy
Copy link
Contributor

the upload.py should run esptool only once since 2.6.1. before it run it twice, first for erase then for upload..
it looks like you have a wrong upload.py for 2.6.1+

@Twilight-Logic
Copy link
Author

Twilight-Logic commented Feb 1, 2020

That difference perhaps explains the reset attempt. The output in the original post came from 2.6.0. There is indeed a difference with version 2.6.3 as there seems to be no reset attempt, although with the original command line as per Arduino IDE the upload still fails. Shown here are the outputs from 2.6.3 of both the failed and successful attempt with the modified command line:

Fail (with --begin no_reset):

$ python upload.py --chip esp8266 --port /dev/ttyUSB0 --baud 115200 --before no_reset --after soft_reset write_flash 0x0 AR488-wifi.bin
esptool.py v2.8
Serial port /dev/ttyUSB0
Connecting........_____....._____....._____....._____....._____....._____....._____
Traceback (most recent call last):
  File "upload.py", line 65, in <module>
    esptool.main(cmdline)
  File "/home/johnc/.arduino15/packages/esp8266/hardware/esp8266/2.6.3/tools/esptool/esptool.py", line 2890, in main
    esp.connect(args.before)
  File "/home/johnc/.arduino15/packages/esp8266/hardware/esp8266/2.6.3/tools/esptool/esptool.py", line 483, in connect
    raise FatalError('Failed to connect to %s: %s' % (self.CHIP_NAME, last_error))
esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header

Success (without --begin no_reset):

$ python upload.py --chip esp8266 --port /dev/ttyUSB0 --baud 115200 --after soft_reset write_flash 0x0 AR488-wifi.bin
esptool.py v2.8
Serial port /dev/ttyUSB0
Connecting....
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: cc:50:e3:55:db:52
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Flash params set to 0x0340
Compressed 317680 bytes to 222562...
Wrote 317680 bytes (222562 compressed) at 0x00000000 in 19.6 seconds (effective 129.4 kbit/s)...
Hash of data verified.

Leaving...
Soft resetting...

@devyte
Copy link
Collaborator

devyte commented Feb 1, 2020

@Twilight-Logic Please try a new install from scratch for 2.6.3. Don't forget to delete the .arduino15 dir.

@Twilight-Logic
Copy link
Author

Well, I must admit to being sceptical about this suggestion, but tried it anyway. I renamed .arduino15 to .arduino15.bak and re-launched the IDE. My preferences were lost (as expected) so had to be set up again, although this takes just a few moments. I installed the ESP8266 library and also had to update the AVR boards library to bring it up to date. After some 5 minutes that was all done and I tried again. I can report that this time the upload was successful. I guess something must have got out of sync during the update process at some point....

The only drawback to this fix is that if someone has other categories of boards installed then they are all going to have to be re-installed but it doesn't take too long so not a big deal I guess.

Thanks for that suggestion.

@Twilight-Logic
Copy link
Author

Twilight-Logic commented Feb 1, 2020

Although I appreciate that deleting the whole of ~/.arduino15 might be "safer", it seems that it is sufficient to delete only ~/.arduino15/packages/esp8266. This avoids loosing preferences and having to re-install other board libraries.

@devyte
Copy link
Collaborator

devyte commented Feb 1, 2020

When moving back and forth between versions with a core, the IDE can sometimes mess up something somewhere, and you end up with an install that is a mix of files. This is not unique to us, I've had it happen with other cores. Me, when moving from one version to another in either direction, I prefer to uninstall - clean - install the new one, because paranoia.
Closing.

@devyte devyte closed this as completed Feb 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants