SerialTimeoutException while flashing firmware to a esp8266 nodeMCU board using esptool

898 views Asked by At

I have been working on a project that involves controlling a 4 channel relay using micropython on a esp8266 nodeMCU board. I have been using esptool to flash the latest micropython firmware bin file to the board. Everything went well at first, and I continued to upload my code file to the board. Things started going sideways on me at that point. I issue had to do with the com3 port being busy. So, I again used esptool to erase the original flash, and then reflash the board. But this time I received a serial timeout exception several seconds after esptool started to write to the board. I tried again with two other identical (and brand new) boards, but I still get the same error every time. Below is the esptool output starting from the command line arguments.

(base) PS C:\development\python> esptool --port com3 --baud 9600 write_flash --flash_size detect --flash_mode dio -z 0x0000 esp8266-20210902-v1.17.bin
esptool.py v3.2
Serial port com3
Connecting...
Device PID identification is only supported on COM and /dev/ serial ports.
.
Detecting chip type... Unsupported detection protocol, switching and trying again...
Connecting...
Device PID identification is only supported on COM and /dev/ serial ports.
.
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 44:17:93:0d:50:04
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Flash will be erased from 0x00000000 to 0x0009afff...
Flash params set to 0x0240
Compressed 633688 bytes to 416263...
Writing at 0x00000000... (3 %)Traceback (most recent call last):
  File "c:\users\billa\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\billa\anaconda3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\billa\Anaconda3\Scripts\esptool.exe\__main__.py", line 7, in <module>
  File "c:\users\billa\anaconda3\lib\site-packages\esptool.py", line 5136, in _main
    main()
  File "c:\users\billa\anaconda3\lib\site-packages\esptool.py", line 4602, in main
    operation_func(esp, args)
  File "c:\users\billa\anaconda3\lib\site-packages\esptool.py", line 3873, in write_flash
    esp.flash_defl_block(block, seq, timeout=timeout)
  File "c:\users\billa\anaconda3\lib\site-packages\esptool.py", line 154, in inner
    return func(*args, **kwargs)
  File "c:\users\billa\anaconda3\lib\site-packages\esptool.py", line 919, in flash_defl_block
    self.ESP_FLASH_DEFL_DATA, struct.pack('<IIII', len(data), seq, 0, 0) + data, self.checksum(data), timeout=timeout)
  File "c:\users\billa\anaconda3\lib\site-packages\esptool.py", line 495, in check_command
    val, data = self.command(op, data, chk, timeout=timeout)
  File "c:\users\billa\anaconda3\lib\site-packages\esptool.py", line 458, in command
    self.write(pkt)
  File "c:\users\billa\anaconda3\lib\site-packages\esptool.py", line 421, in write
    self._port.write(buf)
  File "c:\users\billa\anaconda3\lib\site-packages\serial\serialwin32.py", line 323, in write
    raise writeTimeoutError
serial.serialutil.SerialTimeoutException: Write timeout
(base) PS C:\development\python> esptool --port com3 --baud 9600 erase_flash
esptool.py v3.2
Serial port com3
Connecting...
Device PID identification is only supported on COM and /dev/ serial ports.
.
Detecting chip type... Unsupported detection protocol, switching and trying again...
Connecting...
Device PID identification is only supported on COM and /dev/ serial ports.
.
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 44:17:93:0e:3f:ce
Uploading stub...
Running stub...
Stub running...
Erasing flash (this may take a while)...
Chip erase completed successfully in 4.7s
Hard resetting via RTS pin...
(base) PS C:\development\python> esptool --port com3 --baud 9600 write_flash --flash_size detect --flash_mode dio -z 0x0000 esp8266-20210902-v1.17.bin
esptool.py v3.2
Serial port com3
Connecting...
Device PID identification is only supported on COM and /dev/ serial ports.
.
Detecting chip type... Unsupported detection protocol, switching and trying again...
Connecting...
Device PID identification is only supported on COM and /dev/ serial ports.
.
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 44:17:93:0e:3f:ce
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Flash will be erased from 0x00000000 to 0x0009afff...
Flash params set to 0x0240
Compressed 633688 bytes to 416263...
Writing at 0x00000000... (3 %)Traceback (most recent call last):
  File "c:\users\billa\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\billa\anaconda3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\billa\Anaconda3\Scripts\esptool.exe\__main__.py", line 7, in <module>
  File "c:\users\billa\anaconda3\lib\site-packages\esptool.py", line 5136, in _main
    main()
  File "c:\users\billa\anaconda3\lib\site-packages\esptool.py", line 4602, in main
    operation_func(esp, args)
  File "c:\users\billa\anaconda3\lib\site-packages\esptool.py", line 3873, in write_flash
    esp.flash_defl_block(block, seq, timeout=timeout)
  File "c:\users\billa\anaconda3\lib\site-packages\esptool.py", line 154, in inner
    return func(*args, **kwargs)
  File "c:\users\billa\anaconda3\lib\site-packages\esptool.py", line 919, in flash_defl_block
    self.ESP_FLASH_DEFL_DATA, struct.pack('<IIII', len(data), seq, 0, 0) + data, self.checksum(data), timeout=timeout)
  File "c:\users\billa\anaconda3\lib\site-packages\esptool.py", line 495, in check_command
    val, data = self.command(op, data, chk, timeout=timeout)
  File "c:\users\billa\anaconda3\lib\site-packages\esptool.py", line 458, in command
    self.write(pkt)
  File "c:\users\billa\anaconda3\lib\site-packages\esptool.py", line 421, in write
    self._port.write(buf)
  File "c:\users\billa\anaconda3\lib\site-packages\serial\serialwin32.py", line 323, in write
    raise writeTimeoutError
serial.serialutil.SerialTimeoutException: Write timeout
(base) PS C:\development\python>

I have re-downloaded the firmware bin file just incase it had become corrupt somehow. I also attempted the same process on three different boards.

-----------------UPDATE 12/03/21------------------------------- I tried using the Arduino IDE to upload a test sketch that operates a 4 channel relay. I connected using the same com port (com3) and everything works perfectly! This does not explain why both the Thonny IDE and the esptool fail to connect to com3.

So, here are some conclusions. The issue is not with the esp8266, or the com port in my PC. Both the esptool and Thonny IDE worked in the beginning, and both failed to upload data to the board at roughly the same time, it is unlikely the issue is with either of those tools.

What does that leave to be investigated??

Thanks Bill

0

There are 0 answers