usbcdc_write/usbcdc_read/usbcdc_available ?

vvb333007
Posts: 79
Joined: Wed Jul 31, 2024 5:53 am
Location: Thailand
Contact:

usbcdc_write/usbcdc_read/usbcdc_available ?

Postby vvb333007 » Wed Aug 13, 2025 7:10 am

Hello everyone!

For UART we have uart_write_bytes(), uart_read_bytes()/...

Question#1:
Do we have something simple for USB-CDC?

I have found these:

Code: Select all

ssize_t esp_usb_console_write_buf(const char* buf, size_t size);
ssize_t esp_usb_console_flush(void);
ssize_t esp_usb_console_read_buf(char* buf, size_t buf_size);
bool esp_usb_console_read_available(void);
bool esp_usb_console_write_available(void);
in private headers, but comment there says do not use it from the user code.

Question#2:
Why it is not recommended to use these functions?


My problem is that I have code, which has command line interface. Depending on the configuration it should be deployed either on UART0 or on USB (hardware CDC). For the uart it is simple (uart_write_bytes), however, for the USB I can't find simple write/read/available functions.

Comment in the code above also says that users are advised to use VFS to access USB, but I am not sure how to do that plus, I am not sure if ESP-IDF is compiled with VFS support (I use Arduino framework which is shipped with ESP-IDF precompiled)

:(
Thanks!
Slava.

nopnop2002
Posts: 362
Joined: Thu Oct 03, 2019 10:52 pm
Contact:

Re: usbcdc_write/usbcdc_read/usbcdc_available ?

Postby nopnop2002 » Thu Aug 21, 2025 11:05 pm

How to use USB OTG.
https://github.com/espressif/esp-idf/tr ... sb_console

How to use USB CDC.
https://github.com/espressif/esp-idf/tr ... b/host/cdc

You need to understand the difference between USB OTG and USB CDC.
USB OTG acts as a device and USB CDC acts as a host.

Only ESP32S2/S3/P4 supports this feature.

The "cdcacm" VFS driver was available in ESP-IDF V4, but is likely gone in ESP-IDF V5.

I don’t use Arduino framework.

Who is online

Users browsing this forum: Baidu [Spider], Google [Bot], meta-externalagent and 1 guest