-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathesp8266_packet_header_timeout
404 lines (331 loc) · 16.6 KB
/
esp8266_packet_header_timeout
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
Summary:
I'm sure there is no single cause for the error, as could be seen in the amount of mentions to it on the Web.
The procedure suggested here is based on a minor modification to be done in the esptool.py program, and some previous
tests are proposed to identify if the solutions applies (or not) to the problem you may have.
The esptool.py program allows to define some options in its command line (see --before option, https://github.com/espressif/esptool):
'default_reset',
'no_reset',
'no_reset_no_sync'
You can try with a simple commmand 'chip_id':
1st try: --before default_reset
$ python esptool.py -p /dev/ttyUSB0 --before default_reset chip_id
(if result:)
esptool.py v3.0
Serial port /dev/ttyUSB0
Connecting........_____....._____....._____....._____....._____....._____....._____
A fatal error occurred: Failed to connect to Espressif device: Timed out waiting for packet header
if this is what you get, then try:
2nd try: --before no_reset
$ python esptool.py -p /dev/ttyUSB0 --before no_reset chip_id
esptool.py v3.0
Serial port /dev/ttyUSB0
Connecting........
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 68:c6:3a:d4:d1:a7
Uploading stub...
Running stub...
Stub running...
Chip ID: 0x00d4d1a7
Hard resetting via RTS pin...
if it works, then this solution may apply to the problem you have:
Modify esptool.py, located in .arduino15/packages/esp8266/3.0.3/tools/esptool, Line 511 (if the Esp8266 board was installed using the Board manager)
##original code
def connect(self, mode='default_reset', attempts=DEFAULT_CONNECT_ATTEMPTS, detecting=False):
""" Try connecting repeatedly until successful, or giving up """
print('Connecting...', end='')
sys.stdout.flush()
last_error = None
try:
for _ in range(attempts) if attempts > 0 else itertools.count():
last_error = self._connect_attempt(mode=mode, esp32r0_delay=False) ## line1 to modify
if last_error is None:
break
last_error = self._connect_attempt(mode=mode, esp32r0_delay=True) ## line2 to modify
if last_error is None:
break
finally:
## modified code
try:
for _ in range(attempts) if attempts > 0 else itertools.count():
last_error = self._connect_attempt(mode='default_reset', esp32r0_delay=False) ## changed
if last_error is None:
break
last_error = self._connect_attempt(mode='no_reset', esp32r0_delay=True) ## changed
if last_error is None:
break
finally:
Save it, and now try again to upload your Arduino sketch.
Some Background:
The problem started with the above message, while trying to re-program a Wemos D1 mini board, that I previously flashed with the same program, but an older version.
I followed every sugestion I could find (there are quite many mentions about this issue out there...), just to name a few:
- changed cables (several times)
- changed board (bougth another Wemos D1 mini, and a D1 R2)
- added capacitor to GPIO00
- ensured Linux was updated (Ubuntu 18.04.6 LTS)
- ensured the proper Linux driver was handling the CH340 chip
$ lsmod | grep ch34
ch341 20480 0
usbserial 49152 1 ch341
$ dmesg
..........
2450.612203] ch341 3-1.4:1.0: ch341-uart converter detected
[ 2450.613330] usb 3-1.4: ch341-uart converter now attached to ttyUSB0
..........
$ lsusb
...........
Bus 003 Device 025: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter
...........
-updated Arduino IDE to the last version (Arduino:1.8.15 (Linux))
- re installed the ESP32 part using Git
- re installed the ESP8266 part using Board Manager ( I tried to install both using Git,
but the Arduino app did not work, no idea why not...)
-tried different upload speeds
-included the 26Mhz crystal frequency in the Arduino Tools menu for the D1 boards
( https://www.esp8266.com/viewtopic.php?t=20870&start=4)
line 4910 for R1 in file boards.txt, .arduino15/packages/hardware/esp8266/...
& line 4010 for R2
d1.menu.CrystalFreq.26=26 MHz
d1.menu.CrystalFreq.40=40 MHz
d1.menu.CrystalFreq.40.build.extra_flags=-DF_CRYSTAL=40000000 -DESP8266
Finally, I decided to take a look at esptool.py.
From the code, I noticed the mention to "esp32r0_delay", a summary of the issue is in esptool.py Line 447
(see also https://owenduffy.net/blog/?p=21574 for a detailed explanation, and Details: https://github.com/espressif/esptool/issues/136),
and the existence of 3 different reset types esptool.py uses:
'default_reset',
'no_reset',
'no_reset_no_sync'
Since esptool allows to define these option in the command line (, --before option, see https://github.com/espressif/esptool), I decide to try, starting with a command
that seemed the most simple: 'chip_id' (in fact it does much more).
1st try: --before default_reset
$ python esptool.py -p /dev/ttyUSB0 --before default_reset chip_id
result:
esptool.py v3.0
Serial port /dev/ttyUSB0
Connecting........_____....._____....._____....._____....._____....._____....._____
A fatal error occurred: Failed to connect to Espressif device: Timed out waiting for packet header
(it did not look good...)
2nd try: --before no_reset
$ python esptool.py -p /dev/ttyUSB0 --before no_reset chip_id
esptool.py v3.0
Serial port /dev/ttyUSB0
Connecting........
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 68:c6:3a:d4:d1:a7
Uploading stub...
Running stub...
Stub running...
Chip ID: 0x00d4d1a7
Hard resetting via RTS pin...
It worked!!
So I tried again.
$ python esptool.py -p /dev/ttyUSB0 --before no_reset chip_id
esptool.py v3.0
Serial port /dev/ttyUSB0
Connecting........_____....._____....._____....._____....._____....._____....._____
A fatal error occurred: Failed to connect to Espressif device: Timed out waiting for packet header
It did not work !! ??
So I tried again...
$ python esptool.py -p /dev/ttyUSB0 --before no_reset chip_id
esptool.py v3.0
Serial port /dev/ttyUSB0
Connecting........_____....._____....._____....._____....._____....._____....._____
A fatal error occurred: Failed to connect to Espressif device: Timed out waiting for packet header
It did not work...
I tried 2 more esptool.py commands before doing any change to esptool.py, using the same sequence:
first, --before default_reset
second, --before no_reset
$ python esptool.py -p /dev/ttyUSB0 --before default_reset --no-stub load_ram BlinkWithoutDelay.ino.d1_mini.bin
$ python esptool.py -p /dev/ttyUSB0 --before no_reset --no-stub load_ram BlinkWithoutDelay.ino.d1_mini.bin
$ python esptool.py -p /dev/ttyUSB0 --before default_reset load_ram helloworld-esp8266.bin
$ python esptool.py -p /dev/ttyUSB0 --before default_reset load_ram helloworld-esp8266.bin
(opening the Arduino Serial Monitor AFTER executing the command you should read: "Hello world!")
These .bin files are available at .arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/esptool/test/images.
All the tests using the same sequence ( 'default_reset, 'no_reset') proved to work fine
Details:
Arduino:1.8.15 (Linux), board:"LOLIN(WEMOS) D1 R2 & mini, 80 MHz, Flash, Disabled (new aborts on oom), Disabled, All SSL ciphers (most compatible), 32KB cache + 32KB IRAM (balanced), Use pgm_read macros for IRAM/PROGMEM, 4MB (FS:2MB OTA:~1019KB), v2 Lower Memory, Disabled, None, Only Sketch, 921600"
Executable segment sizes:
ICACHE : 32768 - flash instruction cache
IROM : 319180 - code in flash (default or ICACHE_FLASH_ATTR)
IRAM : 27789 / 32768 - code in IRAM (IRAM_ATTR, ISRs...)
DATA : 1520 ) - initialized variables (global, static) in RAM/HEAP
RODATA : 2428 ) / 81920 - constants (global, static) in RAM/HEAP
BSS : 26112 ) - zeroed variables (global, static) in RAM/HEAP
The Sketch uses 350917 bytes (33%) from global storage space. the maximum is 1044464 bytes.
Global Variables use 30060 bytes (36%) from dynamic memory, leaving 51860 bytes for local variables. The maximum is 81920 bytes.
esptool.py v3.0
Serial port /dev/ttyUSB0
Connecting........_____....._____....._____....._____....._____....._____....._____
Traceback (most recent call last):
File "/home/user/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/upload.py", line 66, in <module>
esptool.main(cmdline)
File "/home/user/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/esptool/esptool.py", line 3552, in main
esp.connect(args.before, args.connect_attempts)
File "/home/user/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/esptool/esptool.py", line 529, 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
user@hostid-540:~/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/esptool$ python esptool.py -p /dev/ttyUSB0 --before default_reset chip_id
esptool.py v3.0
Serial port /dev/ttyUSB0
Connecting........_____....._____....._____....._____....._____....._____....._____
A fatal error occurred: Failed to connect to Espressif device: Timed out waiting for packet header
user@hostid-540:~/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/esptool$ python esptool.py -p /dev/ttyUSB0 --before no_reset chip_id
esptool.py v3.0
Serial port /dev/ttyUSB0
Connecting........
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 68:c6:3a:d4:d1:a7
Uploading stub...
Running stub...
Stub running...
Chip ID: 0x00d4d1a7
Hard resetting via RTS pin...
user@hostid-540:~/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/esptool$ python esptool.py -p /dev/ttyUSB0 --before no_reset chip_id
esptool.py v3.0
Serial port /dev/ttyUSB0
Connecting........_____....._____....._____....._____....._____....._____....._____
A fatal error occurred: Failed to connect to Espressif device: Timed out waiting for packet header
user@hostid-540:~/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/esptool$ python esptool.py -p /dev/ttyUSB0 --before no_reset chip_id
esptool.py v3.0
Serial port /dev/ttyUSB0
Connecting........_____....._____....._____....._____....._____....._____....._____
A fatal error occurred: Failed to connect to Espressif device: Timed out waiting for packet header
######################################
user@hostid-540:~/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/esptool$ python esptool.py -p /dev/ttyUSB0 --before no_reset --no-stub load_ram BlinkWithoutDelay.ino.d1_mini.bin
esptool.py v3.0
Serial port /dev/ttyUSB0
Connecting........_____....._____....._____....._____....._____....._____....._____
A fatal error occurred: Failed to connect to Espressif device: Timed out waiting for packet header
user@hostid-540:~/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/esptool$ python esptool.py -p /dev/ttyUSB0 --before default_reset --no-stub load_ram BlinkWithoutDelay.ino.d1_mini.bin
esptool.py v3.0
Serial port /dev/ttyUSB0
Connecting........_____....._____....._____....._____....._____....._____....._____
A fatal error occurred: Failed to connect to Espressif device: Timed out waiting for packet header
user@hostid-540:~/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/esptool$ python esptool.py -p /dev/ttyUSB0 --before no_reset --no-stub load_ram BlinkWithoutDelay.ino.d1_mini.bin
esptool.py v3.0
Serial port /dev/ttyUSB0
Connecting........
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 68:c6:3a:d4:d1:a7
Enabling default SPI flash mode...
RAM boot...
Downloading 3460 bytes at 4010f000... done!
Downloading 40 bytes at 3fff20b8... done!
All segments done, executing at 4010f494
Exiting immediately.
user@hostid-540:~/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/esptool$
#######################################################################
I did a board Reset
user@hostid-540:~/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/esptool$ python esptool.py -p /dev/ttyUSB0 --before no_reset --no-stub load_ram BlinkWithoutDelay.ino.d1_mini.bin
esptool.py v3.0
Serial port /dev/ttyUSB0
Connecting........_____....._____....._____....._____....._____....._____....._____
A fatal error occurred: Failed to connect to Espressif device: Timed out waiting for packet header
user@hostid-540:~/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/esptool$
hacemos default reset
user@hostid-540:~/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/esptool$ python esptool.py -p /dev/ttyUSB0 --before default_reset --no-stub load_ram BlinkWithoutDelay.ino.d1_mini.bin
esptool.py v3.0
Serial port /dev/ttyUSB0
Connecting........_____....._____....._____....._____....._____....._____....._____
A fatal error occurred: Failed to connect to Espressif device: Timed out waiting for packet header
user@hostid-540:~/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/esptool$ python esptool.py -p /dev/ttyUSB0 --before no_reset --no-stub load_ram BlinkWithoutDelay.ino.d1_mini.bin
esptool.py v3.0
Serial port /dev/ttyUSB0
Connecting........
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 68:c6:3a:d4:d1:a7
Enabling default SPI flash mode...
RAM boot...
Downloading 3460 bytes at 4010f000... done!
Downloading 40 bytes at 3fff20b8... done!
All segments done, executing at 4010f494
Exiting immediately.
#########################################
user@hostid-540:~/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/esptool$ python esptool.py -p /dev/ttyUSB0 --before default_reset load_ram helloworld-esp8266.bin
esptool.py v3.0
Serial port /dev/ttyUSB0
Connecting........_____....._____....._____....._____....._____....._____....._____
A fatal error occurred: Failed to connect to Espressif device: Timed out waiting for packet header
user@hostid-540:~/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/esptool$ python esptool.py -p /dev/ttyUSB0 --before no_reset load_ram helloworld-esp8266.bin
esptool.py v3.0
Serial port /dev/ttyUSB0
Connecting........
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 68:c6:3a:d4:d1:a7
Uploading stub...
Running stub...
Stub running...
RAM boot...
Downloading 48 bytes at 40108000... done!
Downloading 16 bytes at 3ffe8000... done!
All segments done, executing at 4010802c
Exiting immediately.
Now, opening the Arduino Serial Monitor I've found:
Hello world!
Note: the Arduino Serial Monitor should not be opened while using esptool, otherwise esptool.py will not start ("/dev/ttyUSB0 busy")
user@hostid-540:~/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/esptool$ python esptool.py -p /dev/ttyUSB0 --before no_reset load_ram helloworld-esp8266.bin
esptool.py v3.0
Serial port /dev/ttyUSB0
Connecting........_____....._____....._____....._____....._____....._____....._____
A fatal error occurred: Failed to connect to Espressif device: Timed out waiting for packet header
user@hostid-540:~/.arduino15/packages/esp8266/hardware/esp8266/3.0.2/tools/esptool$
######################################
after modifying esptool.py
Arduino output
Executable segment sizes:
ICACHE : 32768 - flash instruction cache
IROM : 231756 - code in flash (default or ICACHE_FLASH_ATTR)
IRAM : 26793 / 32768 - code in IRAM (IRAM_ATTR, ISRs...)
DATA : 1496 ) - initialized variables (global, static) in RAM/HEAP
RODATA : 876 ) / 81920 - constants (global, static) in RAM/HEAP
BSS : 25616 ) - zeroed variables (global, static) in RAM/HEAP
The Sketch uses 350917 bytes (33%) from global storage space. the maximum is 1044464 bytes.
Global Variables use 30060 bytes (36%) from dynamic memory, leaving 51860 bytes for local variables. The maximum is 81920 bytes.
esptool.py v3.0
Serial port /dev/ttyUSB0
Connecting........_
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 68:c6:3a:d4:d1:a7
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 265072 bytes to 195082...
Writing at 0x00000000... (8 %)
Writing at 0x00004000... (16 %)
Writing at 0x00008000... (25 %)
Writing at 0x0000c000... (33 %)
Writing at 0x00010000... (41 %)
Writing at 0x00014000... (50 %)
Writing at 0x00018000... (58 %)
Writing at 0x0001c000... (66 %)
Writing at 0x00020000... (75 %)
Writing at 0x00024000... (83 %)
Writing at 0x00028000... (91 %)
Writing at 0x0002c000... (100 %)
Wrote 265072 bytes (195082 compressed) at 0x00000000 in 17.2 seconds (effective 123.1 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting via RTS pin...
## end of tests, it works...