2025-03-28 21:11:08 +08:00
**English | [简体中文 ](README_zh.md )**
2025-03-28 13:27:52 +08:00
2024-12-23 20:04:02 +08:00
<h1 align="center" style="margin: 30px 0 30px; font-weight: bold;">CherryUSB</h1>
<p align="center">
2025-03-28 13:27:52 +08:00
<a href="https://github.com/cherry-embedded/CherryUSB/releases"><img src="https://img.shields.io/github/release/cherry-embedded/CherryUSB.svg"></a>
2024-12-23 20:04:02 +08:00
<a href="https://github.com/cherry-embedded/CherryUSB/blob/master/LICENSE"><img src="https://img.shields.io/github/license/cherry-embedded/CherryUSB.svg?style=flat-square"></a>
<a href="https://github.com/cherry-embedded/CherryUSB/actions/workflows/deploy-docs.yml"><img src="https://github.com/cherry-embedded/CherryUSB/actions/workflows/deploy-docs.yml/badge.svg"> </a>
<a href="https://discord.com/invite/wFfvrSAey8"><img src="https://img.shields.io/badge/Discord-blue?logo=discord&style=flat-square"> </a>
</p>
2025-03-04 18:54:30 +08:00
CherryUSB is a tiny and beautiful, high performance and portable USB host and device stack for embedded system with USB IP.
2021-11-30 21:43:33 +08:00
2024-03-08 17:30:21 +08:00

2022-05-21 16:50:01 +08:00
2025-03-28 13:27:52 +08:00
## Why choose CherryUSB
2022-05-25 11:00:17 +08:00
2023-06-03 16:23:16 +08:00
### Easy to study USB
In 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:
- Lean code, simple logic, no complex C syntax
- Tree-based programming with cascading code
- Class-drivers and porting-drivers are templating and simplification
- Clear API classification (slave: initialisation, registration api, command callback api, data sending and receiving api; host: initialisation, lookup api, data sending and receiving api)
2024-07-11 17:57:29 +08:00
### Easy to use USB
2023-06-03 16:23:16 +08:00
In 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:
- Equivalent to using uart tx dma/uart rx dma
2024-10-10 21:39:40 +08:00
- 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 it)
2023-06-03 16:23:16 +08:00
### Easy to bring out USB performance
Taking 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:
- Porting drivers directly to registers, no abstraction layer encapsulation
- Memory zero copy
- If IP has DMA then uses DMA mode (DMA with hardware packetization)
- Unlimited length make it easier to interface with hardware DMA and take advantage of DMA
2024-10-10 21:39:40 +08:00
- Packetization is handled in interrupt
2022-05-25 11:00:17 +08:00
2024-07-11 17:57:29 +08:00
## Directory Structure
2021-12-04 14:41:09 +08:00
2021-12-12 15:21:56 +08:00
| Directory | Description |
|:-------------:|:---------------------------:|
|class | usb class driver |
|common | usb spec macros and utils |
2023-06-04 14:42:57 +08:00
|core | usb core implementation |
2024-05-23 23:14:53 +08:00
|demo | usb device and host demo |
2023-06-04 14:42:57 +08:00
|osal | os wrapper |
2024-05-23 23:14:53 +08:00
|platform | class support for other os |
2023-06-04 14:42:57 +08:00
|docs | doc for guiding |
|port | usb dcd and hcd porting |
|tools | tool url |
2021-12-12 15:21:56 +08:00
2022-05-25 11:00:17 +08:00
## Device Stack Overview
2021-12-12 15:21:56 +08:00
2022-02-01 23:07:38 +08:00
CherryUSB 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.
2021-12-12 15:21:56 +08:00
2025-03-28 13:27:52 +08:00
CherryUSB Device Stack has the following functions:
2021-12-12 15:21:56 +08:00
2025-03-28 21:11:08 +08:00
- Support USB2.0 full and high speed(USB3.0 super speed TODO)
2021-12-12 15:21:56 +08:00
- Support endpoint irq callback register by users, let users do whatever they wants in endpoint irq callback.
2022-04-04 15:54:53 +08:00
- Support Composite Device
2023-11-21 22:23:07 +08:00
- Support Communication Device Class (CDC_ACM, CDC_ECM)
2021-12-12 15:21:56 +08:00
- Support Human Interface Device (HID)
- Support Mass Storage Class (MSC)
2025-03-28 13:27:52 +08:00
- Support USB VIDEO CLASS (UVC1.0, UVC1.5)
- Support USB AUDIO CLASS (UAC1.0, UAC2.0)
2021-12-12 15:21:56 +08:00
- Support Device Firmware Upgrade CLASS (DFU)
- Support USB MIDI CLASS (MIDI)
2022-04-04 15:54:53 +08:00
- Support Remote NDIS (RNDIS)
2025-03-28 13:27:52 +08:00
- Support WINUSB1.0, WINUSB2.0, WEBUSB, BOS
2021-12-12 21:49:21 +08:00
- Support Vendor class
2024-07-23 22:37:27 +08:00
- Support UF2
2024-08-17 20:58:56 +08:00
- Support Android Debug Bridge (Only support shell)
2024-03-17 22:54:04 +08:00
- Support multi device with the same USB IP
2021-12-12 15:21:56 +08:00
2022-06-23 21:30:32 +08:00
CherryUSB Device Stack resource usage (GCC 10.2 with -O2):
2021-11-30 21:43:33 +08:00
2022-10-20 21:22:08 +08:00
| file | FLASH (Byte) | No Cache RAM (Byte) | RAM (Byte) | Heap (Byte) |
|:-------------:|:--------------:|:-------------------------:|:-------------:|:----------------:|
2025-05-15 20:27:06 +08:00
|usbd_core.c | ~6000 | (512(default) + 320) * bus | 0 | 0 |
|usbd_cdc_acm.c | ~400 | 0 | 0 | 0 |
|usbd_msc.c | ~3800 | (128 + 512(default)) * bus | 16 * bus | 0 |
|usbd_hid.c | ~360 | 0 | 0 | 0 |
|usbd_audio.c | ~1500 | 0 | 0 | 0 |
|usbd_video.c | ~3700 | 0 | 132 * bus | 0 |
|usbd_rndis.c | ~4000 | 2 * 1580(default)+156+8 | 80 | 0 |
2021-11-30 21:43:33 +08:00
2022-05-25 11:00:17 +08:00
## Host Stack Overview
2021-11-30 21:43:33 +08:00
2025-03-28 13:27:52 +08:00
The CherryUSB Host Stack has a standard enumeration implementation for devices mounted on root hubs 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.
2022-01-29 23:36:16 +08:00
2025-03-28 13:27:52 +08:00
CherryUSB Host Stack has the following functions:
2022-01-29 23:36:16 +08:00
2024-07-07 11:54:04 +08:00
- Support low speed, full speed, high speed and super speed devices
2022-01-29 23:36:16 +08:00
- Automatic loading of supported Class drivers
- Support blocking transfers and asynchronous transfers
2022-04-04 15:54:53 +08:00
- Support Composite Device
2025-02-09 15:32:32 +08:00
- Multi-level HUB support, expandable up to 7 levels(Testing hub with 10 ports works well,only support dwc2/ehci/xhci/rp2040)
2023-11-21 22:23:07 +08:00
- Support Communication Device Class (CDC_ACM, CDC_ECM)
2022-01-29 23:36:16 +08:00
- Support Human Interface Device (HID)
- Support Mass Storage Class (MSC)
2025-03-28 13:27:52 +08:00
- Support USB Video CLASS (UVC1.0, UVC1.5)
2024-06-16 20:59:32 +08:00
- Support USB Audio CLASS (UAC1.0)
2022-04-04 15:54:53 +08:00
- Support Remote NDIS (RNDIS)
2024-01-25 22:03:35 +08:00
- Support USB Bluetooth class (support nimble and zephyr bluetooth stack, support **CLASS:0xE0 ** or vendor class like cdc acm)
2024-07-07 12:07:49 +08:00
- Support Vendor class (serial, net, wifi)
2023-11-21 22:23:07 +08:00
- Support USB modeswitch
2024-10-31 21:43:41 +08:00
- Support Android Open Accessory
2024-01-06 22:16:58 +08:00
- Support multi host with the same USB IP
2022-01-29 23:36:16 +08:00
2022-02-01 23:07:38 +08:00
The 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.
2022-01-29 23:36:16 +08:00
2022-06-23 21:30:32 +08:00
CherryUSB Host Stack resource usage (GCC 10.2 with -O2):
2023-12-16 23:19:57 +08:00
| file | FLASH (Byte) | No Cache RAM (Byte) | RAM (Byte) | Heap (Byte) |
|:-------------:|:--------------:|:-------------------------------:|:---------------------------:|:------------:|
2025-05-15 20:27:06 +08:00
|usbh_core.c | ~10000(enable lsusb)/ ~7500(disable lsusb) | (512(default) + 8 * (1+x) * n) * bus | sizeof(struct usbh_hub) * bus | raw_config_desc |
2025-05-09 16:16:49 +08:00
|usbh_hub.c | ~6000 | (32 + 4 * (1+x)) * bus | 12 + sizeof(struct usbh_hub) * x | 0 |
2025-05-15 20:27:06 +08:00
|usbh_cdc_acm.c | ~900 | 7 * x | 4 + sizeof(struct usbh_cdc_acm) * x | 0 |
|usbh_msc.c | ~3400 | 128 * x | 4 + sizeof(struct usbh_msc) * x | 0 |
|usbh_hid.c | ~1400 | 64 * x | 4 + sizeof(struct usbh_hid) * x | 0 |
|usbh_video.c | ~5700 | 128 * x | 4 + sizeof(struct usbh_video) * x | 0 |
|usbh_audio.c | ~8400 | 128 * x | 4 + sizeof(struct usbh_audio) * x | 0 |
|usbh_rndis.c | ~5200 | 512 + 2 * 2048(default)| sizeof(struct usbh_rndis) * 1 | 0 |
|usbh_cdc_ecm.c | ~2200 | 2 * 1514 + 16 | sizeof(struct usbh_cdc_ecm) * 1 | 0 |
|usbh_cdc_ncm.c | ~3500 | 2 * 2048(default) + 16 + 32 | sizeof(struct usbh_cdc_ncm) * 1 | 0 |
|usbh_bluetooth.c | ~1000 | 2 * 2048(default) | sizeof(struct usbh_bluetooth) * 1 | 0 |
2022-09-14 20:33:47 +08:00
2025-03-28 13:27:52 +08:00
Among them, `sizeof(struct usbh_hub)` and `sizeof(struct usbh_hubport)` are affected by the following macros:
2022-09-14 20:33:47 +08:00
```
#define CONFIG_USBHOST_MAX_EXTHUBS 1
#define CONFIG_USBHOST_MAX_EHPORTS 4
2023-12-30 15:03:32 +08:00
#define CONFIG_USBHOST_MAX_INTERFACES 8
#define CONFIG_USBHOST_MAX_INTF_ALTSETTINGS 8
2022-09-14 20:33:47 +08:00
#define CONFIG_USBHOST_MAX_ENDPOINTS 4
```
2022-06-23 21:30:32 +08:00
2025-03-28 13:27:52 +08:00
x is affected by the following macros:
2023-07-12 23:01:15 +08:00
```
#define CONFIG_USBHOST_MAX_CDC_ACM_CLASS 4
#define CONFIG_USBHOST_MAX_HID_CLASS 4
#define CONFIG_USBHOST_MAX_MSC_CLASS 2
#define CONFIG_USBHOST_MAX_AUDIO_CLASS 1
#define CONFIG_USBHOST_MAX_VIDEO_CLASS 1
```
2024-03-27 19:34:24 +08:00
## USB IP Support
Only standard and commercial USB IP are listed.
| IP | device | host | Support status |
|:----------------:|:----------:|:--------:|:--------------:|
2024-12-09 20:18:07 +08:00
| OHCI(intel) | none | OHCI | √ |
2024-03-27 19:34:24 +08:00
| EHCI(intel) | none | EHCI | √ |
| XHCI(intel) | none | XHCI | √ |
2024-06-15 21:12:03 +08:00
| UHCI(intel) | none | UHCI | × |
2024-03-27 19:34:24 +08:00
| DWC2(synopsys) | DWC2 | DWC2 | √ |
| MUSB(mentor) | MUSB | MUSB | √ |
| FOTG210(faraday)| FOTG210 | EHCI | √ |
2024-08-21 20:04:18 +08:00
| CHIPIDEA(synopsys)| CHIPIDEA | EHCI | √ |
2024-03-27 19:34:24 +08:00
| CDNS2(cadence) | CDNS2 | CDNS2 | √ |
| CDNS3(cadence) | CDNS3 | XHCI | × |
| DWC3(synopsys) | DWC3 | XHCI | × |
2022-05-25 11:00:17 +08:00
## Documentation Tutorial
2021-11-30 21:43:33 +08:00
2025-03-28 13:27:52 +08:00
Quickly start, USB basic concepts, API manual, Class basic concepts and examples, see [CherryUSB Documentation Tutorial ](https://cherryusb.readthedocs.io/ ).
2021-11-30 21:43:33 +08:00
2022-05-25 11:00:17 +08:00
## Video Tutorial
2021-11-30 21:43:33 +08:00
2025-03-28 21:11:08 +08:00
CherryUSB Cheese (based V1.4.3): https://www.bilibili.com/cheese/play/ss707687201 .
2022-04-13 10:29:33 +08:00
2025-03-28 21:11:08 +08:00
## Descriptor Generator Tool
2022-04-13 10:29:33 +08:00
2025-03-28 21:11:08 +08:00
TODO
2022-05-27 22:52:37 +08:00
## Demo Repo
2023-12-26 20:33:41 +08:00
| Manufacturer | CHIP or Series | USB IP| Repo Url | Support version | Support status |
|:--------------------:|:------------------:|:-----:|:--------:|:------------------:|:-------------:|
2023-12-27 20:20:25 +08:00
|Bouffalolab | BL702/BL616/BL808 | bouffalolab/ehci|[bouffalo_sdk ](https://github.com/CherryUSB/bouffalo_sdk )|<= latest | Long-term |
2025-05-15 20:27:06 +08:00
|ST | STM32F1x/STM32F4/STM32H7 | fsdev/dwc2 |[stm32_repo ](https://github.com/CherryUSB/cherryusb_stm32 )|<= latest | Long-term |
2024-08-26 19:52:37 +08:00
|HPMicro | HPM6000/HPM5000 | hpm/ehci |[hpm_sdk ](https://github.com/CherryUSB/hpm_sdk )|<= latest | Long-term |
2024-06-15 21:12:03 +08:00
|Essemi | ES32F36xx | musb |[es32f369_repo ](https://github.com/CherryUSB/cherryusb_es32 )|<= latest | Long-term |
2024-08-21 20:04:18 +08:00
|Phytium | e2000 | pusb2/xhci |[phytium_repo ](https://gitee.com/phytium_embedded/phytium-free-rtos-sdk )|>=1.4.0 | Long-term |
2024-06-15 21:12:03 +08:00
|Artinchip | d12x/d13x/d21x | aic/ehci/ohci |[luban-lite ](https://gitee.com/artinchip/luban-lite )|<= latest | Long-term |
2024-08-26 19:52:37 +08:00
|Espressif | esp32s2/esp32s3/esp32p4 | dwc2 |[esp32_repo ](https://github.com/CherryUSB/cherryusb_esp32 )|<= latest | Long-term |
2024-10-10 21:30:42 +08:00
|NXP | mcx | kinetis/chipidea/ehci |[nxp_mcx_repo ](https://github.com/CherryUSB/cherryusb_mcx )|<= latest | Long-term |
2025-01-19 21:21:27 +08:00
|Kendryte | k230 | dwc2 |[k230_repo ](https://github.com/CherryUSB/k230_sdk )|v1.2.0 | Long-term |
2025-05-14 19:44:08 +08:00
|Actionstech | ATS30xx | dwc2 |[action_zephyr_repo ](https://github.com/CherryUSB/lv_port_actions_technology/tree/master/action_technology_sdk )|>=1.4.0 | Long-term |
2025-05-13 23:15:48 +08:00
|Nationstech | n32h4x | dwc2 |[nation_repo ](https://github.com/CherryUSB/cherryusb_nation )|>=1.5.0 | Long-term |
2025-01-19 20:44:56 +08:00
|Raspberry pi | rp2040/rp2350 | rp2040 |[pico-examples ](https://github.com/CherryUSB/pico-examples )|<= latest | Long-term |
2024-08-25 17:22:27 +08:00
|AllwinnerTech | F1C100S/F1C200S | musb |[cherryusb_rtt_f1c100s ](https://github.com/CherryUSB/cherryusb_rtt_f1c100s )|<= latest | the same with musb |
|Bekencorp | bk7256/bk7258 | musb |[bk_idk ](https://github.com/CherryUSB/bk_idk )| v0.7.0 | the same with musb |
|Sophgo | cv18xx | dwc2 |[cvi_alios_open ](https://github.com/CherryUSB/cvi_alios_open )| v0.7.0 | TBD |
2024-06-15 21:12:03 +08:00
|WCH | CH32V307/ch58x | ch32_usbfs/ch32_usbhs/ch58x |[wch_repo ](https://github.com/CherryUSB/cherryusb_wch )|<= v0.10.2 | TBD |
2022-06-05 16:45:39 +08:00
2024-08-21 20:04:18 +08:00
## Package Support
CherryUSB package is available as follows:
- [RT-Thread ](https://packages.rt-thread.org/detail.html?package=CherryUSB )
- [YOC ](https://www.xrvm.cn/document?temp=usb-host-protocol-stack-device-driver-adaptation-instructions&slug=yocbook )
- [ESP-Registry ](https://components.espressif.com/components/cherry-embedded/cherryusb )
2024-05-31 23:01:12 +08:00
## Commercial Support
2024-06-15 21:12:03 +08:00
Refer to https://cherryusb.readthedocs.io/zh-cn/latest/support/index.html.
2024-05-31 23:01:12 +08:00
2022-06-05 16:45:39 +08:00
## Contact
2024-05-05 12:04:08 +08:00
CherryUSB discord: https://discord.com/invite/wFfvrSAey8.
## Company Support
2025-03-28 13:27:52 +08:00
Thanks to the following companies for their support (in no particular order):
2024-05-05 12:04:08 +08:00
2024-11-29 22:41:56 +08:00
<img src="docs/assets/bouffalolab.jpg" width="100" height="80"/> <img src="docs/assets/hpmicro.jpg" width="100" height="80" /> <img src="docs/assets/eastsoft.jpg" width="100" height="80" /> <img src="docs/assets/rtthread.jpg" width="100" height="80" /> <img src="docs/assets/sophgo.jpg" width="100" height="80" /> <img src="docs/assets/phytium.jpg" width="100" height="80" /> <img src="docs/assets/thead.jpg" width="100" height="80" /> <img src="docs/assets/nuvoton.jpg" width="100" height="80" /> <img src="docs/assets/artinchip.jpg" width="100" height="80" /> <img src="docs/assets/bekencorp.jpg" width="100" height="80" /> <img src="docs/assets/nxp.png" width="100" height="80" /> <img src="docs/assets/espressif.png" width="100" height="80" /> <img src="docs/assets/canaan.jpg" width="100" height="80" />
2025-05-14 19:44:08 +08:00
<img src="docs/assets/actions.jpg" width="100" height="80" /> <img src="docs/assets/nationstech.jpg" width="100" height="80" />