USB Serial/JTAG Controller Console

On chips with an integrated USB Serial/JTAG Controller, it is possible to use the part of this controller that implements a serial port (CDC) to implement the serial console, instead of using UART with an external USB-UART bridge chip. ESP32-C3 contains this controller, providing the following functions:

  • Bidirectional serial console, which can be used with IDF Monitor or another serial monitor.

  • Flashing using esptool.py and idf.py flash.

  • JTAG debugging using e.g. OpenOCD, simultaneous with serial operations.

Note that, in contrast with the USB OTG peripheral in some Espressif chips, the USB Serial/JTAG Controller is a fixed function device, implemented entirely in hardware. This means it cannot be reconfigured to perform any function other than to provide a serial channel and JTAG debugging functionality.

Hardware Requirements

Connect ESP32-C3 to the USB port as follows:

GPIO

USB

19

D+ (green)

18

D- (white)

GND

GND (black)

+5V (red)

Some development boards may offer a USB connector for the USB Serial/JTAG Controller — in that case, no extra connections are required.

Software Configuration

USB console feature can be enabled using CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG option in menuconfig tool (see CONFIG_ESP_CONSOLE_UART).

Once the option is enabled, build the project as usual.

Alternatively, you can access the output through usb_serial_jtag port but make sure the option CONFIG_ESP_CONSOLE_SECONDARY_USB_SERIAL_JTAG in choice ESP_CONSOLE_SECONDARY is selected.

Warning

Besides output, if you also want to input or use REPL with console, please select CONFIG_ESP_CONSOLE_USB_SERIAL_JTAG.

Uploading the Application

The USB Serial/JTAG Controller is able to put the ESP32-C3 into download mode automatically. Simply flash as usual, but specify the USB Serial/JTAG Controller port on your system: idf.py flash -p PORT where PORT is the name of the proper port.

Limitations

There are several limitations to the USB Serial/JTAG console feature. These may or may not be significant, depending on the type of application being developed, and the development workflow.

1. If the application accidentally reconfigures the USB peripheral pins, or disables the USB Serial/JTAG Controller, the device will disappear from the system. After fixing the issue in the application, you will need to manually put the ESP32-C3 into download mode by pulling low GPIO9 and resetting the chip. .. note:

In rare cases it's possible that data sent from the ESP32-C3 to the host gets 'stuck' in host memory. Sending more data will get it 'unstuck', but if the application does not send more data, depending on the driver, this data needs to be flushed to the host manually. The non-blocking (default) driver and the VFS implementation will flush automatically after a newline. The blocking (interrupt-based) driver will automatically flush when its transmit buffer becomes empty.
  1. If the application enters deep sleep mode, the USB Serial/JTAG device will disappear from the system.

  2. For data sent in the direction of ESP32-C3 to PC Terminal (e.g. stdout, logs), the ESP32-C3 first writes to a small internal buffer. If this buffer becomes full (for example, if no PC Terminal is connected), the ESP32-C3 will do a one-time wait of 50ms hoping for the PC Terminal to request the data. This can appear as a very brief 'pause' in your application.

  3. For data sent in the PC Terminal to ESP32-C3 direction (e.g. console commands), many PC Terminals will wait for the ESP32-C3 to ingest the bytes before allowing you to sending more data. This is in contrast to using a USB-to-Serial (UART) bridge chip, which will always ingest the bytes and send them to a (possibly not listening) ESP32-C3.

  1. The USB Serial/JTAG controller will not work during sleep (both light and deep sleep) due to the lack of an APB and USB PHY clock during sleep. Thus, entering sleep has the following implications on the USB Serial/JTAG controller:

    1. Both the APB clock and the USB PHY clock (derived form the main PLL clock) will be disabled during sleep. As a result, the USB Serial/JTAG controller will not be able receive or respond to any USB transactions from the connected host (including periodic CDC Data IN transactions). Thus it may appear to the host that the USB Serial/JTAG controller has disconnected.

    2. If users enter sleep manually (via esp_light_sleep_start() or esp_deep_sleep_start()), users should be cognizant of the fact that USB Serial/JTAG controller will not work during sleep. ESP-IDF does not add any safety check to reject entry to sleep even if the USB Serial/JTAG controller is connected. In the case where sleep is entered while the USB Serial/JTAG controller is connected, connection can be re-established by unplugging and re-plugging the USB cable.

    3. If users enter sleep automatically (via esp_pm_configure()), enabling the CONFIG_USJ_NO_AUTO_LS_ON_CONNECTION option will allow the ESP32-C3 to automatically detect whether the USB Serial/JTAG controller is currently connected to a host, and prevent automatic entry to sleep as long as the connection persists. However, note that this option will increase power consumption.