USB

[中文]


Does ESP32 support USB function?

  • No, ESP32 does not support USB function.

  • However, ESP32-S2/S3 supports USB2.0 Full-speed mode.

  • ESP32-P4 supports USB2.0 High-speed and Full-speed modes.


Does the ESP-IDF SDK USB interface support HID and MSC modes?

  • ESP32S2/S3 can be used as MSC Host to support reading from or writing to storage devices such as USB flash disks. For details, please refer to esp-idf.

  • ESP32S2/S3 can be used as MSC Device to simulate storage of USB flash disks. For details, please refer to esp-iot-solution.

  • ESP32S2/S3 can be used as HID Host. For details, please refer to ESP-IDF Host HID.

  • ESP32S2/S3 can be used as HID Device. For details, please refer to ESP-IDF Device HID.


What is the stable current output for ESP32-S2’s USB interface?

The current output capability of the VBUS power line is determined by the power supply, not by the ESP32-S2 chip. If the chip is self-powered, please refer to Self-Powered Device.


Does ESP32-S3’s USB peripheral supports USB Host?

Yes, regarding this function, ESP32-S3 is the same as ESP32-S2.


Does ESP32-C3 USB support USB serial port function and USB JTAG function?

Yes, but you cannot define the descriptor by yourself.


What are the USB features of ESP32-S2 and ESP32-S3?

ESP32-S3 and ESP32-S2 support USB 2.0 OTG (supporting full-speed mode), and both support Host and Device functions. On top of that, ESP32-S3 also supports USB-Serial-JTAG peripheral, which can be used to download and debug firmware.


Are there any references to the library and demo of ESP32-S2 USB Host?

Please refer to USB Host in ESP-IDF.


The USB protocol supported by ESP32-S2 is OTG 1.1, with the maximum speed of 12 Mbps. Can it communicate with USB 2.0 devices?

In the full speed mode, USB 2.0 devices are compatible with USB 1.1 devices, so they can communicate with each other.


Does ESP32-S2/S3 support USB cameras?

Supported. For ESP32-S2/ESP32-S3 USB Host UVC example code, please refer to usb_hub_dual_camera. This example can connect to a single USB camera, or multiple USB cameras through a HUB.


Does ESP32-S3 support USB cameras with microphones and speakers?

Supported. Please refer to the example codes for ESP32-S2/ESP32-S3 respectively:


Is there any reference for the example of using ESP32S2 as a USB flash drive (MSC DEVICE)?

Please refer to usb_msc_wireless_disk demo. The average read and write speed currently tested is: read 540 KB/s, write 350 KB/s.


As ESP32-C3 already has USB function, can I download firmware directly via USB without using the cp2102 chip?

Yes, ESP32-C3 can download firmware via USB, The USB serial port number should be displayed as COMx on Windows devices and ttyACMx on Linux devices.


Does ESP32-C3 support USB Host?

No, it only supports USB-Serial-JTAG function and can only be used as the USB device.


The ESP32-C3 chip can use USB to download firmware, but it is not supported under ESP-IDF v4.3. How to use USB to download firmware?

You need to compile under ESP-IDF v4.4 or later versions. After pulling the latest branch and updating the IDF tool, you can compile normally and download it using USB. Please refer to usb-serial-jtag-console for the usage.


Does the ESP32-S2 support USB HID?

Yes. For the example of USB HID Device, please refer to ESP-IDF Device HID. For the example of USB HID Host, please refer to ESP-IDF Host HID example.


Why is this error log printed when I am testing the USB Camera + Wi-Fi Transfer example?

E (1437) UVC STREAM: Configuration descriptor larger than control transfer max length

This error log is reported because the length of the descriptor sent by the USB Camera is larger than the default length (256). You can modify the following configuration to 2048 for testing:

Component config > UVC Stream > (2048) Max control transfer data size (Bytes)


Does ESP32-S3 support USB CDC for printing program log and downloading firmware?

Yes, ESP32-S3 supports printing program log and downloading firmware using USB CDC when the following configuration option is enabled:

Component config > ESP System Settings > Channel for console output > USB CDC


Does ESP32-S3 support devices with USB Device being Class 0?

Supported, you can refer to the example: esp-idf/components/tinyusb/additions/src/usb_descriptors.c. When Class code == 00H, the class category is specified by the interface.


Can the ESP32-S3’s USB OTG interface be used in both USB Host and USB Device modes?

  • The ESP32-S3’s USB OTG interface can not be used as USB Host and USB Device at the same time. However, it is possible to switch between the USB Host mode and the USB Device mode by software.

  • If you need the standard negotiation function of USB OTG, please note that currently ESP32-S3 only supports this function on the hardware, and does not support it in software protocol.


When testing the esp-idf/examples/peripherals/usb/device/tusb_serial_device example to send data using TinyUSB, do I have to use the tinyusb_cdcacm_write_flush() function?

To prevent sending FIFO overflows, you can use the ‘tinyusb_cdcacm_write_flush()’ function to flush. However, a large number of cycles of flushing may fail. So, it is recommended to set it according to the actual application.


Can ESP32-S3 use an external USB hub chip with two of its USB ports connecting to a USB 4G module and a dongle at the same time?

Supported. Two devices can be connected to the ESP32-S3 chip via a USB hub. For the implementation of the USB 4G module, please refer to 4G Internet Solution; for the encryption dog, you need to develop the corresponding USB Host driver according to the device type.


When ESP32-S2/ESP32-S3 serves as the UVC Host and connects some models of UVC cameras, why is there an error HID_PIPI_EVENT_ERROR_OVERFLOW in the log?

This is because MPS of the Alt interface endpoint of the selected camera is too large (ESP32-S2/ESP32-S3 supports up to 512 bytes). Please confirm whether the camera has an interface of less than or equal to 512 bytes under USB1.1.


Does ESP32-S2/ESP32-S3 support USB 4G Internet access solutions?

Yes, depending on the support of the 4G module, refer to (ECM/RNDIS recommended):


Why can’t I access the internet or successfully ping after obtaining an IP using ECM/RNDIS to connect to the 4G module?

  • Check if the auto-dial function in ECM/RNDIS mode has been activated. For details, please refer to the corresponding module’s datasheet.

  • Check if the SIM card is properly inserted and whether it has been successfully registered to the network.


What is the reason for the 4G module printing No ECM interface found for device VID: xxxx, PID: xxxx, ignore it after connecting to USB?

The reason is that the ECM interface was not recognized. Please check whether the module has been correctly set to ECM mode. For details, please refer to the documentation of the corresponding module.


What is the reason for the E (887) HCD DWC: EP MPS (512) exceeds supported limit (408) printout after connecting the 4G module to USB?

The USB endpoint MPS of this module exceeds the size allowed by the ESP chip hardware, please try:

  • Connect using the RNDIS protocol.

  • Replace with another 4G module.

  • Using the ESP32-P4 chip, this chip supports a larger USB endpoint MPS.


Does it support connecting a 4G module and a USB sound card simultaneously using a USB HUB?

Supported. It is recommended to use 4G modules with RNDIS/ECM protocol and USB UAC sound cards. Refer to 4G Internet Solution and USB UAC Sound Card Example respectively.


Is there a limit to the number of devices that can be connected via a USB HUB?

There are hardware limitations. The ESP32-S2/ESP32-S3 USB Host peripheral has 8 channels; the ESP32-P4 USB Host HS peripheral has 16 channels; the ESP32-P4 USB Host FS peripheral has 8 channels. One endpoint of a device will occupy one channel, and the HUB itself will also occupy a certain number of channels. Therefore, the actual number of connectable USB devices depends on the number of device endpoints and the number of channels occupied by the HUB.


Is there any USB CDC Host example for ESP32-S2/ESP32-S3?


When burning firmware through the ESP32-C3/ESP32-S3 USB Serial/JTAG Controller function, I found that the PC sometimes cannot recognize the USB serial port, or automatically disconnects from the USB serial port repeatedly after recognizing it. What is the reason?

At present, the startup logic of the ESP32/ESP32-S2/ESP32-S3/ESP32-C3 chip is: if it cannot start normally (due to empty flash, no correct data/firmware in flash, the power-on sequence problem of flash, etc.), the internal timer will trigger the chip to restart every few seconds. The chip cannot connect stably until the program starts normally or enters the download mode. The ESP32-S3/ESP32-C3 USB-Serial-JTAG peripheral will be re-initialized when the chip restarts, so the corresponding result is that the chip tries to connect to and disconnects from the PC every few seconds. We provide the following two solutions:

  • You need to boot the chip to enter the download mode manually before the first download or after flash is erased, so that the chip can be connected stably.

  • You can also burn the firmware that can run stably through UART in advance to solve this issue. If there is firmware that can run stably in the chip, the USB serial port of the chip can be connected stably in subsequent programming.

If there is no strap pin test point reserved for booting manually, you may need to try several times in the initial USB download.


Why does ESP32-S2/ESP32-S3 not reach the maximum USB full speed, 12 Mbps?

We will explain this issue with the TinyUSB protocol stack as an example. As this USB mode does not use DMA, but directly uses CPU polling, some time slices are wasted in each transfer. As a result, the TinyUSB protocol stack is only expected to reach 6.4 Mbps (it can reach 9.628 Mbps theoretically if the batch transfer is adopted).


How can I confirm if ESP32-S2/ESP32-S3 USB supports a certain USB camera or not?

ESP32-S2/ESP32-S3 USB only supports USB cameras that correspond to wMaxPacketSize Video Streaming endpoints which include 512 bytes at the maximum. You can use USB Stream Example to test. An error log will be printed if the camera is not supported.


What is the maximum resolution of USB cameras that ESP32-S2/ESP32-S3 support?

  • If we do not consider local JPEG decoding, the bottleneck is the throughput rate of USB. The USB camera generally adopts synchronous transmission. ESP USB has a limitation of FIFO size, which can reach 500 KB/s at the maximum currently. Thus, if you want to achieve 15 frames, the size of each frame can only be 33 KB. The maximum resolution that can be achieved by 33 KB depends on the compression rate, and generally it can reach 480 * 320.

  • If you take local JPEG decoding into consideration, you also need to consider whether this resolution can reach 15 frames per second.


Can the ESP32-S2/ESP32-S3 USB recognize the USB plugging and unplugging action when it is used as a USB CDC Device?

  • Yes, the USB device uses the tinyusb protocol stack, including mount and umount callback functions to response the USB plugging and unplugging events.

  • Please note that if the device is a self-powered USB device and you need to detect the plug and unplug action without power off, please reserve the VBUS detection pin. Refer to the Self-Powered USB Device Solution.


After enabling the RNDIS and CDC functions on the ESP32-S3 USB, I found that the PC can recognize the COM port. However, the automatic programming function of the COM port is invalid. Is it expected?

  • Yes. The USB auto-programming function is implemented through the USB-Seial-JTAG peripheral, and the USB RNDIS function is implemented through the USB-OTG peripheral. However, only one of the two peripherals can work at a moment.

  • If the USB-OTG peripheral is used in the application, the automatic programming function implemented by the USB-Seial-JTAG peripheral will not be available. But you can manually enter the download mode for USB burning.

  • Please refer to the USB-Serial-JTAG Peripheral Introduction.


Does ESP32-S2/ESP32-S3 support the USB CDC NCM protocol?

Please refer to the USB NCM example.


After I initialize the USB pins of ESP32-C3/ESP32-S3 to GPIO or other peripheral pins, why cannot I burn firmware through USB?

The USB pin of the ESP32-C3/ESP32-S3 can be initialized to GPIO or other peripheral pins. However, please note that after the initialization, the original USB download function will be disconnected, and the download mode cannot be entered automatically through USB. But you can manually pull down the Boot pin (GPIO9 in ESP32-C3 and GPIO0 in ESP32-S3) to make ESP32-C3/ESP32-S3 enter the download mode. Then you can download firmware through USB.


What should I pay attention to if I want to use the USB interface of ESP32-C3/ESP32-S3 as the unique download interface of firmware?

  • DO NOT use USB pins of ESP32-C3 (GPIO18 and GPIO19) / ESP32-S3 (GPIO19 and GPIO20) as other peripheral functions.

  • If the USB pins have to be reused as other functions in the application, the BOOT pin (GPIO9 in ESP32-C3, GPIO0 in ESP32-S3) must be wired to manually enter the chip into the download mode.


When I attempted to download and print log via the USB interface using the command idf.py -p com35 flash monitor on Windows, I encountered the following error. What’s the reason for it?

  • The error is as follows:

Connecting...
Failed to get PID of a device on com35, using standard reset sequence.
  • On Windows, the COM port must be configured in the upper case, not the lower case com.


How can I apply for USB VID/PID for ESP32-S series products?

If your software is based on the TinyUSB protocol stack, you can use the default TinyUSB PID. Otherwise, you need to apply for a USB VID/PID for each ESP32-S series product. For detailed instructions, please refer to “usb-pids”.


Is it possible to fix the COM port when downloading firmware using the USB-Serial-JTAG interface on Windows?

  • Please open the Windows CMD as the administrator and execute the following command to add a registry entry. In this way, you can prevent incremental numbering based on the Serial number. Then you need to restart the computer to enable the modification.

REG ADD HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\usbflags\303A10010101 /V IgnoreHWSerNum /t REG_BINARY /d 01

Can a USB drive be used for OTA upgrades?

Yes, it can be done using the component esp_msc_ota.


Does the ESP32 series chip support USB 2.0 High-Speed mode (480 Mbps)?

Currently, only ESP32-P4 supports USB 2.0 High-Speed mode.


How to improve the transmission rate of ESP32-S3 USB?

To enhance the transmission performance of USB, you can use the USB bulk transfer method, as well as increase the amount of data transferred per packet.


Does the USB interface of ESP32-S3 support USB charging function?

Not supported, currently the USB PD (USB-PowerDelivery) protocol is not supported.


A USB disk application is implemented based on the ESP32-S3 USB interface. Can the ESP32-S3 USB disk always appear as the Z: drive when plugged into a PC?

  • The drive letter is automatically assigned by the operating system and cannot be fixed by the software on ESP32-S3.

  • Drive Letter Assignment: The operating system will assign an unused drive letter to the USB disk based on the existing drive letters in the current system. In Windows systems, common drive letters are English letters from A to Z. Generally, A and B are traditionally reserved for floppy disk drives, C is usually the system disk, and the remaining letters are sequentially assigned to other storage devices (including hard disk partitions, optical drives, and external USB drives, etc.).


How does a USB UAC device synchronize with the host’s audio?

Since the USB bus is not a clock bus, the interval of each transmission is not fixed, so UAC devices may experience audio and video desynchronization, noise, and other phenomena. It is recommended to synchronize with the host using the feedback endpoint, and let the host send more or less data through the feedback endpoint to achieve audio synchronization.

The usb_device_uac component now supports the feedback endpoint. You can refer to the example code of this component to implement audio synchronization for the USB UAC device.


Does ESP32-P4 support USB?

Supported, ESP32-P4 has USB HS PHY and USB FS PHY as well as a USB-Serial-JTAG interface.


How to Use USB FS PHY as a Host with ESP32-P4?

When calling the USB host initialization function usb_host_install, you can use the USB FS PHY as the host by setting the value of peripheral_map in the structure parameter to BIT1.


Which two IOs are used when ESP32-P4 uses USB FS PHY as a host?

The default is IO26/IO27, which can be switched to IO24/IO25 by burning the efuse bit USB_PHY_SEL.


Can the two IO pins of the USB High-Speed PHY on ESP32-P4 be used as regular IO pins?

The USB_D- and USB_D+ of the high-speed USB2.0 OTG interface use dedicated digital pins, with pin numbers 49-50, and do not support use as regular IO ports.



Does the Espressif USB host protocol stack support HUB? How to use it?

Yes, the HUB function is supported in the low-level driver. To enable it, please set the macro CONFIG_USB_HOST_HUBS_SUPPORTED=y.


Can the Serial-JTAG and Full-Speed USB pins be adjusted on the ESP32-P4?

By default, FS_PHY1 is connected to USB_SERIAL_JTAG, and FS_PHY2 is connected to OTG_FS. The connection can be changed through EFUSE_USB_PHY_SEL.


Is the High-Speed USB of ESP32-P4 available for programming?

After entering download mode, programming can be done via High-Speed USB.