ESP32-C3 Flashing fails part way

ashesman
Posts: 20
Joined: Sun Jun 02, 2019 9:25 pm

ESP32-C3 Flashing fails part way

Postby ashesman » Wed Dec 21, 2022 10:57 pm

I have been flashing an ESP32-C3 over built in USB many times and suddenly it stopped flashing fully. It fails always somewhere between 20-30% of the main flash. I also notice that the Windows device manager flashes when this happens, like USB devices are changing. It is like the chip dies during flashing and drops the USB!

I have other boards that are still flashing fine. This one was flashing fine all morning, then suddenly stopped working. I cant do a flash-erase as it does not work for ESP32-C3 (according to the command output).

I tried power cycles, rebooting my PC etc. The problem is specific to this device and happened for no apparent reason. There was no hardware change or damage. Just stopped all by itself!

How can I recover this device?

Code: Select all

>idf.py -p COM6 flash
Executing action: flash
Running ninja in directory c:\users\x\documents\esp32\evnexhomeesp32firmware\build
Executing "ninja flash"...
[1/6] cmd.exe /C "cd /D C:\Users\x\Documents\ESP32\Ev...2/EvnexHomeESP32Firmware/build/EvnexHomeESP32Firmware.bin"
EvnexHomeESP32Firmware.bin binary size 0xdc7b0 bytes. Smallest app partition is 0x140000 bytes. 0x63850 bytes (31%) free.
[2/6] Performing build step for 'bootloader'
[1/1] cmd.exe /C "cd /D C:\Users\x\Documents\ESP32\EvnexHomeESP32Firmware\build\bootloader\esp-idf\esptool_py && C:\Espressif\python_env\idf4.4_py3.8_env\Scripts\python.exe C:/Espressif/frameworks/esp-idf-v4.4.2/components/partition_table/check_sizes.py --offset 0x8000 bootloader 0x0 C:/Users/x/Documents/ESP32/EvnexHomeESP32Firmware/build/bootloader/bootloader.bin"
Bootloader binary size 0x4d30 bytes. 0x32d0 bytes (40%) free.
[3/4] cmd.exe /C "cd /D C:\Espressif\frameworks\esp-idf-v4...sp-idf-v4.4.2/components/esptool_py/run_serial_tool.cmake"
esptool.py esp32c3 -p COM6 -b 460800 --before=default_reset --after=hard_reset --no-stub write_flash --flash_mode dio --flash_freq 80m --flash_size 4MB 0x0 bootloader/bootloader.bin 0x20000 EvnexHomeESP32Firmware.bin 0x8000 partition_table/partition-table.bin 0xf000 ota_data_initial.bin
esptool.py v3.3.2-dev
Serial port COM6
Connecting...
Chip is ESP32-C3 (revision 3)
Features: Wi-Fi
Crystal is 40MHz
MAC: a0:76:4e:6c:69:f0
Changing baud rate to 460800
Changed.
Enabling default SPI flash mode...
Configuring flash size...
Flash will be erased from 0x00000000 to 0x00004fff...
Flash will be erased from 0x00020000 to 0x000fcfff...
Flash will be erased from 0x00008000 to 0x00008fff...
Flash will be erased from 0x0000f000 to 0x00010fff...
Erasing flash...
Took 0.22s to erase flash block
Writing at 0x00000000... (5 %)
Writing at 0x00000400... (10 %)
Writing at 0x00000800... (15 %)
Writing at 0x00000c00... (20 %)
Writing at 0x00001000... (25 %)
Writing at 0x00001400... (30 %)
Writing at 0x00001800... (35 %)
Writing at 0x00001c00... (40 %)
Writing at 0x00002000... (45 %)
Writing at 0x00002400... (50 %)
Writing at 0x00002800... (55 %)
Writing at 0x00002c00... (60 %)
Writing at 0x00003000... (65 %)
Writing at 0x00003400... (70 %)
Writing at 0x00003800... (75 %)
Writing at 0x00003c00... (80 %)
Writing at 0x00004000... (85 %)
Writing at 0x00004400... (90 %)
Writing at 0x00004800... (95 %)
Writing at 0x00004c00... (100 %)
Wrote 20480 bytes at 0x00000000 in 0.4 seconds (420.0 kbit/s)...
Hash of data verified.
Erasing flash...
Took 4.71s to erase flash block
Writing at 0x00020000... (0 %)
Writing at 0x00020400... (0 %)
Writing at 0x00020800... (0 %)
Writing at 0x00020c00... (0 %)
Writing at 0x00021000... (0 %)
Writing at 0x00021400... (0 %)
Writing at 0x00021800... (0 %)
Writing at 0x00021c00... (0 %)
Writing at 0x00022000... (1 %)
Writing at 0x00022400... (1 %)
Writing at 0x00022800... (1 %)
Writing at 0x00022c00... (1 %)
Writing at 0x00023000... (1 %)
Writing at 0x00023400... (1 %)
Writing at 0x00023800... (1 %)
Writing at 0x00023c00... (1 %)
Writing at 0x00024000... (1 %)
Writing at 0x00024400... (2 %)
Writing at 0x00024800... (2 %)
Writing at 0x00024c00... (2 %)
Writing at 0x00025000... (2 %)
Writing at 0x00025400... (2 %)
Writing at 0x00025800... (2 %)
Writing at 0x00025c00... (2 %)
Writing at 0x00026000... (2 %)
Writing at 0x00026400... (2 %)
Writing at 0x00026800... (3 %)
Writing at 0x00026c00... (3 %)
Writing at 0x00027000... (3 %)
Writing at 0x00027400... (3 %)
Writing at 0x00027800... (3 %)
Writing at 0x00027c00... (3 %)
Writing at 0x00028000... (3 %)
Writing at 0x00028400... (3 %)
Writing at 0x00028800... (3 %)
Writing at 0x00028c00... (4 %)
Writing at 0x00029000... (4 %)
Writing at 0x00029400... (4 %)
Writing at 0x00029800... (4 %)
Writing at 0x00029c00... (4 %)
Writing at 0x0002a000... (4 %)
Writing at 0x0002a400... (4 %)
Writing at 0x0002a800... (4 %)
Writing at 0x0002ac00... (4 %)
Writing at 0x0002b000... (5 %)
Writing at 0x0002b400... (5 %)
Writing at 0x0002b800... (5 %)
Writing at 0x0002bc00... (5 %)
Writing at 0x0002c000... (5 %)
Writing at 0x0002c400... (5 %)
Writing at 0x0002c800... (5 %)
Writing at 0x0002cc00... (5 %)
Writing at 0x0002d000... (6 %)
Writing at 0x0002d400... (6 %)
Writing at 0x0002d800... (6 %)
Writing at 0x0002dc00... (6 %)
Writing at 0x0002e000... (6 %)
Writing at 0x0002e400... (6 %)
Writing at 0x0002e800... (6 %)
Writing at 0x0002ec00... (6 %)
Writing at 0x0002f000... (6 %)
Writing at 0x0002f400... (7 %)
Writing at 0x0002f800... (7 %)
Writing at 0x0002fc00... (7 %)
Writing at 0x00030000... (7 %)
Writing at 0x00030400... (7 %)
Writing at 0x00030800... (7 %)
Writing at 0x00030c00... (7 %)
Writing at 0x00031000... (7 %)
Writing at 0x00031400... (7 %)
Writing at 0x00031800... (8 %)
Writing at 0x00031c00... (8 %)
Writing at 0x00032000... (8 %)
Writing at 0x00032400... (8 %)
Writing at 0x00032800... (8 %)
Writing at 0x00032c00... (8 %)
Writing at 0x00033000... (8 %)
Writing at 0x00033400... (8 %)
Writing at 0x00033800... (8 %)
Writing at 0x00033c00... (9 %)
Writing at 0x00034000... (9 %)
Writing at 0x00034400... (9 %)
Writing at 0x00034800... (9 %)
Writing at 0x00034c00... (9 %)
Writing at 0x00035000... (9 %)
Writing at 0x00035400... (9 %)
Writing at 0x00035800... (9 %)
Writing at 0x00035c00... (9 %)
Writing at 0x00036000... (10 %)
Writing at 0x00036400... (10 %)
Writing at 0x00036800... (10 %)
Writing at 0x00036c00... (10 %)
Writing at 0x00037000... (10 %)
Writing at 0x00037400... (10 %)
Writing at 0x00037800... (10 %)
Writing at 0x00037c00... (10 %)
Writing at 0x00038000... (10 %)
Writing at 0x00038400... (11 %)
Writing at 0x00038800... (11 %)
Writing at 0x00038c00... (11 %)
Writing at 0x00039000... (11 %)
Writing at 0x00039400... (11 %)
Writing at 0x00039800... (11 %)
Writing at 0x00039c00... (11 %)
Writing at 0x0003a000... (11 %)
Writing at 0x0003a400... (12 %)
Writing at 0x0003a800... (12 %)
Writing at 0x0003ac00... (12 %)
Writing at 0x0003b000... (12 %)
Writing at 0x0003b400... (12 %)
Writing at 0x0003b800... (12 %)
Writing at 0x0003bc00... (12 %)
Writing at 0x0003c000... (12 %)
Writing at 0x0003c400... (12 %)
Writing at 0x0003c800... (13 %)
Writing at 0x0003cc00... (13 %)
Writing at 0x0003d000... (13 %)
Writing at 0x0003d400... (13 %)
Writing at 0x0003d800... (13 %)
Writing at 0x0003dc00... (13 %)
Writing at 0x0003e000... (13 %)
Writing at 0x0003e400... (13 %)
Writing at 0x0003e800... (13 %)
Writing at 0x0003ec00... (14 %)
Writing at 0x0003f000... (14 %)
Writing at 0x0003f400... (14 %)
Writing at 0x0003f800... (14 %)
Writing at 0x0003fc00... (14 %)
Writing at 0x00040000... (14 %)
Writing at 0x00040400... (14 %)
Writing at 0x00040800... (14 %)
Writing at 0x00040c00... (14 %)
Writing at 0x00041000... (15 %)
Writing at 0x00041400... (15 %)
Writing at 0x00041800... (15 %)
Writing at 0x00041c00... (15 %)
Writing at 0x00042000... (15 %)
Writing at 0x00042400... (15 %)
Writing at 0x00042800... (15 %)
Writing at 0x00042c00... (15 %)
Writing at 0x00043000... (15 %)
Writing at 0x00043400... (16 %)
Writing at 0x00043800... (16 %)
Writing at 0x00043c00... (16 %)
Writing at 0x00044000... (16 %)
Writing at 0x00044400... (16 %)
Writing at 0x00044800... (16 %)
Writing at 0x00044c00... (16 %)
Writing at 0x00045000... (16 %)
Writing at 0x00045400... (17 %)
Writing at 0x00045800... (17 %)
Writing at 0x00045c00... (17 %)
Writing at 0x00046000... (17 %)
Writing at 0x00046400... (17 %)
Writing at 0x00046800... (17 %)
Writing at 0x00046c00... (17 %)
Writing at 0x00047000... (17 %)
Writing at 0x00047400... (17 %)
Writing at 0x00047800... (18 %)
Writing at 0x00047c00... (18 %)
Writing at 0x00048000... (18 %)
Writing at 0x00048400... (18 %)
Writing at 0x00048800... (18 %)
Writing at 0x00048c00... (18 %)
Writing at 0x00049000... (18 %)
Writing at 0x00049400... (18 %)
Writing at 0x00049800... (18 %)
Writing at 0x00049c00... (19 %)
Writing at 0x0004a000... (19 %)
Writing at 0x0004a400... (19 %)
Writing at 0x0004a800... (19 %)
Writing at 0x0004ac00... (19 %)
Writing at 0x0004b000... (19 %)
Writing at 0x0004b400... (19 %)
Writing at 0x0004b800... (19 %)
Writing at 0x0004bc00... (19 %)
Writing at 0x0004c000... (20 %)
Writing at 0x0004c400... (20 %)
Writing at 0x0004c800... (20 %)
Writing at 0x0004cc00... (20 %)
Writing at 0x0004d000... (20 %)
Writing at 0x0004d400... (20 %)
Writing at 0x0004d800... (20 %)
Writing at 0x0004dc00... (20 %)
Writing at 0x0004e000... (20 %)
Writing at 0x0004e400... (21 %)
Writing at 0x0004e800... (21 %)
Writing at 0x0004ec00... (21 %)
Writing at 0x0004f000... (21 %)
Writing at 0x0004f400... (21 %)
Writing at 0x0004f800... (21 %)
Writing at 0x0004fc00... (21 %)
Writing at 0x00050000... (21 %)
Writing at 0x00050400... (21 %)
Writing at 0x00050800... (22 %)
Writing at 0x00050c00... (22 %)
Writing at 0x00051000... (22 %)
Writing at 0x00051400... (22 %)
Writing at 0x00051800... (22 %)
Writing at 0x00051c00... (22 %)
Writing at 0x00052000... (22 %)
Writing at 0x00052400... (22 %)
Writing at 0x00052800... (23 %)
Writing at 0x00052c00... (23 %)
Writing at 0x00053000... (23 %)
Writing at 0x00053400... (23 %)
Writing at 0x00053800... (23 %)
Writing at 0x00053c00... (23 %)
Writing at 0x00054000... (23 %)
Writing at 0x00054400... (23 %)
Writing at 0x00054800... (23 %)
Writing at 0x00054c00... (24 %)
Writing at 0x00055000... (24 %)
Writing at 0x00055400... (24 %)
Writing at 0x00055800... (24 %)
Writing at 0x00055c00... (24 %)
Writing at 0x00056000... (24 %)
Writing at 0x00056400... (24 %)
Writing at 0x00056800... (24 %)
Writing at 0x00056c00... (24 %)
Writing at 0x00057000... (25 %)
Writing at 0x00057400... (25 %)
Traceback (most recent call last):
  File "C:/Espressif/frameworks/esp-idf-v4.4.2/components/esptool_py/esptool/esptool.py", line 5399, in <module>
    _main()
  File "C:/Espressif/frameworks/esp-idf-v4.4.2/components/esptool_py/esptool/esptool.py", line 5392, in _main
    main()
  File "C:/Espressif/frameworks/esp-idf-v4.4.2/components/esptool_py/esptool/esptool.py", line 4824, in main
    operation_func(esp, args)
  File "C:/Espressif/frameworks/esp-idf-v4.4.2/components/esptool_py/esptool/esptool.py", line 4028, in write_flash
    esp.flash_block(block, seq)
  File "C:/Espressif/frameworks/esp-idf-v4.4.2/components/esptool_py/esptool/esptool.py", line 801, in flash_block
    self.check_command("write to target Flash after seq %d" % seq,
  File "C:/Espressif/frameworks/esp-idf-v4.4.2/components/esptool_py/esptool/esptool.py", line 495, in check_command
    val, data = self.command(op, data, chk, timeout=timeout)
  File "C:/Espressif/frameworks/esp-idf-v4.4.2/components/esptool_py/esptool/esptool.py", line 451, in command
    self._port.timeout = new_timeout
  File "C:\Espressif\python_env\idf4.4_py3.8_env\lib\site-packages\serial\serialutil.py", line 372, in timeout
    self._reconfigure_port()
  File "C:\Espressif\python_env\idf4.4_py3.8_env\lib\site-packages\serial\serialwin32.py", line 222, in _reconfigure_port
    raise SerialException(
serial.serialutil.SerialException: Cannot configure port, something went wrong. Original message: OSError(22, 'A device which does not exist was specified.', None, 433)
CMake Error at run_serial_tool.cmake:56 (message):
  C:/Espressif/python_env/idf4.4_py3.8_env/Scripts/python.exe
  C:/Espressif/frameworks/esp-idf-v4.4.2/components/esptool_py/esptool/esptool.py
  --chip esp32c3 failed


FAILED: CMakeFiles/flash C:/Users/x/Documents/ESP32/EvnexHomeESP32Firmware/build/CMakeFiles/flash
cmd.exe /C "cd /D C:\Espressif\frameworks\esp-idf-v4.4.2\components\esptool_py && C:\Espressif\tools\cmake\3.23.1\bin\cmake.exe -D IDF_PATH="C:/Espressif/frameworks/esp-idf-v4.4.2" -D SERIAL_TOOL="C:/Espressif/python_env/idf4.4_py3.8_env/Scripts/python.exe C:/Espressif/frameworks/esp-idf-v4.4.2/components/esptool_py/esptool/esptool.py --chip esp32c3" -D SERIAL_TOOL_ARGS="--before=default_reset --after=hard_reset --no-stub write_flash @flash_args" -D WORKING_DIRECTORY="C:/Users/x/Documents/ESP32/EvnexHomeESP32Firmware/build" -P C:/Espressif/frameworks/esp-idf-v4.4.2/components/esptool_py/run_serial_tool.cmake"
ninja: build stopped: subcommand failed.
ninja failed with exit code 1

ashesman
Posts: 20
Joined: Sun Jun 02, 2019 9:25 pm

Re: ESP32-C3 Flashing fails part way

Postby ashesman » Thu Dec 22, 2022 1:52 am

As a follow up, eventually I was able to fix this. I dont know if it was by chance or what I did!

I tried to start a USB-JTAG debug session from Espressif IDE. It did not start (it never does, always times out on open OCD). But, after that I was able to program from the command line again (over built in USB as usual).

I suspect the attempt to start a JTAG session caused the chip to be erased. But as there is no output feedback, just a one line timeout error message, I cant be sure.

But it has been fine ever since!

ashesman
Posts: 20
Joined: Sun Jun 02, 2019 9:25 pm

Re: ESP32-C3 Flashing fails part way

Postby ashesman » Mon Jan 09, 2023 9:51 pm

For future reference, this issue seems to be able to be solved by holding IO9 low manually during flashing. I found that answer here: https://esp32.com/viewtopic.php?f=12&t= ... 24#p108124

Lazie8
Posts: 1
Joined: Mon Mar 04, 2024 3:51 pm

Re: ESP32-C3 Flashing fails part way

Postby Lazie8 » Mon Mar 04, 2024 4:06 pm

I just had the same thing happen (running Debian 12 Linux). After quite a few successful code changes and flashes to the board today, it failed part way through the main program upload section. I tried many changes, but then remembered that I had opened the gtkterm window (a simple GUI serial port terminal) so I could use it to monitor/track a code problem I was tracing. Even though it wasn't connected to the device's USB serial port, and I closed gtkterm once I realized the flash had failed, the flash failure persisted. I reset the chip, tried erasing the flash (that failed with a timeout, too), unplugged it, manually put it in boot-mode, but nothing would bring it back.

I'm writing this for someone else searching for problem resolutions. I rebooted my computer (since it's a Linux machine, I rarely do that, maybe once every few months). That cleared up the flashing problem and all is working normally again. I'm speculating that there's some sort of persistent connection with that USB port, but not sure why. I didn't really think that would be the problem, so I didn't check to see if the gtkterm process had actually stopped - that's most likely. So, killing that process probably would have been adequate.

Thanks to everyone for a great code-base!
Doug

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: ESP32-C3 Flashing fails part way

Postby ESP_Sprite » Tue Mar 05, 2024 1:55 am

Lazie8 wrote:
Mon Mar 04, 2024 4:06 pm
I just had the same thing happen (running Debian 12 Linux).
Did you try making GPIO9 low on reset?

Who is online

Users browsing this forum: Majestic-12 [Bot] and 88 guests