logo elektroda
logo elektroda
X
logo elektroda

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

TvWidget 2805 30
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #1 19485282
    TvWidget
    Level 38  
    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
    khoam
    Level 42  
    You can use this controller as a serial port for monitoring (idf monitor), instead of the UART. Select CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG for CONFIG_ESP_CONSOLE_UART in sdkconfig.
    Link .
  • #3 19485480
    TvWidget
    Level 38  
    In "Component config" I only found the option "Channel for console output". There, however, USB cannot be selected.
  • #4 19485520
    khoam
    Level 42  
    Mea culpa. This option (CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG) is available in ESP-IDF version 4.4 (developer, master). It is not available in the latest, stable 4.3.
  • #5 19485609
    TvWidget
    Level 38  
    In the case of this USB Serial on the ESP32-C3, is it possible to change the descriptor ?
  • ADVERTISEMENT
  • #6 19485625
    khoam
    Level 42  
    There is nothing in the technical documentation for the ESP32-C3 about this and I don't think it is possible.
  • #7 19486141
    TvWidget
    Level 38  
    I am still puzzled by this JTAG Controller. Is it possible to enter a program via USB ?
  • ADVERTISEMENT
  • #8 19486143
    khoam
    Level 42  
    TvWidget wrote:
    I am still wondering about this JTAG Controller. Is it possible to enter the program via USB ?
    .
    Yes, this is described at the link I provided earlier.
  • #9 19486154
    TvWidget
    Level 38  
    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
    khoam
    Level 42  
    During the reset, to enter download mode the states on certain pins should be forced, as below.

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

    So the idea is mainly to force a low state on GPIO 9 during reset.
  • #11 19486292
    TvWidget
    Level 38  
    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
    khoam
    Level 42  
    TvWidget wrote:
    Do I understand correctly that the USB port will always be enabled in "Download Boot" mode and in "SPI Boot" mode
    .
    Not the USB port, but the ESP32-C3 chip itself can be set in either of these two modes. If it is set in "Download Boot" mode then it can be programmed from UART 0 or USB.

    TvWidget wrote:
    Will it not be possible to replace the firmware via USB if there is no button in it ?
    .
    In such a case, it remains possible to upload the new firmware via HTTPS OTA and WiFi.
  • #13 19486325
    TvWidget
    Level 38  
    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.
  • #14 19486334
    khoam
    Level 42  
    TvWidget wrote:
    When will the GPIO18 and GPIO19 pins be used for USB ?
    .
    In normal operation (after booting) then when the program uses these pins for that purpose. They don't have to be used as USB, they are regular GPIOs.
  • #15 19486601
    TvWidget
    Level 38  
    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
    khoam
    Level 42  
    You simply have to download or clone the "master" version from https://github.com/espressif/esp-idf.
    I don't use eclipse, but the eclipse plugin should also work with the "master" version - you need to indicate the directory where this ESP-IDF version is located. You need to update the "master" version from time to time.

    TvWidget wrote:
    Do you perhaps know when the official version 4.4 can be expected ?
    .
    I can only guess based on the release dates of the next versions so far - September?
  • #17 19486652
    TvWidget
    Level 38  
    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
    khoam
    Level 42  
    You probably downloaded the zip instead of cloning the repository with git. The mbedtls component is in another repository (https://github.com/espressif/mbedtls/tree/99c88bb7bd7c2d91c6873abd6e6d5ee04f4f164c), while the ESP-IDF repository in github only has a link to it.
    I attach the mbedtls itself, it should be in .../components/mbedtls/mbedtls/ after unzipping.
  • #19 19486676
    TvWidget
    Level 38  
    Now the lwip is missing. How to "git clone the repository" ?
  • ADVERTISEMENT
  • #21 19486935
    TvWidget
    Level 38  
    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
    khoam
    Level 42  
    You can also use Arduino Core for ESP32 version 2.0.0-alpha, which is based on ESP-IDF master and supports ESP32-C3.
    Link .
  • #23 19493333
    TvWidget
    Level 38  
    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
    khoam
    Level 42  
    TvWidget wrote:
    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 characters to be sent from the buffer ?
    .
    It would be best to check the occupancy of this buffer before sending any more characters :) .
    Quote:
    An USB-to-serial bridge chip will just send the bytes to a (not listening) chip.


    TvWidget wrote:
    I tried using JTAG Controller via USB.
    .
    Have you configured the USB driver according to Link ?
  • #25 19493397
    TvWidget
    Level 38  
    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
    khoam
    Level 42  
    I think the driver " Espressif - WinUSB support for JTAG (ESP32-C3) " is not properly installed. I don't use Windows, so a certain class of problems elude me ;) .
  • #27 19494298
    TvWidget
    Level 38  
    Or do you know from which version of ESP-IDF is EPS32-C3 supported ?
  • #29 19494523
    TvWidget
    Level 38  
    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
    khoam
    Level 42  
    And have you tried with just one argument?
    Code: Bash
    Log in, to see the code
    .
    The esp32c3-builtin.cfg script already references the relevant configuration files:
    Code: Bash
    Log in, to see the code
    .

    Added after 3 [minutes]: .

    TvWidget wrote:
    Error: libusb_open() failed with LIBUSB_ERROR_NOT_FOUND
    .
    This instead looks like a communication problem between the USB driver and the physical interface.

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.
Summary generated by the language model.
ADVERTISEMENT