Simple USB Host CDC driver maintained in esp-iot-solution

readme

## iot_usbh_cdc Component

This component implements a simple version of the USB host CDC driver. The API is designed similarly to [ESP-IDF UART driver](https://docs.espressif.com/projects/esp-idf/en/latest/esp32s2/api-reference/peripherals/uart.html), which can be used to replace the original UART driver to realize the update from UART to USB.

**Features:**

1. Similar API to ESP-IDF UART driver
2. Support USB CDC device
3. Support USB Vendor device
4. Support USB CDC multiple interface

### User Guide

Please refer: https://docs.espressif.com/projects/esp-iot-solution/en/latest/usb/usb_host_iot_usbh_cdc.html

### Add component to your project

Please use the component manager command `add-dependency` to add the `iot_usbh_cdc` to your project's dependency, during the `CMake` step the component will be downloaded automatically

```
idf.py add-dependency "espressif/iot_usbh_cdc=*"
```

### Examples

Please use the component manager command `create-project-from-example` to create the project from the example template

* USB Host CDC Basic Example

```
idf.py create-project-from-example "espressif/iot_usbh_cdc=*:usb_cdc_basic"
```

Then the example will be downloaded in the current folder, you can check into it for build and flash.

> Or you can download examples from esp-iot-solution repository: [usb_cdc_basic](https://github.com/espressif/esp-iot-solution/tree/master/examples/usb/host/usb_cdc_basic).

changelog

# ChangeLog

## v0.2.2 - 2023-12-08

* Add doc and example

## v0.2.1 - 2023-11-23

* Fix possible cmake_utilities dependency issue

## v0.2.0 - 2023-10-09

* add hardware test
* decrease the stack priority to `usb base` level

## v0.1.3 - 2023-04-17

### Bug Fixes:

* Update iot_usbh version to 0.1.2, fix build error with latest ESP-IDF `release/v4.4`

## v0.1.2 - 2023-02-21

### Bug Fixes:

* Fix the multi-thread access error caused by `usbh_cdc_driver_delete()`

## v0.1.1 - 2023-02-13

* Support IDF5.0
* Change dependency iot_usbh to public

## v0.1.0 - 2023-02-02

* initial version

readme of usb_cdc_basic example

                                        
                                        # USB Host CDC Basic Example

This example demonstrates how to use [iot_usbh_cdc](https://components.espressif.com/components/espressif/iot_usbh_cdc) to communicate with USB CDC device.

## How to use the example

### Hardware Required

The example can be run on ESP32-S2 or ESP32-S3 based development board with USB interface. 

### Setup the Hardware

Connect the external USB device to ESP32-S USB interface directly.

| ESP32-Sx GPIO | USB Device  |
| ------------- | ----------- |
| 20            | D+ (green)  |
| 19            | D- (white)  |
| GND           | GND (black) |
| +5V           | +5V (red)   |

### Configure the project

1. The example enables one bulk interface by default.
2. Users can modify the `EXAMPLE_BULK_ITF_NUM` to `2` in `usb_cdc_basic_main.c` to enable two bulk interfaces.
3. Users need to modify the endpoint address `EXAMPLE_BULK_OUTx_EP_ADDR` and `EXAMPLE_BULK_INx_EP_ADDR` to the actual endpoint address of the USB device.
4. Use the command below to set build target to `esp32s2` or `esp32s3`.

```
idf.py set-target esp32s3
```

### Build and Flash

Build the project and flash it to the board, then run monitor tool to view serial output:

```
idf.py -p PORT build flash monitor
```

(To exit the serial monitor, type ``Ctrl-]``.)

See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.

## Example Output

If your USB device (eg. 4G Module) supports AT command, When host send `AT`, the device usually returns `OK` in most cases.

```
I (408) USB_HCDC: Waitting Device Connection
I (438) USB_HCDC: Port=1 init succeed
W (438) USB_HCDC: Waitting USB Connection
I (688) USB_HCDC: line 261 HCD_PORT_EVENT_CONNECTION
I (688) USB_HCDC: Resetting Port
I (748) USB_HCDC: Port speed = 1
I (748) USB_HCDC: Set Device Addr = 1
I (748) USB_HCDC: Set Device Addr Done
I (748) USB_HCDC: Set Device Configuration = 1
I (748) USB_HCDC: Set Device Configuration Done
I (758) USB_HCDC: Set Device Line State: dtr 1, rts 0
I (758) USB_HCDC: Set Device Line State Done
I (768) USB_HCDC: Creating bulk in pipe
I (768) USB_HCDC: Creating bulk out pipe
I (808) USB_HCDC: usb driver install succeed

I (6059) cdc_basic_demo: Send itf0 len=4: AT

I (6069) cdc_basic_demo: Send itf1 len=4: AT

I (6079) cdc_basic_demo: Itf 0, Receive len=6: 
OK

I (6079) cdc_basic_demo: Itf 1, Receive len=6: 
OK

I (7089) cdc_basic_demo: Send itf0 len=4: AT

I (7089) cdc_basic_demo: Send itf1 len=4: AT

I (7109) cdc_basic_demo: Itf 0, Receive len=6: 
OK

I (7109) cdc_basic_demo: Itf 1, Receive len=6: 
OK
```
                                    

License: Apache-2.0

To add this component to your project, run:

idf.py add-dependency "espressif/iot_usbh_cdc^0.2.2"

or download archive

Dependencies

  • espressif/cmake_utilities 0.*
  • ESP-IDF >=4.4.1
  • espressif/iot_usbh 0.*
  • Examples:

    usb_cdc_basic

    more details

    Stats

    • Downloaded in total
      Downloaded in total 465 times
    • Downloaded this version
      This version: 58 times

    Badge

    espressif/iot_usbh_cdc version: 0.2.2 |