Skip to content

Commit 3622995

Browse files
committed
Merge branch 'feat/add_cherryusb_demo' into 'master'
feat(usb): add CherryUSB serial device and host example See merge request espressif/esp-idf!39467
2 parents 0a7ace3 + 1f76ea9 commit 3622995

File tree

18 files changed

+2228
-18
lines changed

18 files changed

+2228
-18
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.22)
4+
5+
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
6+
idf_build_set_property(MINIMAL_BUILD ON)
7+
project(cherryusb_serial_device)
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
| Supported Targets | ESP32-P4 | ESP32-S2 | ESP32-S3 |
2+
| ----------------- | -------- | -------- | -------- |
3+
4+
# CherryUSB Serial Device Example
5+
6+
Starts a CDC Device, and sends back any received data from the host.
7+
8+
(See the README.md file in the upper level 'examples' directory for more information about examples.)
9+
10+
## How to use example
11+
12+
This example can also be configured to act as double serial device.
13+
Run `idf.py menuconfig` and in `Example Configuration → Enable usb cdc acm two channel` enable.
14+
15+
### Hardware Required
16+
17+
Any ESP board that have USB-OTG supported.
18+
19+
#### Pin Assignment
20+
21+
_Note:_ In case your board doesn't have micro-USB connector connected to USB-OTG peripheral, you may have to DIY a cable and connect **D+** and **D-** to the pins listed below.
22+
23+
See common pin assignments for USB Device examples from [upper level](../../README.md#common-pin-assignments).
24+
25+
### Build and Flash
26+
27+
Build the project and flash it to the board, then run monitor tool to view serial output:
28+
29+
```bash
30+
idf.py -p PORT flash monitor
31+
```
32+
33+
(Replace PORT with the name of the serial port to use.)
34+
35+
(To exit the serial monitor, type ``Ctrl-]``.)
36+
37+
See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
38+
39+
## Example output
40+
41+
When running, the example will print the following output:
42+
43+
```
44+
I (271) main_task: Started on CPU0
45+
I (291) main_task: Calling app_main()
46+
[I/USB] cherryusb, version: v1.4.3
47+
[I/USB] ========== dwc2 udc params ==========
48+
[I/USB] CID:00000000
49+
[I/USB] GSNPSID:4f54400a
50+
[I/USB] GHWCFG1:00000000
51+
[I/USB] GHWCFG2:224dd930
52+
[I/USB] GHWCFG3:00c804b5
53+
[I/USB] GHWCFG4:d3f0a030
54+
[I/USB] dwc2 fsphy type:1, hsphy type:0, dma support:2
55+
[I/USB] dwc2 has 7 endpoints and dfifo depth(32-bit words) is 200, default config: 7 endpoints
56+
[I/USB] =================================
57+
[I/USB] fifo0 size:0010, offset:0050
58+
[I/USB] fifo1 size:0010, offset:0060
59+
[I/USB] fifo2 size:0010, offset:0070
60+
[I/USB] fifo3 size:0010, offset:0080
61+
[I/USB] fifo4 size:0010, offset:0090
62+
[I/USB] fifo5 size:0010, offset:00a0
63+
[I/USB] fifo6 size:0010, offset:00b0
64+
I (391) device_cdc_main: usb cdc acm init done
65+
I (721) device_cdc_main: intf:0, dtr:0
66+
I (721) device_cdc_main: intf:0, rts:0
67+
I (2981) device_cdc_main: intf:0, dtr:0
68+
I (2981) device_cdc_main: intf:0, rts:0
69+
I (2981) device_cdc_main: intf:0, dtr:0
70+
I (2981) device_cdc_main: intf:0, rts:0
71+
I (2981) device_cdc_main: intf:0, dtr:0
72+
I (2981) device_cdc_main: intf:0, rts:0
73+
I (2991) device_cdc_main: intf:0, dtr:0
74+
I (2991) device_cdc_main: intf:0, rts:0
75+
I (2991) device_cdc_main: intf:0, dtr:0
76+
I (2991) device_cdc_main: intf:0, rts:0
77+
I (3001) device_cdc_main: intf:0, dtr:0
78+
I (3001) device_cdc_main: intf:0, rts:0
79+
I (6011) device_cdc_main: actual out len:13
80+
I (6021) device_cdc_main: actual in len:13
81+
I (10411) device_cdc_main: actual out len:13
82+
I (10421) device_cdc_main: actual in len:13
83+
I (11111) device_cdc_main: intf:0, dtr:0
84+
I (11111) device_cdc_main: intf:0, rts:0
85+
```
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
idf_component_register(SRCS "device_cdc_main.c"
2+
INCLUDE_DIRS "."
3+
)
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
menu "Example Configuration"
2+
3+
choice EXAMPLE_USB_DEVICE_RHPORT
4+
prompt "USB Device Peripheral"
5+
default EXAMPLE_USB_DEVICE_RHPORT_HS if IDF_TARGET_ESP32P4
6+
default EXAMPLE_USB_DEVICE_RHPORT_FS
7+
help
8+
Allows set the USB Peripheral Controller for USB device.
9+
10+
- High-speed (USB OTG2.0 Peripheral for High-, Full- and Low-speed)
11+
- Full-speed (USB OTG1.1 Peripheral for Full- and Low-speed)
12+
13+
config EXAMPLE_USB_DEVICE_RHPORT_HS
14+
bool "OTG2.0"
15+
depends on IDF_TARGET_ESP32P4
16+
config EXAMPLE_USB_DEVICE_RHPORT_FS
17+
bool "OTG1.1"
18+
19+
endchoice
20+
21+
config EXAMPLE_CHERRYUSB_CDC_ACM_TWO_CHANNEL
22+
bool "Enable usb cdc acm two channel"
23+
default n
24+
25+
config EXAMPLE_CHERRYUSB_INIT_DEINIT_LOOP
26+
bool "Perform init deinit of cherryusb stack in a loop"
27+
default n
28+
29+
config EXAMPLE_CHERRYUSB_SET_READ_BUFFER_SIZE_MPS
30+
bool "set usb read buffer size to MPS"
31+
default y
32+
help
33+
If this option is disabled, a larger receive buffer will be configured for DMA at a time,
34+
which may improve efficiency a little. However, when the host sends data with a length that
35+
is an integer multiple of MPS, the host may not send ZLP, resulting in failure to report
36+
the receipt of data in a timely manner.
37+
38+
endmenu

0 commit comments

Comments
 (0)