$ show cherry-embedded/CherryUSB
CherryUSB is a portable, high-performance USB device and host stack for embedded systems (MCUs, RTOS). It provides a full-featured USB 2.0/3.0 stack with support for many USB class drivers (CDC ACM/ECM/NCM, HID, MSC, Audio, Video, DFU, MIDI, RNDIS, MTP, ADB, Bluetooth, vendor serial, gamepad, etc.) on both device and host sides. The architecture separates OS abstraction (OSAL), hardware controller drivers (DWC2, EHCI, XHCI, OHCI, MUSB, ChipIdea, FSdev, and many vendor-specific ports), and class implementations. It includes extensive demo templates, platform integrations (FatFS, lwIP, LVGL, UF2 bootloader), and tooling (Python test scripts, UF2 conv). The stack is used in commercial products and is registered in several embedded package ecosystems (RT-Thread, ESP-IDF, Bouffalolab). Key entry points are usbd_initialize() and usbh_initialize() with class-specific initialization routines in the demo folder. The codebase is large and well-organized but contains legacy ports and some vendor-specific glue code that may require adaptation.
The LLM identified 3 files worth highlighting for reuse:
A generic, lock-free ring buffer implementation optimized for power-of-two sizes. Provides linear read/write access functions (chry_ringbuffer_data_len, chry_ringbuffer_write, chry_ringbuffer_read, etc.) that allow efficient zero-copy or contiguous access. Reusable in any embedded project requiring a thread-safe FIFO without locks (e.g., serial drivers, audio buffers). Self-contained header with no external dependencies beyond stdint.h and stddef.h.
Header-only macros for singly and doubly linked lists (usb_slist, usb_dlist). Provides init, insert, remove, iteration, and splice operations with O(1) overhead. Used throughout CherryUSB for URB queues, class lists, and endpoint state tracking. Cleanly written with minimal dependencies, easy to extract for generic linked-list needs in embedded C projects.
Common lwIP glue layer for USB Ethernet host classes (CDC ECM, RNDIS, NCM, ASIX, RTL8152). Implements netif input/output, DHCP client start, and MAC address configuration. Encapsulates the pattern of bridging USB bulk streaming to a network stack. Self-contained with minimal dependencies on CherryUSB (uses usb_osal and usb_log). Can be reused as a template for porting USB Ethernet drivers to lwIP on other platforms.