• Home
Name Date Size #Lines LOC

..--

class/12-May-2024-17,12713,536

common/12-May-2024-2,1751,345

core/12-May-2024-2,3991,818

demo/12-May-2024-86,15184,662

osal/12-May-2024-416314

port/12-May-2024-2,2631,735

tools/12-May-2024-22

CMakeLists.txtD12-May-20241.9 KiB6153

LICENSED12-May-202411.1 KiB202169

README.mdD12-May-20249.9 KiB183138

README_zh.mdD12-May-20249.3 KiB181137

cherryusb_config_template.hD12-May-20243.9 KiB15277

README.md

1# CherryUSB
2
3[中文版](./README_zh.md)
4
5CherryUSB is a tiny, beautiful and portable USB host and device stack for embedded system with USB IP.
6
7![CherryUSB](./docs/assets/CherryUSB.svg)
8
9## Why choose
10
11### Easy to study USB
12
13In order to make it easier for users to learn USB basics, enumeration, driver loading and IP drivers, the code has been written with the following advantages:
14
15- Lean code, simple logic, no complex C syntax
16- Tree-based programming with cascading code
17- Class-drivers and porting-drivers are templating and simplification
18- Clear API classification (slave: initialisation, registration api, command callback api, data sending and receiving api; host: initialisation, lookup api, data sending and receiving api)
19
20### Easy to use  USB
21
22In order to facilitate the use of the USB interface and to take into account the fact that users have learned about uart and dma, the following advantages have been designed for the data sending and receiving class of interface:
23
24- Equivalent to using uart tx dma/uart rx dma
25- There is no limit to the length of send and receive, the user does not need to care about the USB packetization process (the porting driver does the packetization process)
26
27### Easy to bring out USB performance
28
29Taking into account USB performance issues and trying to achieve the theoretical bandwidth of the USB hardware, the design of the data transceiver class interface has the following advantages:
30
31- Porting drivers directly to registers, no abstraction layer encapsulation
32- Memory zero copy
33- If IP has DMA then uses DMA mode (DMA with hardware packetization)
34- Unlimited length make it easier to interface with hardware DMA and take advantage of DMA
35- Subcontracting function is handled in interrupt
36
37## Directoy Structure
38
39```
40.
41├── class
42├── common
43├── core
44├── demo
45├── docs
46├── osal
47├── packet capture
48└── port
49└── tools
50
51```
52
53|   Directory       |  Description            |
54|:-------------:|:---------------------------:|
55|class          |  usb class driver           |
56|common         |  usb spec macros and utils  |
57|core           |  usb core implementation    |
58|demo           |  different chips demo       |
59|osal           |  os wrapper                 |
60|docs           |  doc for guiding            |
61|port           |  usb dcd and hcd porting    |
62|tools          |  tool url                   |
63
64## Device Stack Overview
65
66CherryUSB Device Stack provides a unified framework of functions for standard device requests, CLASS requests, VENDOR requests and custom special requests. The object-oriented and chained approach allows the user to quickly get started with composite devices without having to worry about the underlying logic. At the same time, a standard dcd porting interface has been standardised for adapting different USB IPs to achieve ip-oriented programming.
67
68CherryUSB Device Stack has the following functions:
69
70- Support USB2.0 full and high speed, USB3.0 super speed
71- Support endpoint irq callback register by users, let users do whatever they wants in endpoint irq callback.
72- Support Composite Device
73- Support Communication Device Class (CDC)
74- Support Human Interface Device (HID)
75- Support Mass Storage Class (MSC)
76- Support USB VIDEO CLASS (UVC1.0、UVC1.5)
77- Support USB AUDIO CLASS (UAC1.0、UAC2.0)
78- Support Device Firmware Upgrade CLASS (DFU)
79- Support USB MIDI CLASS (MIDI)
80- Support Remote NDIS (RNDIS)
81- Support WINUSB1.0、WINUSB2.0(with BOS)
82- Support Vendor class
83
84CherryUSB Device Stack resource usage (GCC 10.2 with -O2):
85
86|   file        |  FLASH (Byte)  |  No Cache RAM (Byte)      |  RAM (Byte)   |  Heap (Byte)     |
87|:-------------:|:--------------:|:-------------------------:|:-------------:|:----------------:|
88|usbd_core.c    |  3516          | 256(default) + 320        | 0             | 0                |
89|usbd_cdc.c     |  392           | 0                         | 0             | 0                |
90|usbd_msc.c     |  2839          | 128 + 512(default)        | 16            | 0                |
91|usbd_hid.c     |  364           | 0                         | 0             | 0                |
92|usbd_audio.c   |  1455          | 0                         | 0             | 0                |
93|usbd_video.c   |  2494          | 0                         | 84            | 0                |
94|usbd_rndis.c   |  2109          | 3340                      | 76            | 0                |
95
96## Host Stack Overview
97
98The CherryUSB Host Stack has a standard enumeration implementation for devices mounted on roothubs and external hubs, and a standard interface for different Classes to indicate what the Class driver needs to do after enumeration and after disconnection. A standard hcd porting interface has also been standardised for adapting different USB IPs for IP-oriented programming. Finally, the host stack is managed using os, and provides osal to make a adaptation for different os.
99
100CherryUSB Host Stack has the following functions:
101
102- Automatic loading of supported Class drivers
103- Support blocking transfers and asynchronous transfers
104- Support Composite Device
105- Multi-level HUB support, expandable up to 7 levels
106- Support Communication Device Class (CDC)
107- Support Human Interface Device (HID)
108- Support Mass Storage Class (MSC)
109- Support USB Video CLASS
110- Support USB Audio CLASS
111- Support Remote NDIS (RNDIS)
112- Support Vendor class
113
114The CherryUSB Host stack also provides the lsusb function, which allows you to view information about all mounted devices, including those on external hubs, with the help of a shell plugin.
115
116CherryUSB Host Stack resource usage (GCC 10.2 with -O2):
117
118|   file        |  FLASH (Byte)  |  No Cache RAM (Byte)            |  RAM (Byte)                 |  Heap (Byte)                    |
119|:-------------:|:--------------:|:-------------------------------:|:---------------------------:|:-------------------------------:|
120|usbh_core.c    |  4237          | 512 + 8 * (1+x) *n              | 28                          | sizeof(struct usbh_urb)         |
121|usbh_hub.c     |  2919          | 32 + 4* (1+x) | 12 + sizeof(struct usbh_hub) * (1+x)          | 0                               |
122|usbh_cdc_acm.c |  1099          | 7             | 4  + sizeof(struct usbh_cdc_acm) * x          | 0                               |
123|usbh_msc.c     |  2502          | 32            | 4  + sizeof(struct usbh_msc) * x              | 0                               |
124|usbh_hid.c     |  956           | 128           | 4  + sizeof(struct usbh_hid) * x              | 0                               |
125|usbh_video.c   |  2330          | 128           | 4  + sizeof(struct usbh_video) * x            | 0                               |
126|usbh_audio.c   |  3168          | 128           | 4  + sizeof(struct usbh_audio) * x            | 0                               |
127|usbh_rndis.c   |  3030          | 4096          | 4  + sizeof(struct usbh_rndis) * x            | 0                               |
128
129Among them, `sizeof(struct usbh_hub)` and `sizeof(struct usbh_hubport)` are affected by the following macros:
130
131```
132#define CONFIG_USBHOST_MAX_EXTHUBS          1
133#define CONFIG_USBHOST_MAX_EHPORTS          4
134#define CONFIG_USBHOST_MAX_INTERFACES       6
135#define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 1
136#define CONFIG_USBHOST_MAX_ENDPOINTS        4
137```
138
139x is affected by the following macros:
140
141```
142#define CONFIG_USBHOST_MAX_CDC_ACM_CLASS 4
143#define CONFIG_USBHOST_MAX_HID_CLASS     4
144#define CONFIG_USBHOST_MAX_MSC_CLASS     2
145#define CONFIG_USBHOST_MAX_AUDIO_CLASS   1
146#define CONFIG_USBHOST_MAX_VIDEO_CLASS   1
147#define CONFIG_USBHOST_MAX_RNDIS_CLASS   1
148
149```
150
151## Documentation Tutorial
152
153Quickly start, USB basic concepts, API manual, Class basic concepts and examples, see [CherryUSB Documentation Tutorial](https://cherryusb.readthedocs.io/)
154
155## Video Tutorial
156
157USB basic concepts and how the CherryUSB Device stack is implemented, see [CherryUSB Device Stack Tutorial](https://www.bilibili.com/video/BV1Ef4y1t73d).
158
159## Graphical Config Tool
160
161[chryusb_configurator](https://github.com/Egahp/chryusb_configurator) is written in **electron + vite2 + ts** framework,currently used to automate the generation of descriptor arrays, with additional functionality to be added later.
162
163## Demo Repo
164
165|   Manufacturer       |  CHIP or Series    | USB IP| Repo Url |Current version|
166|:--------------------:|:------------------:|:-----:|:--------:|:---------------------------:|
167|Bouffalolab    |  BL702/BL616/BL808 | bouffalolab/ehci|[bouffalo_sdk](https://github.com/CherryUSB/cherryusb_bouffalolab)| v0.10.1 |
168|ST    |  STM32F1x | fsdev |[stm32_repo](https://github.com/CherryUSB/cherryusb_stm32)|≤ v0.10.1 |
169|ST    |  STM32F4/STM32H7 | dwc2 |[stm32_repo](https://github.com/CherryUSB/cherryusb_stm32)|≤ v0.10.1 |
170|HPMicro    |  HPM6750 | hpm/ehci |[hpm_sdk](https://github.com/CherryUSB/cherryusb_hpmicro)| v0.10.1 |
171|Essemi    |  ES32F36xx | musb |[es32f369_repo](https://github.com/CherryUSB/cherryusb_es32)|≤ v0.10.1 |
172|AllwinnerTech    |  F1C100S/F1C200S | musb |[cherryusb_rtt_f1c100s](https://github.com/CherryUSB/cherryusb_rtt_f1c100s)|≤ v0.10.1 |
173|Phytium |  e2000 | xhci |[phytium_repo](https://gitee.com/phytium_embedded/phytium-free-rtos-sdk)|v0.9.0 |
174|Raspberry pi |  rp2040 | rp2040 |[pico-examples](https://github.com/CherryUSB/pico-examples)|≤ v0.10.1 |
175|WCH    |  CH32V307/ch58x | ch32_usbfs/ch32_usbhs/ch58x |[wch_repo](https://github.com/CherryUSB/cherryusb_wch)|≤ v0.10.1 |
176|Nordicsemi |  Nrf52840 | nrf5x |[nrf5x_repo](https://github.com/CherryUSB/cherryusb_nrf5x)|≤ v0.10.1 |
177|Espressif    |  esp32s3 | dwc2 |[esp32_repo](https://github.com/CherryUSB/cherryusb_esp32)|≤ v0.10.1 |
178|Bekencorp    |  BK72xx | musb |[armino](https://github.com/CherryUSB/armino)|v0.7.0 |
179|Sophgo    |  cv18xx | dwc2 |[cvi_alios_open](https://github.com/CherryUSB/cvi_alios_open)|v0.7.0 |
180
181## Contact
182
183QQ group: 642693751

README_zh.md

1# CherryUSB
2
3[English](./README.md)
4
5CherryUSB 是一个小而美的、可移植性高的、用于嵌入式系统(带 USB IP)的 USB 主从协议栈。
6
7![CherryUSB](./docs/assets/CherryUSB.svg)
8
9## 为什么选择
10
11### 易于学习 USB
12
13为了方便用户学习 USB 基本知识、枚举、驱动加载、IP 驱动,因此,编写的代码具备以下优点:
14
15- 代码精简,逻辑简单,无复杂 C 语言语法
16- 树状化编程,代码层层递进
17- Class 驱动和 porting 驱动模板化、精简化
18- API 分类清晰(从机:初始化、注册类、命令回调类、数据收发类;主机:初始化、查找类、数据收发类)
19
20### 易于使用 USB
21
22为了方便用户使用 USB 接口,考虑到用户学习过 uart 和 dma,因此,设计的数据收发类接口具备以下优点:
23
24- 等价于使用 uart tx dma/uart rx dma
25- 收发长度没有限制,用户不需要关心 USB 分包过程(porting 驱动做分包过程)
26
27### 易于发挥 USB 性能
28
29考虑到 USB 性能问题,尽量达到 USB 硬件理论带宽,因此,设计的数据收发类接口具备以下优点:
30
31- Porting 驱动直接对接寄存器,无抽象层封装
32- Memory zero copy
33- IP 如果带 DMA 则使用 DMA 模式(DMA 带硬件分包功能)
34- 长度无限制,方便对接硬件 DMA 并且发挥 DMA 的优势
35- 分包功能在中断中处理
36
37## 目录结构
38
39```
40.
41├── class
42├── common
43├── core
44├── demo
45├── docs
46├── osal
47└── port
48└── tools
49```
50
51|   目录名       |  描述                          |
52|:-------------:|:-------------------------------:|
53|class          |  usb class 类主从驱动           |
54|common         |  usb spec 定义、常用宏、标准接口定义 |
55|core           |  usb 主从协议栈核心实现          |
56|demo           |  示例                            |
57|docs           |  文档                            |
58|osal           |  os 封装层                       |
59|port           |  usb 主从需要实现的 porting 接口 |
60|tools          |  工具链接                        |
61
62## Device 协议栈简介
63
64CherryUSB Device 协议栈对标准设备请求、CLASS 请求、VENDOR 请求以及 custom 特殊请求规范了一套统一的函数框架,采用面向对象和链表的方式,能够使得用户快速上手复合设备,不用管底层的逻辑。同时,规范了一套标准的 dcd porting 接口,用于适配不同的 USB IP,达到面向 ip 编程。
65
66CherryUSB Device 协议栈当前实现以下功能:
67
68- 支持 USB2.0 全速和高速设备,USB3.0 超速设备
69- 支持端点中断注册功能,porting 给用户自己处理中断里的数据
70- 支持复合设备
71- 支持 Communication Device Class (CDC)
72- 支持 Human Interface Device (HID)
73- 支持 Mass Storage Class (MSC)
74- 支持 USB VIDEO CLASS (UVC1.0、UVC1.5)
75- 支持 USB AUDIO CLASS (UAC1.0、UAC2.0)
76- 支持 Device Firmware Upgrade CLASS (DFU)
77- 支持 USB MIDI CLASS (MIDI)
78- 支持 Remote NDIS (RNDIS)
79- 支持 WINUSB1.0、WINUSB2.0(带 BOS )
80- 支持 Vendor 类 class
81
82CherryUSB Device 协议栈资源占用说明(GCC 10.2 with -O2):
83
84|   file        |  FLASH (Byte)  |  No Cache RAM (Byte)      |  RAM (Byte)   |  Heap (Byte)     |
85|:-------------:|:--------------:|:-------------------------:|:-------------:|:----------------:|
86|usbd_core.c    |  3516          | 256(default) + 320        | 0             | 0                |
87|usbd_cdc.c     |  392           | 0                         | 0             | 0                |
88|usbd_msc.c     |  2839          | 128 + 512(default)        | 16            | 0                |
89|usbd_hid.c     |  364           | 0                         | 0             | 0                |
90|usbd_audio.c   |  1455          | 0                         | 0             | 0                |
91|usbd_video.c   |  2494          | 0                         | 84            | 0                |
92|usbd_rndis.c   |  2109          | 3340                      | 76            | 0                |
93
94## Host 协议栈简介
95
96CherryUSB Host 协议栈对挂载在 roothub、外部 hub 上的设备规范了一套标准的枚举实现,对不同的 Class 类也规范了一套标准接口,用来指示在枚举后和断开连接后该 Class 驱动需要做的事情。同时,规范了一套标准的 hcd porting 接口,用于适配不同的 USB IP,达到面向 IP 编程。最后,协议栈使用 OS 管理,并提供了 osal 用来适配不同的 os。
97
98CherryUSB Host 协议栈当前实现以下功能:
99
100- 自动加载支持的Class 驱动
101- 支持阻塞式传输和异步传输
102- 支持复合设备
103- 支持多级 HUB,最高可拓展到 7 级
104- 支持 Communication Device Class (CDC)
105- 支持 Human Interface Device (HID)
106- 支持 Mass Storage Class (MSC)
107- Support USB Video CLASS
108- Support USB Audio CLASS
109- 支持 Remote NDIS (RNDIS)
110- 支持 Vendor 类 class
111
112同时,CherryUSB Host 协议栈还提供了 lsusb 的功能,借助 shell 插件可以查看所有挂载设备的信息,包括外部 hub 上的设备的信息。
113
114CherryUSB Host 协议栈资源占用说明(GCC 10.2 with -O2):
115
116|   file        |  FLASH (Byte)  |  No Cache RAM (Byte)            |  RAM (Byte)                 |  Heap (Byte)                    |
117|:-------------:|:--------------:|:-------------------------------:|:---------------------------:|:-------------------------------:|
118|usbh_core.c    |  4237          | 512 + 8 * (1+x) *n              | 28                          | sizeof(struct usbh_urb)         |
119|usbh_hub.c     |  2919          | 32 + 4* (1+x) | 12 + sizeof(struct usbh_hub) * (1+x)          | 0                               |
120|usbh_cdc_acm.c |  1099          | 7             | 4  + sizeof(struct usbh_cdc_acm) * x          | 0                               |
121|usbh_msc.c     |  2502          | 32            | 4  + sizeof(struct usbh_msc) * x              | 0                               |
122|usbh_hid.c     |  956           | 128           | 4  + sizeof(struct usbh_hid) * x              | 0                               |
123|usbh_video.c   |  2330          | 128           | 4  + sizeof(struct usbh_video) * x            | 0                               |
124|usbh_audio.c   |  3168          | 128           | 4  + sizeof(struct usbh_audio) * x            | 0                               |
125|usbh_rndis.c   |  3030          | 4096          | 4  + sizeof(struct usbh_rndis) * x            | 0                               |
126
127其中,`sizeof(struct usbh_hub)` 和 `sizeof(struct usbh_hubport)` 受以下宏影响:
128
129```
130#define CONFIG_USBHOST_MAX_EXTHUBS          1
131#define CONFIG_USBHOST_MAX_EHPORTS          4
132#define CONFIG_USBHOST_MAX_INTERFACES       6
133#define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 1
134#define CONFIG_USBHOST_MAX_ENDPOINTS        4
135```
136
137x 受以下宏影响:
138
139```
140#define CONFIG_USBHOST_MAX_CDC_ACM_CLASS 4
141#define CONFIG_USBHOST_MAX_HID_CLASS     4
142#define CONFIG_USBHOST_MAX_MSC_CLASS     2
143#define CONFIG_USBHOST_MAX_AUDIO_CLASS   1
144#define CONFIG_USBHOST_MAX_VIDEO_CLASS   1
145#define CONFIG_USBHOST_MAX_RNDIS_CLASS   1
146
147```
148
149## 文档教程
150
151CherryUSB 快速入门、USB 基本概念,API 手册,Class 基本概念和例程,参考 [CherryUSB 文档教程](https://cherryusb.readthedocs.io/)
152
153## 视频教程
154
155USB 基本知识点与 CherryUSB Device 协议栈是如何编写的,参考 [CherryUSB Device 协议栈教程](https://www.bilibili.com/video/BV1Ef4y1t73d).
156
157## 图形化界面配置工具
158
159[chryusb_configurator](https://github.com/Egahp/chryusb_configurator) 采用 **electron + vite2 + ts** 框架编写,当前用于自动化生成描述符数组,后续会增加其他功能。
160
161## 示例仓库
162
163|   厂商               |  芯片或者系列      | USB IP| 仓库链接 |      当前版本        |
164|:--------------------:|:------------------:|:-----:|:--------:|:---------------------------:|
165|Bouffalolab    |  BL702/BL616/BL808 | bouffalolab/ehci|[bouffalo_sdk](https://github.com/CherryUSB/cherryusb_bouffalolab)| v0.10.1 |
166|ST    |  STM32F1x | fsdev |[stm32_repo](https://github.com/CherryUSB/cherryusb_stm32)|≤ v0.10.1 |
167|ST    |  STM32F4/STM32H7 | dwc2 |[stm32_repo](https://github.com/CherryUSB/cherryusb_stm32)|≤ v0.10.1 |
168|HPMicro    |  HPM6750 | hpm/ehci |[hpm_sdk](https://github.com/CherryUSB/cherryusb_hpmicro)| v0.10.1 |
169|Essemi    |  ES32F36xx | musb |[es32f369_repo](https://github.com/CherryUSB/cherryusb_es32)|≤ v0.10.1 |
170|AllwinnerTech    |  F1C100S/F1C200S | musb |[cherryusb_rtt_f1c100s](https://github.com/CherryUSB/cherryusb_rtt_f1c100s)|≤ v0.10.1 |
171|Phytium |  e2000 | xhci |[phytium_repo](https://gitee.com/phytium_embedded/phytium-free-rtos-sdk)|v0.9.0 |
172|Raspberry pi |  rp2040 | rp2040 |[pico-examples](https://github.com/CherryUSB/pico-examples)|≤ v0.10.1 |
173|WCH    |  CH32V307/ch58x | ch32_usbfs/ch32_usbhs/ch58x |[wch_repo](https://github.com/CherryUSB/cherryusb_wch)|≤ v0.10.1 |
174|Nordicsemi |  Nrf52840 | nrf5x |[nrf5x_repo](https://github.com/CherryUSB/cherryusb_nrf5x)|≤ v0.10.1 |
175|Espressif    |  esp32s3 | dwc2 |[esp32_repo](https://github.com/CherryUSB/cherryusb_esp32)|≤ v0.10.1 |
176|Bekencorp    |  BK72xx | musb |[armino](https://github.com/CherryUSB/armino)|v0.7.0 |
177|Sophgo    |  cv18xx | dwc2 |[cvi_alios_open](https://github.com/CherryUSB/cvi_alios_open)|v0.7.0 |
178
179## Contact
180
181QQ 群:642693751