examples/peripherals/usb/host/cdc/README.md
| Supported Targets | ESP32-H4 | ESP32-P4 | ESP32-S2 | ESP32-S3 |
|---|
(See the README.md file in the upper level 'examples' directory for more information about examples.)
This example demonstrates how to use the CDC-ACM Host Driver together with VCP drivers to enable an ESP chip to communicate with USB CDC devices, including vendor-specific USB-to-UART converters (e.g., CP210x, FTDI FT23x, CH34x). CDC-ACM is a USB device class specification that allows USB devices to appear as serial ports, commonly used by USB-to-UART converters and virtual COM port devices.
The example performs the following operations:
Follow instructions in examples/usb/README.md for specific hardware setup.
Prepare the USB CDC device:
Connect the CDC device to the USB Host port
Build this project and flash it to the USB host board, then run monitor tool to view serial output:
idf.py -p PORT flash monitor
(Replace PORT with the name of the serial port to use.)
(To exit the serial monitor, type Ctrl-]. To stop the example, press the Boot button on the board.)
See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
After flashing and connecting a CDC device, you should see output similar to the following in the idf monitor:
I (256) usb_task: Running USB task
I (256) usb_task: - Installing USB Host
I (266) usb_task: - Installing CDC-ACM driver
I (276) app_main: Waiting for CDC devices. Press Boot button to quit.
I (584) USB-CDC: New CDC device connected VID=0x10C4 PID=0xEA60
I (594) USB-CDC: CDC device opened (slot 0). Descriptor:
...
I (1154) USB-CDC: Testing data transmission
I (1174) USB-CDC: - Data received (slot 0)
I (1174) USB-CDC: 0x4ffbf640 43 44 43 20 74 65 73 74 20 73 74 72 69 6e 67 21 |CDC test string!|
I (1274) USB-CDC: Testing control line state command
I (1294) USB-CDC: - Control line state set to DTR=false, RTS=true
I (1314) USB-CDC: Testing line coding commands
I (1314) USB-CDC: - Line Coding Get: Rate: 115200, Stop bits: 0, Parity: 0, Databits: 8
I (1314) USB-CDC: - Line Set: Rate: 115200, Stop bits: 0, Parity: 0, Databits: 8
I (1314) USB-CDC: Example finished for device in slot 0. You can disconnect or connect another device.
If the CDC device is not detected, check:
If data is sent but not received:
idf.py menuconfig to get more detailed informationIf you see warnings like:
W (xxx) USB-CDC: Line coding get not supported
W (xxx) USB-CDC: Control line state set not supported
This is normal for some CDC-ACM devices that don't support these optional commands. The example will continue to work for basic data transfer operations.