Skip to content

Commit 6069bdc

Browse files
committed
feat(examples/peripherals/usb/cherryusb/host/cherryusb_host): add CherryUSB host example
1 parent f866fbd commit 6069bdc

File tree

9 files changed

+931
-0
lines changed

9 files changed

+931
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# The following lines of boilerplate have to be in your project's
2+
# CMakeLists in this exact order for cmake to work correctly
3+
cmake_minimum_required(VERSION 3.5)
4+
5+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
6+
idf_build_set_property(MINIMAL_BUILD ON)
7+
project(cherryusb_host)
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
| Supported Targets | ESP32-P4 | ESP32-S2 | ESP32-S3 |
2+
| ----------------- | -------- | -------- | -------- |
3+
4+
# CherryUSB Host Example
5+
6+
(See the README.md file in the upper level 'examples' directory for more information about examples.)
7+
8+
This example demonstrates how to use the CherryUSB host driver. Currently, this example supports communication with HID devices (such as Keyboard and Mouse) and serial port devices (such as CDC_ACM, CH34x, CP210x, PL2303, FTDI FT23x/FT423x devices).
9+
10+
## How to use example
11+
12+
If you need to enable support for FTDI, please enable the following configuration
13+
Run `idf.py menuconfig` and in `Component config → CherryUSB Configuration → Enable usb host mode → Enable usb ftdi driver` enable.
14+
15+
### Hardware Required
16+
* Development board with USB-OTG support
17+
* A USB cable for Power supply and programming
18+
* USB OTG Cable
19+
20+
#### Pin Assignment
21+
22+
Follow instruction in [examples/usb/README.md](../../../README.md) for specific hardware setup.
23+
24+
### Build and Flash
25+
26+
Build the project and flash it to the board, then run monitor tool to view serial output:
27+
28+
```bash
29+
idf.py -p PORT flash monitor
30+
```
31+
32+
(Replace PORT with the name of the serial port to use.)
33+
34+
(To exit the serial monitor, type ``Ctrl-]``.)
35+
36+
See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
37+
38+
## Example output
39+
40+
When running, the example will print the following output:
41+
42+
```
43+
I (264) main_task: Started on CPU0
44+
I (304) main_task: Calling app_main()
45+
[I/USB] cherryusb, version: v1.5.0
46+
[I/USB] ========== dwc2 hcd params ==========
47+
[I/USB] CID:00000000
48+
[I/USB] GSNPSID:4f54400a
49+
[I/USB] GHWCFG1:00000000
50+
[I/USB] GHWCFG2:215fffd0
51+
[I/USB] GHWCFG3:03805eb5
52+
[I/USB] GHWCFG4:dff1a030
53+
[I/USB] dwc2 has 16 channels and dfifo depth(32-bit words) is 896
54+
I (334) HOST: Init usb
55+
I (334) main_task: Returned from app_main()
56+
[I/usbh_hub] New low-speed device on Bus 0, Hub 1, Port 1 connected
57+
[I/usbh_core] New device found,idVendor:413c,idProduct:2113,bcdDevice:0110
58+
[I/usbh_core] The device has 1 bNumConfigurations
59+
[I/usbh_core] The device has 2 interfaces
60+
[I/usbh_core] Enumeration success, start loading class driver
61+
[I/usbh_core] Loading hid class driver
62+
[I/usbh_hid] Ep=81 Attr=03 Mps=8 Interval=10 Mult=00
63+
[I/usbh_hid] Register HID Class:/dev/input0
64+
I (1054) HID: intf 0, SubClass 1, Protocol 1
65+
[I/usbh_core] Loading hid class driver
66+
[W/usbh_hid] Do not support set idle
67+
[I/usbh_hid] Ep=82 Attr=03 Mps=3 Interval=10 Mult=00
68+
[I/usbh_hid] Register HID Class:/dev/input1
69+
I (1074) HID: intf 1, SubClass 0, Protocol 0
70+
71+
Keyboard
72+
xiaodou
73+
```
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
set(srcs "main.c")
2+
3+
if(CONFIG_CHERRYUSB_HOST_HID)
4+
list(APPEND srcs "hid.c")
5+
endif()
6+
7+
if(CONFIG_CHERRYUSB_HOST_CDC_ACM OR CONFIG_CHERRYUSB_HOST_FTDI OR CONFIG_CHERRYUSB_HOST_CH34X OR
8+
CONFIG_CHERRYUSB_HOST_CP210X OR CONFIG_CHERRYUSB_HOST_PL2303)
9+
list(APPEND srcs "cdc_acm.c")
10+
endif()
11+
12+
idf_component_register(SRCS ${srcs}
13+
INCLUDE_DIRS "."
14+
)
15+
16+
if(CONFIG_CHERRYUSB_HOST_HID)
17+
# Make sure the definitions in hid.c are linked correctly
18+
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u usbh_hid_run_real")
19+
endif()
20+
21+
if(CONFIG_CHERRYUSB_HOST_CDC_ACM)
22+
# Make sure the definitions in hid.c are linked correctly
23+
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u usbh_cdc_acm_run_real")
24+
endif()
25+
26+
if(CONFIG_CHERRYUSB_HOST_FTDI)
27+
# Make sure the definitions in hid.c are linked correctly
28+
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u usbh_ftdi_run_real")
29+
endif()
30+
31+
if(CONFIG_CHERRYUSB_HOST_CH34X)
32+
# Make sure the definitions in hid.c are linked correctly
33+
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u usbh_ch34x_run_real")
34+
endif()
35+
36+
if(CONFIG_CHERRYUSB_HOST_CP210X)
37+
# Make sure the definitions in hid.c are linked correctly
38+
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u usbh_cp210x_run_real")
39+
endif()
40+
41+
if(CONFIG_CHERRYUSB_HOST_PL2303)
42+
# Make sure the definitions in hid.c are linked correctly
43+
target_link_libraries(${COMPONENT_LIB} INTERFACE "-u usbh_pl2303_run_real")
44+
endif()
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
menu "Example Configuration"
2+
3+
config EXAMPLE_HAL_USE_ESP32_S3_USB_OTG
4+
bool "Use dev kit ESP32-S3-USB-OTG"
5+
depends on IDF_TARGET_ESP32S3
6+
default y
7+
8+
config EXAMPLE_CHERRYUSB_INIT_DEINIT_LOOP
9+
bool "Perform init deinit of cherryusb stack in a loop"
10+
default n
11+
12+
endmenu

0 commit comments

Comments
 (0)