esptool.py stub not working on ESP32-C3 with GPIO9=1 if USB application is already in flash (ESPTOOL-595)

jeffyx
Posts: 6
Joined: Sat Jan 14, 2023 5:55 pm

esptool.py stub not working on ESP32-C3 with GPIO9=1 if USB application is already in flash (ESPTOOL-595)

Postby jeffyx » Sun Jan 15, 2023 7:49 am

Hello,

I testing a ESP32-C3 on a AI Thinker ESP-C3-13 on a custom board using the native USB Serial/JTAG port and I am puzzled by the following behavior:

If the USB version of micropython for the C3 is loaded in flash, I can't seem to be able to use stub-based command of esptool.py unless I physically force the GPIO9 pin to 0 (to force the dowload mode and prevent micropython from starting).

esptool works ok with GPIO9=1 if I don't use the stub (--no-stub option), or if I erase the flash or put in a non-USB application (like the ESP-IDF hello world example)

Esptool does seem to be able to reset the chip over the native USB interface since it can read a bunch of infos, but it causes an exception once the stub firmware has been launched (trace below).

I suspect that when GPIO9=1, micropython launches at power up and configures the USB serial port in a way that survives the esptool reset and confuses the stub firmware. Or maybe the presence of micropython in the flash somehow interferes with the stub execution? Does the stub fail to do some initializations? Is there a conflict between the USB-controlled boot mode and strapping-pin-controlled boot? ...

Any idea of what might be going on here and what a work-around could be?

I'm designing a small board and I'd like to avoid having to add a switch to manually force GPIO9 to low in order to program the chip, even if I have an application using the native USB serial port.

I have spent the last few days reading forum and tickets to eliminate other possible problems:

- GPIO2 and GPIO8 are high as expected
- The timing of the CHIP_EN signal meets the requirements
- The power supply does not seem to be an issue (I provide 500 mA, adding local decoupling does not help, and micropython works fine even with wifi apps)
- I tried the latest esptool (v4.5.dev0) without any improvement
- I tried the esptool option "–before usb_reset" without improvement
- I have tried different baud rates

Here is a curated trace of the esptool running the chip_id command when GPIO9=1 and micropython is loaded in flash.

Code: Select all

esptool.py --port /dev/ttyACM0 --chip esp32c3 --trace --baud 115200 --before usb_reset chip_id

Code: Select all

...
TRACE +0.000 Write 18 bytes:
    c000060800000000 0000000000a20638 | ...............8
    40c0                              | @.
TRACE +0.000 Read 1 bytes: c0
TRACE +0.000 Read 13 bytes: 01060400b434000000000000c0
TRACE +0.000 Received full packet: 01060400b434000000000000
TRACE +0.001 Read 1 bytes: c0
TRACE +0.000 Read 5 bytes: 4f484149c0
TRACE +0.000 Received full packet: 4f484149
Stub running...
TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=18200060
TRACE +0.000 Write 14 bytes: c0000a04000000000018200060c0
TRACE +3.003 No serial data received.
TRACE +0.000 Unable to verify flash chip connection (No serial data received.).
TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=18200060
TRACE +0.000 Write 14 bytes: c0000a04000000000018200060c0
TRACE +0.000 Unable to perform XMC flash chip startup sequence ().
Warning: ESP32-C3 has no Chip ID. Reading MAC instead.
TRACE +0.000 command op=0x0a data len=4 wait_response=1 timeout=3.000 data=44880060
TRACE +0.000 Write 14 bytes: c0000a04000000000044880060c0
Traceback (most recent call last):
  File "/home/jfcliche/.espressif/python_env/idf5.1_py3.10_env/lib/python3.10/site-packages/esptool/cmds.py", line 969, in chip_id
    chipid = esp.chip_id()
  File "/home/jfcliche/.espressif/python_env/idf5.1_py3.10_env/lib/python3.10/site-packages/esptool/targets/esp32.py", line 287, in chip_id
    raise NotSupportedError(self, "chip_id")
esptool.util.NotSupportedError: Function chip_id is not supported for ESP32-C3.

During handling of the above exception, another exception occurred:


Traceback (most recent call last):
...
  File "/home/jfcliche/.espressif/python_env/idf5.1_py3.10_env/lib/python3.10/site-packages/esptool/loader.py", line 690, in read_reg
    val, data = self.command(
  File "/home/jfcliche/.espressif/python_env/idf5.1_py3.10_env/lib/python3.10/site-packages/esptool/loader.py", line 376, in command
    p = self.read()
  File "/home/jfcliche/.espressif/python_env/idf5.1_py3.10_env/lib/python3.10/site-packages/esptool/loader.py", line 308, in read
    return next(self._slip_reader)
StopIteration
Thanks.

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

Re: esptool.py stub not working on ESP32-C3 with GPIO9=1 if USB application is already in flash

Postby ESP_Sprite » Mon Jan 16, 2023 2:11 am

Curious. What specific MicroPython binary do you use?

jeffyx
Posts: 6
Joined: Sat Jan 14, 2023 5:55 pm

Re: esptool.py stub not working on ESP32-C3 with GPIO9=1 if USB application is already in flash

Postby jeffyx » Mon Jan 16, 2023 11:28 pm

I use the Micropython image esp32c3-usb-20220618-v1.19.1.bin.

I flash the ESP32-C3 with:

Code: Select all

esptool.py --port /dev/ttyACM0 write_flash -z 0x0 esp32c3-usb-20220618-v1.19.1.bin
Edit: I discovered that if I disable transmission compression (-z), I then can use the --no-stub option and then I gen no error.

Code: Select all

esptool.py --port /dev/ttyACM0 --no-stub write_flash  0x0 esp32c3-usb-20220618-v1.19.1.bin

ESP_pdragun
Posts: 12
Joined: Fri Dec 02, 2022 2:18 pm

Re: esptool.py stub not working on ESP32-C3 with GPIO9=1 if USB application is already in flash (ESPTOOL-595)

Postby ESP_pdragun » Mon Jan 23, 2023 2:44 pm

Hi,
thank you for reporting and providing all the details about the issue. I was able to reproduce it. We will take care of it.

jeffyx
Posts: 6
Joined: Sat Jan 14, 2023 5:55 pm

Re: esptool.py stub not working on ESP32-C3 with GPIO9=1 if USB application is already in flash (ESPTOOL-595)

Postby jeffyx » Tue Jan 24, 2023 1:42 am

Thanks for the reply and I'm happy the issue could be replicated. This seems to be issue/ticket material. Is there issue I can follow or should I open one on esp-idf GitHub?

User avatar
ESP_Roland
Posts: 265
Joined: Tue Oct 09, 2018 10:28 am

Re: esptool.py stub not working on ESP32-C3 with GPIO9=1 if USB application is already in flash (ESPTOOL-595)

Postby ESP_Roland » Tue Jan 24, 2023 6:00 am

I have added the internal tracking number to the title. We will get back to you if that is fine with you. If not then feel free to open an issue in the esptool project - but please mention that it is a duplicate of this forum report.

jeffyx
Posts: 6
Joined: Sat Jan 14, 2023 5:55 pm

Re: esptool.py stub not working on ESP32-C3 with GPIO9=1 if USB application is already in flash (ESPTOOL-595)

Postby jeffyx » Tue Jan 24, 2023 3:10 pm

Got it. That's great. Let me know if I can be of assistance.
JF

ESP_pdragun
Posts: 12
Joined: Fri Dec 02, 2022 2:18 pm

Re: esptool.py stub not working on ESP32-C3 with GPIO9=1 if USB application is already in flash (ESPTOOL-595)

Postby ESP_pdragun » Mon Mar 06, 2023 2:09 pm

Hi,

can you please try latest version of esptool v4.5.1? I was able to flash it using this version without any issues.

If you want to know more about this issue you can follow https://github.com/espressif/esptool/issues/842 and https://github.com/espressif/esptool/issues/848
This fix is just a workaround for the feature but there will be a proper fix comming soon.

Let me know if that helped.

jeffyx
Posts: 6
Joined: Sat Jan 14, 2023 5:55 pm

Re: esptool.py stub not working on ESP32-C3 with GPIO9=1 if USB application is already in flash (ESPTOOL-595)

Postby jeffyx » Mon Mar 06, 2023 10:32 pm

Hi,
I pulled tag 4.5.1 (confirmed by git describe) and confirmed I was running the right version. However I still see the same problem. I erased the flash, and could run commands with the stub. But once I installed Micropython (USB version) I have to use --no-stub.

Code: Select all

(esp_venv) $ esptool.py --port /dev/ttyACM0 --chip esp32c3 chip_id
esptool.py v4.5.1
Serial port /dev/ttyACM0
Connecting...
Chip is ESP32-C3 (revision v0.3)
Features: WiFi, BLE
Crystal is 40MHz
MAC: 34:b4:72:49:36:80
Uploading stub...
Running stub...
Stub running...

A fatal error occurred: Unable to verify flash chip connection (No serial data received.).
The referred Github issues relate to the S3. Has the stub of the C3 been recompiled as well? I can see that the change of clock speed could have an impact here, as the manuals specify that the USB port required a very specific clock frequency to operate properly.

JF

ESP_pdragun
Posts: 12
Joined: Fri Dec 02, 2022 2:18 pm

Re: esptool.py stub not working on ESP32-C3 with GPIO9=1 if USB application is already in flash (ESPTOOL-595)

Postby ESP_pdragun » Tue Mar 07, 2023 4:19 pm

Sorry. yes, you are right, those are not related. I got confused because it suddenly started working for me with the latest esptool and the only difference was this commit basically. During checking the diff I somehow replaced S3 with C3.

The reason why it worked for me was that I started in bootloader mode. So flashing the micropython was working as expected, but then the chip was not reset (even if reset seq was executed) and stayed in bootloader mode. So running any command after this would succeed, as you mentioned, in bootloader mode it works. But after disconnecting and connecting the chip again it is not working.

At this point, I am not sure what the reason could be. I will try to investigate more.

Who is online

Users browsing this forum: Baidu [Spider], cdollar, Google [Bot], MicroController and 191 guests