How to fix ESP32 Running stub… StopIteration


When flashing an ESP32, especially when flashing remotely, you see the following log message

Serial port rfc2217://
Device PID identification is only supported on COM and /dev/ serial ports.
Chip is ESP32-S2
Features: WiFi, No Embedded Flash, No Embedded PSRAM, ADC and temperature sensor calibration in BLK2 of efuse V2
Crystal is 40MHz
MAC: 60:55:f9:f0:3a:16
Uploading stub...
Running stub...
Traceback (most recent call last):
  File "/usr/local/bin/", line 34, in <module>
  File "/usr/local/lib/python3.8/dist-packages/esptool/", line 1004, in _main
  File "/usr/local/lib/python3.8/dist-packages/esptool/", line 684, in main
    esp = esp.run_stub()
  File "/usr/local/lib/python3.8/dist-packages/esptool/", line 912, in run_stub
    p =
  File "/usr/local/lib/python3.8/dist-packages/esptool/", line 307, in read
    return next(self._slip_reader)


This issue occurs not because of a hardware defect but because the latency of the connection is quite high and therefore the timeout occurs before the communication between the script and the bootloader can happen.

In order to fix it, you need to edit the hard-coded default timeout in the installation!

First, you need to identify the location of in your installation. You can simply do that from the following part of the stack trace:

File "/usr/local/lib/python3.8/dist-packages/esptool/", line 912, in run_stub p =

In this case, is located at


You need to edit the following line:

MEM_END_ROM_TIMEOUT = 0.05  # short timeout for ESP_MEM_END, as it may never respond

and increase the timeout – my recommendation is to increase it to 2.5 seconds.

… or you can simply change the timeout using the following command:

sed -i -e 's/MEM_END_ROM_TIMEOUT = 0.05/MEM_END_ROM_TIMEOUT = 2.5/g' /usr/local/lib/python3.8/dist-packages/esptool/

After that, your upload should work just fine.