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