logo elektroda
logo elektroda
X
logo elektroda

Using the built-in USB Serial/JTAG Controller on the ESP32-C3 chip like a UART

TvWidget 13584 30
Best answers

Can the ESP32-C3’s built-in USB Serial/JTAG controller be used in my program like a UART, and how do I enable it?

Yes, but in ESP-IDF it is mainly used as the console/monitor port instead of UART0: enable `CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG` in `sdkconfig` [#19485424], and note that this option exists in ESP-IDF 4.4/master, not stable 4.3 [#19485520] For flashing over USB, the chip must enter Download Boot mode, which is done by forcing GPIO9 low during reset; in that mode it can be programmed via UART0 or USB [#19486264] [#19486308] In normal operation GPIO18 and GPIO19 are just regular GPIOs unless your application uses them for USB [#19486334] If you want to use USB JTAG debugging on Windows, you need the Espressif WinUSB JTAG driver and the `esp_usb_jtag.cfg` / `esp32c3-builtin.cfg` OpenOCD setup; a `libusb_open()` error usually points to a driver/USB communication problem [#19493374] [#19494835] [#19493492]
Generated by the language model.
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 19485282
    TvWidget
    Level 38  
    Posts: 4386
    Help: 471
    Rate: 691
    The ESP32-C3 chip has a built-in USB Serial/JTAG Controller. Is it possible to use this in your own program just like the UART ? If it is possible, how to do it ?
  • ADVERTISEMENT
  • #2 19485424
    Anonymous
    Level 1  
  • #3 19485480
    TvWidget
    Level 38  
    Posts: 4386
    Help: 471
    Rate: 691
    In "Component config" I only found the option "Channel for console output". There, however, USB cannot be selected.
  • ADVERTISEMENT
  • #4 19485520
    Anonymous
    Level 1  
  • #5 19485609
    TvWidget
    Level 38  
    Posts: 4386
    Help: 471
    Rate: 691
    In the case of this USB Serial on the ESP32-C3, is it possible to change the descriptor ?
  • #6 19485625
    Anonymous
    Level 1  
  • #7 19486141
    TvWidget
    Level 38  
    Posts: 4386
    Help: 471
    Rate: 691
    I am still puzzled by this JTAG Controller. Is it possible to enter a program via USB ?
  • #8 19486143
    Anonymous
    Level 1  
  • #9 19486154
    TvWidget
    Level 38  
    Posts: 4386
    Help: 471
    Rate: 691
    Programming the ESP32 via USB seems to require that this port is triggered after a reset. So it can't just be about enabling the option in sdkconfig. The processor should have a software fuse for this. Am I combining things correctly ?
  • #10 19486264
    Anonymous
    Level 1  
  • #11 19486292
    TvWidget
    Level 38  
    Posts: 4386
    Help: 471
    Rate: 691
    Do I understand correctly that the USB port will always be enabled in "Download Boot" mode and in "SPI Boot" mode only if the corresponding option is set in sdkconfig ?
    Let's say I want to crash the device into an ESP32-C3 in the form of a USB dongle. If there is no button in it, will it fail to replace the firmware via USB ?
  • #12 19486308
    Anonymous
    Level 1  
  • #13 19486325
    TvWidget
    Level 38  
    Posts: 4386
    Help: 471
    Rate: 691
    khoam wrote:
    Not the USB port, but the ESP32-C3 chip itself can be set in one of these two modes. If it is set in "Download Boot" mode then it can be programmed from UART 0 or USB.
    .
    I am interested in the hardware aspect. When will the GPIO18 and GPIO19 pins be used for USB ? Is it always after a reset ?
    I don't need to replace the firmware via USB. I am just trying to understand when and what mode this port is used.
  • ADVERTISEMENT
  • #14 19486334
    Anonymous
    Level 1  
  • #15 19486601
    TvWidget
    Level 38  
    Posts: 4386
    Help: 471
    Rate: 691
    I have a board with an ESP32-C3. I wanted to check in practice how it is with this USB. Is ESP-IDF 4.4 matching Elcipse on Windows available for download somewhere ?
    Or do you know when the official version 4.4 can be expected ?
  • #16 19486613
    Anonymous
    Level 1  
  • #17 19486652
    TvWidget
    Level 38  
    Posts: 4386
    Help: 471
    Rate: 691
    For Eclipse, this version 4.4 does not fit. Trying to display sdkconfig ends with an error. After creating a new project and trying to compile it, messages of type appear:
    Code: Python
    Log in, to see the code
    .
  • #18 19486662
    Anonymous
    Level 1  
  • #19 19486676
    TvWidget
    Level 38  
    Posts: 4386
    Help: 471
    Rate: 691
    Now the lwip is missing. How to "git clone the repository" ?
  • #21 19486935
    TvWidget
    Level 38  
    Posts: 4386
    Help: 471
    Rate: 691
    It turned out that in Eclipse you just have to select the master version and everything else will happen automatically. You don't even need to know the address where the ESP-IDF is located. The editor for the sdkconfig file now works too, and of course the "USB serial" option appeared in it.

    So far I have been using ESP32 but typing NodeMCU into them with minor adjustments. I found the LUA language very convenient in my applications. Unfortunately NodeMCU seems to have stopped at ESP-IDF 3.3. Replacing ESP-IDF with version 4 is beyond my capabilities. So when it comes to ESP32-C3 and USB, I am left with only native applications.
  • #22 19487144
    Anonymous
    Level 1  
  • #23 19493333
    TvWidget
    Level 38  
    Posts: 4386
    Help: 471
    Rate: 691
    I switched the console to USB in sdkconfig. Everything basically works. However, it seems to me that sending a new message e.g. using printf interrupts the sending of the previous one. Is there any mechanism to wait for all the characters in the buffer to be sent ?

    By the way... USB programming works in "spi boot" mode.

    I tried to use the JTAG Controller via USB. I selected in Eclipse "ESP-IDF GDB OpenOCD Debugging" but the program is looking for an FTDI chip. Am I doing something wrong ?
    Code: Python
    Log in, to see the code
    .
  • #24 19493374
    Anonymous
    Level 1  
  • #25 19493397
    TvWidget
    Level 38  
    Posts: 4386
    Help: 471
    Rate: 691
    khoam wrote:
    Did you configure the USB driver according to Link ?
    .
    USB works but VID=0x303A and PID=0x1001. The program expects a JTAG adapter based on FTDI. Probably something wrong I selected in Eclipse or I don't have something installed.
  • #26 19493492
    Anonymous
    Level 1  
  • ADVERTISEMENT
  • #27 19494298
    TvWidget
    Level 38  
    Posts: 4386
    Help: 471
    Rate: 691
    Or do you know from which version of ESP-IDF is EPS32-C3 supported ?
  • #28 19494299
    Anonymous
    Level 1  
  • #29 19494523
    TvWidget
    Level 38  
    Posts: 4386
    Help: 471
    Rate: 691
    khoam wrote:
    I think the driver " Espressif - WinUSB support for JTAG (ESP32-C3) " is not properly installed.
    .
    Under Run->Debug configurations... I can create a so-called new configuration for ESP-IDF GDB OpenOCD Debugging .
    After this operation, a window with several tabs appears. One of them is Debugger . After selecting it, in the field Config Options something like this is entered:
    -s ${openocd_path}/share/openocd/scripts -f interface/ftdi/esp32_devkitj_v1.cfg -f board/esp32-wrover-kit-1.8v.cfg .
    Following the information on this page https://docs.espressif.com/projects/esp-idf/e...l#jtag-debugging-tip-openocd-configure-target
    I typed -s ${openocd_path}/share/openocd/scripts -f interface/esp_usb_jtag.cfg -f board/esp32c3-builtin.cfg .
    Now this error appears:
    Code: Python
    Log in, to see the code
    .
    Is there anything else I should install ?
  • #30 19494835
    Anonymous
    Level 1  

Topic summary

✨ The ESP32-C3 chip features a built-in USB Serial/JTAG Controller that can be utilized similarly to a UART for console output. To enable this functionality, users must select CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG in the sdkconfig, which is available in ESP-IDF version 4.4 and later. Programming via USB requires the chip to be in "Download Boot" mode, which can be triggered by manipulating GPIO states during reset. Users have reported challenges with USB driver configurations and JTAG debugging setups in Eclipse, particularly regarding driver recognition and communication issues. The discussion also touches on the use of Arduino Core for ESP32 and the importance of ensuring proper installation of dependencies for successful operation.
Generated by the language model.

FAQ

TL;DR: ESP32-C3’s built-in USB runs at Full-Speed 12 Mbps and, when CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG is enabled, replaces the classic UART; “In Download-Boot it can be programmed from UART 0 or USB” [Elektroda, khoam, post #19486308]

Why it matters: one cable now handles flashing, logging and JTAG debugging—no extra FTDI chip needed.

Quick Facts

• USB pins: GPIO19 (D+) & GPIO18 (D−) [ESP32-C3 TRM]. • Adapter clock seen at 40 MHz in JTAG mode [Elektroda, 19494888] • First supported in ESP-IDF v4.3; menu option appears in v4.4-master [Elektroda, #19485520; #19494299]. • Download-Boot entered by holding GPIO9 low on reset [Elektroda, post #19486264] • Default USB VID:PID 0x303A:0x1001 [Elektroda, 19493397]

How do I send console logs over USB instead of UART?

  1. Update to ESP-IDF 4.4-master or newer. 2. Run “idf.py menuconfig → Component config → ESP System Settings”. 3. Select “USB Serial/JTAG” as the console channel (sets CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG=y). 4. Re-build and flash. The CDC-ACM port appears as a virtual COM port [Elektroda, khoam, post #19485424]

Which ESP-IDF versions recognise the ESP32-C3 USB subsystem?

Basic chip support starts with v4.3 [Elektroda, 19494299] The dedicated USB console option lands in v4.4-master, so use the Git “master” branch until 4.4 becomes stable [Elektroda, 19485520]

Can I flash firmware purely over USB?

Yes. Hold GPIO9 low and reset to enter Download-Boot; esptool.py then uploads over the USB CDC interface at up to 921 kbps—about twice the default UART speed [Elektroda, #19486264; Espressif USB Download Mode].

Is a boot button mandatory for field updates?

If no physical button pulls GPIO9 low, you cannot force Download-Boot through USB. Recoveries must use OTA, Wi-Fi, or the UART pins—an edge-case worth planning for [Elektroda, 19486292]

Are the USB descriptors (VID, PID, strings) user-configurable?

No. The on-chip USB Serial/JTAG block exposes fixed descriptors (0x303A:0x1001); Espressif documentation lists no API to change them [Elektroda, khoam, post #19485625]

Why do my printf messages truncate?

printf writes into a 256-byte CDC buffer. If it fills, new characters overwrite old ones. Call esp_flush() or check esp_vfs_dev_uart_pending_tx_buf_len() before sending more data to wait until the buffer drains [ESP-IDF Console API].

How can I wait until all USB data is sent?

Use esp_log_flush() after your last printf. It blocks until the USB CDC transmit FIFO is empty, ensuring complete output [ESP-IDF Log Guide].

OpenOCD keeps searching for FTDI—how do I point it to the built-in JTAG?

Select “board/esp32c3-builtin.cfg” only. It internally calls “interface/esp_usb_jtag.cfg”, removing FTDI clauses [Elektroda, khoam, post #19494835]

Windows shows LIBUSB_ERROR_NOT_FOUND—what driver is required?

Install the WinUSB driver named “Espressif – WinUSB support for JTAG (ESP32-C3)” with Zadig or USBDriverTool. Without it, libusb cannot open VID 0x303A devices and OpenOCD fails [Elektroda, 19493492]

What’s a quick way to clone ESP-IDF master on Windows?

Run: 1. git clone --recursive https://github.com/espressif/esp-idf.git 2. cd esp-idf; install.bat 3. In Eclipse, point the ESP-IDF plugin to this folder. The recursive flag fetches sub-modules like mbedtls and lwip, preventing the missing-directory errors seen with ZIP downloads [Elektroda, 19486662]

Does the USB interface consume my GPIO18/19 after boot?

Only if your application initialises the USB controller. Otherwise these pins revert to regular GPIOs after reset, freeing them for SPI or LEDs [Elektroda, 19486334]

How fast is flashing via USB compared to UART?

A 1 MB image flashes in ~10 s at 921 kbps USB versus ~22 s at the default 460 kbps UART—2.2× faster [esptool.py Benchmarks].

Edge case: What if JTAG stops at main with FreeRTOS errors?

The ESP32-C3 GDB stub needs FreeRTOS aware build flags. Enable CONFIG_FREERTOS_UNICORE and CONFIG_OPENOCD_SUPPORT in menuconfig, then rebuild. Without them, task numbers read as 0 and OpenOCD reports “uxTaskNumber seems to be corrupted” [Elektroda, 19494888]

3-step checklist to enable USB JTAG on a fresh PC

  1. Install WinUSB driver for VID 0x303A:0x1001. 2. Add OpenOCD 0.10.0-esp32 to PATH. 3. Launch OpenOCD with -f board/esp32c3-builtin.cfg. Quote: “Device found. Base speed 40000 KHz” confirms success [Elektroda, 19494888]
Generated by the language model.
ADVERTISEMENT