├── .devcontainer ├── Dockerfile └── devcontainer.json ├── .gitignore ├── README.md └── examples ├── device ├── CMakeLists.txt ├── main │ ├── CMakeLists.txt │ ├── idf_component.yml │ └── main.c ├── sdkconfig.ci └── sdkconfig.defaults └── host ├── CMakeLists.txt ├── main ├── CMakeLists.txt ├── idf_component.yml └── main.c ├── sdkconfig.ci └── sdkconfig.defaults /.devcontainer/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM espressif/idf 2 | 3 | ARG DEBIAN_FRONTEND=nointeractive 4 | ARG CONTAINER_USER=esp 5 | ARG USER_UID=1000 6 | ARG USER_GID=$USER_UID 7 | 8 | RUN apt-get update \ 9 | && apt install -y -q \ 10 | cmake \ 11 | git \ 12 | hwdata \ 13 | libglib2.0-0 \ 14 | libnuma1 \ 15 | libpixman-1-0 \ 16 | linux-tools-virtual \ 17 | && rm -rf /var/lib/apt/lists/* 18 | 19 | RUN update-alternatives --install /usr/local/bin/usbip usbip `ls /usr/lib/linux-tools/*/usbip | tail -n1` 20 20 | 21 | # QEMU 22 | ENV QEMU_REL=esp-develop-20220919 23 | ENV QEMU_SHA256=f6565d3f0d1e463a63a7f81aec94cce62df662bd42fc7606de4b4418ed55f870 24 | ENV QEMU_DIST=qemu-${QEMU_REL}.tar.bz2 25 | ENV QEMU_URL=https://github.com/espressif/qemu/releases/download/${QEMU_REL}/${QEMU_DIST} 26 | 27 | ENV LC_ALL=C.UTF-8 28 | ENV LANG=C.UTF-8 29 | 30 | RUN wget --no-verbose ${QEMU_URL} \ 31 | && echo "${QEMU_SHA256} *${QEMU_DIST}" | sha256sum --check --strict - \ 32 | && tar -xf $QEMU_DIST -C /opt \ 33 | && rm ${QEMU_DIST} 34 | 35 | ENV PATH=/opt/qemu/bin:${PATH} 36 | 37 | RUN groupadd --gid $USER_GID $CONTAINER_USER \ 38 | && adduser --uid $USER_UID --gid $USER_GID --disabled-password --gecos "" ${CONTAINER_USER} \ 39 | && usermod -a -G dialout $CONTAINER_USER 40 | USER ${CONTAINER_USER} 41 | ENV USER=${CONTAINER_USER} 42 | WORKDIR /home/${CONTAINER_USER} 43 | 44 | RUN echo "source /opt/esp/idf/export.sh > /dev/null 2>&1" >> ~/.bashrc 45 | 46 | ENTRYPOINT [ "/opt/esp/entrypoint.sh" ] 47 | 48 | CMD ["/bin/bash", "-c"] -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | // For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: 2 | // https://github.com/microsoft/vscode-dev-containers/tree/v0.183.0/containers/ubuntu 3 | { 4 | "name": "ESP-IDF QEMU", 5 | "build": { 6 | "dockerfile": "Dockerfile" 7 | }, 8 | // Add the IDs of extensions you want installed when the container is created 9 | "workspaceMount": "source=${localWorkspaceFolder},target=${localWorkspaceFolder},type=bind", 10 | /* the path of workspace folder to be opened after container is running 11 | */ 12 | "workspaceFolder": "${localWorkspaceFolder}", 13 | "mounts": [ 14 | "source=extensionCache,target=/root/.vscode-server/extensions,type=volume" 15 | ], 16 | "customizations": { 17 | "vscode": { 18 | "settings": { 19 | "terminal.integrated.defaultProfile.linux": "bash", 20 | "idf.espIdfPath": "/opt/esp/idf", 21 | "idf.customExtraPaths": "", 22 | "idf.pythonBinPath": "/opt/esp/python_env/idf5.1_py3.8_env/bin/python", 23 | "idf.toolsPath": "/opt/esp", 24 | "idf.gitPath": "/usr/bin/git" 25 | }, 26 | "extensions": [ 27 | "ms-vscode.cpptools", 28 | "espressif.esp-idf-extension" 29 | ], 30 | }, 31 | "codespaces": { 32 | "settings": { 33 | "terminal.integrated.defaultProfile.linux": "bash", 34 | "idf.espIdfPath": "/opt/esp/idf", 35 | "idf.customExtraPaths": "", 36 | "idf.pythonBinPath": "/opt/esp/python_env/idf5.1_py3.8_env/bin/python", 37 | "idf.toolsPath": "/opt/esp", 38 | "idf.gitPath": "/usr/bin/git" 39 | }, 40 | "extensions": [ 41 | "ms-vscode.cpptools", 42 | "espressif.esp-idf-extension" 43 | ], 44 | } 45 | }, 46 | "runArgs": ["--privileged"] 47 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # VS Code Settings 2 | .vscode/ 3 | 4 | # Example project files 5 | examples/**/sdkconfig 6 | examples/**/sdkconfig.old 7 | examples/**/build 8 | 9 | # lock files for examples and components 10 | dependencies.lock 11 | 12 | # managed_components for examples 13 | managed_components 14 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # CherryUSB Examples for ESP 2 | 3 | This is the examples repository for the [CherryUSB](https://github.com/cherry-embedded/CherryUSB), which is a tiny and portable USB Stack (device & host) for embedded system with USB IP. 4 | 5 | This repository is wrapped as an ESP-IDF component and finally published to [Component Registry](https://components.espressif.com/). 6 | 7 | You can build the examples in this repository with **ESP-IDF v4.4.1 or later** directly. Or using the ESP-IDF component manager. 8 | 9 | ## How to add this component from esp-registry to your project 10 | 11 | Just add ``idf_component.yml`` to your main component with the following content:: 12 | 13 | ```yaml 14 | ## IDF Component Manager Manifest File 15 | dependencies: 16 | cherry-embedded/cherryusb: "^1.5.1~0" 17 | ``` 18 | 19 | Or simply run: 20 | 21 | ``` 22 | idf.py add-dependency "cherry-embedded/cherryusb" 23 | ``` 24 | 25 | During the build process, the ESP-IDF build system will automatically download and install this component. 26 | 27 | ## API Documentation 28 | 29 | 1. Library introduction can be found on [README](https://github.com/cherry-embedded/CherryUSB/blob/master/README.md) from the upstream CherryUSB. 30 | 2. Full API code documentations and step by step guides can be found in [CherryUSB Docs Website](https://cherryusb.readthedocs.io/). -------------------------------------------------------------------------------- /examples/device/CMakeLists.txt: -------------------------------------------------------------------------------- 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.16) 4 | 5 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 6 | 7 | project(cherryusb) 8 | -------------------------------------------------------------------------------- /examples/device/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | idf_component_register(SRCS "main.c" 3 | INCLUDE_DIRS ".") 4 | -------------------------------------------------------------------------------- /examples/device/main/idf_component.yml: -------------------------------------------------------------------------------- 1 | ## IDF Component Manager Manifest File 2 | dependencies: 3 | cherry-embedded/cherryusb: "^1.5.0" 4 | ## Required IDF version 5 | idf: 6 | version: ">=4.1.0" 7 | # # Put list of dependencies here 8 | # # For components maintained by Espressif: 9 | # component: "~1.0.0" 10 | # # For 3rd party components: 11 | # username/component: ">=1.0.0,<2.0.0" 12 | # username2/component2: 13 | # version: "~1.0.0" 14 | # # For transient dependencies `public` flag can be set. 15 | # # `public` flag doesn't have an effect dependencies of the `main` component. 16 | # # All dependencies of `main` are public by default. 17 | # public: true 18 | -------------------------------------------------------------------------------- /examples/device/main/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD 3 | * 4 | * SPDX-License-Identifier: CC0-1.0 5 | */ 6 | 7 | #include 8 | #include 9 | #include "sdkconfig.h" 10 | #include "freertos/FreeRTOS.h" 11 | #include "freertos/task.h" 12 | #include "esp_chip_info.h" 13 | #include "esp_flash.h" 14 | #include "esp_system.h" 15 | #include "usbd_core.h" 16 | #include "usbh_core.h" 17 | #include "demo/cdc_acm_msc_template.c" 18 | 19 | extern void cdc_acm_msc_init(uint8_t busid, uintptr_t reg_base); 20 | 21 | void app_main(void) 22 | { 23 | USB_LOG_INFO("Hello CherryUSB!\n"); 24 | 25 | cdc_acm_msc_init(0, 0x60080000); 26 | while(1) 27 | { 28 | vTaskDelay(10); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /examples/device/sdkconfig.ci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CherryUSB/cherryusb_esp32/de730108cf02883a82d132d895f226ff5ed34625/examples/device/sdkconfig.ci -------------------------------------------------------------------------------- /examples/device/sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | # This file was generated using idf.py save-defconfig. It can be edited manually. 2 | # 3 | CONFIG_CHERRYUSB=y 4 | CONFIG_CHERRYUSB_DEVICE=y 5 | CONFIG_CHERRYUSB_DEVICE_CDC_ACM=y 6 | CONFIG_CHERRYUSB_DEVICE_HID=y 7 | CONFIG_CHERRYUSB_DEVICE_MSC=y 8 | -------------------------------------------------------------------------------- /examples/host/CMakeLists.txt: -------------------------------------------------------------------------------- 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.16) 4 | 5 | include($ENV{IDF_PATH}/tools/cmake/project.cmake) 6 | 7 | project(cherryusb) 8 | -------------------------------------------------------------------------------- /examples/host/main/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | idf_component_register(SRCS "main.c" 3 | INCLUDE_DIRS ".") 4 | -------------------------------------------------------------------------------- /examples/host/main/idf_component.yml: -------------------------------------------------------------------------------- 1 | ## IDF Component Manager Manifest File 2 | dependencies: 3 | ## Required IDF version 4 | idf: 5 | version: '>=4.1.0' 6 | # # Put list of dependencies here 7 | # # For components maintained by Espressif: 8 | # component: "~1.0.0" 9 | # # For 3rd party components: 10 | # username/component: ">=1.0.0,<2.0.0" 11 | # username2/component2: 12 | # version: "~1.0.0" 13 | # # For transient dependencies `public` flag can be set. 14 | # # `public` flag doesn't have an effect dependencies of the `main` component. 15 | # # All dependencies of `main` are public by default. 16 | # public: true 17 | cherry-embedded/cherryusb: ^1.5.0 18 | -------------------------------------------------------------------------------- /examples/host/main/main.c: -------------------------------------------------------------------------------- 1 | /* 2 | * SPDX-FileCopyrightText: 2010-2022 Espressif Systems (Shanghai) CO LTD 3 | * 4 | * SPDX-License-Identifier: CC0-1.0 5 | */ 6 | 7 | #include 8 | #include 9 | #include "sdkconfig.h" 10 | #include "freertos/FreeRTOS.h" 11 | #include "freertos/task.h" 12 | #include "esp_chip_info.h" 13 | #include "esp_flash.h" 14 | #include "esp_system.h" 15 | #include "esp_netif.h" 16 | #include "esp_event.h" 17 | #include "esp_log.h" 18 | #include "usbd_core.h" 19 | #include "usbh_core.h" 20 | #include "demo/usb_host.c" 21 | 22 | void app_main(void) 23 | { 24 | USB_LOG_INFO("Hello CherryUSB!\n"); 25 | 26 | // Initialize TCP/IP network interface aka the esp-netif (should be called only once in application) 27 | ESP_ERROR_CHECK(esp_netif_init()); 28 | // Create default event loop that running in background 29 | ESP_ERROR_CHECK(esp_event_loop_create_default()); 30 | 31 | usbh_initialize(0, 0x60080000); 32 | while(1) 33 | { 34 | vTaskDelay(10); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /examples/host/sdkconfig.ci: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CherryUSB/cherryusb_esp32/de730108cf02883a82d132d895f226ff5ed34625/examples/host/sdkconfig.ci -------------------------------------------------------------------------------- /examples/host/sdkconfig.defaults: -------------------------------------------------------------------------------- 1 | # This file was generated using idf.py save-defconfig. It can be edited manually. 2 | # 3 | CONFIG_CHERRYUSB=y 4 | CONFIG_CHERRYUSB_HOST=y 5 | CONFIG_CHERRYUSB_HOST_CUSTOM=y 6 | CONFIG_CHERRYUSB_HOST_CDC_ACM=y 7 | CONFIG_CHERRYUSB_HOST_HID=y 8 | CONFIG_CHERRYUSB_HOST_CDC_RNDIS=y 9 | --------------------------------------------------------------------------------