Skip to content

Commit 0c3af3a

Browse files
feat: Porting commit for version 0.19
1 parent 331c263 commit 0c3af3a

File tree

8 files changed

+388
-0
lines changed

8 files changed

+388
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
name: ESP-USB Test Apps
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened, synchronize]
6+
7+
jobs:
8+
build:
9+
name: Build
10+
strategy:
11+
matrix:
12+
idf_ver: ["release-v5.1", "release-v5.2", "release-v5.3", "release-v5.4", "release-v5.5", "latest"]
13+
runs-on: ubuntu-latest
14+
container: espressif/idf:${{ matrix.idf_ver }}
15+
env:
16+
ESP_USB_MANIFEST: ./esp-usb/.build-test-rules.yml
17+
ESP_TINYUSB_TEST_APPS: ./esp-usb/device/esp_tinyusb/test_apps
18+
steps:
19+
- uses: actions/checkout@v4
20+
with:
21+
submodules: 'true'
22+
- name: Clone esp-usb repository
23+
run: |
24+
git clone https://github.com/espressif/esp-usb.git
25+
- name: Build
26+
shell: bash
27+
run: |
28+
. ${IDF_PATH}/export.sh
29+
pip install --no-cache-dir idf-component-manager>=2.1.2 idf-build-apps==2.4.3 pyyaml --upgrade
30+
export PEDANTIC_FLAGS="-DIDF_CI_BUILD -Werror -Werror=deprecated-declarations -Werror=unused-variable -Werror=unused-but-set-variable -Werror=unused-function"
31+
export EXTRA_CFLAGS="${PEDANTIC_FLAGS} -Wstrict-prototypes"
32+
export EXTRA_CXXFLAGS="${PEDANTIC_FLAGS}"
33+
python .github/ci/override_managed_component.py tinyusb . ${{ env.ESP_TINYUSB_TEST_APPS }}/*/
34+
idf-build-apps find --path ${{ env.ESP_TINYUSB_TEST_APPS }}/ --recursive --target esp32s2 --manifest-file ${{ env.ESP_USB_MANIFEST }}
35+
idf-build-apps build --path ${{ env.ESP_TINYUSB_TEST_APPS }}/ --recursive --target esp32s2 --manifest-file ${{ env.ESP_USB_MANIFEST }}
36+
- uses: actions/upload-artifact@v4
37+
with:
38+
name: usb_test_app_bin_${{ matrix.idf_ver }}
39+
path: |
40+
${{env.ESP_TINYUSB_TEST_APPS}}/**/build/bootloader/bootloader.bin
41+
${{env.ESP_TINYUSB_TEST_APPS}}/**/build/partition_table/partition-table.bin
42+
${{env.ESP_TINYUSB_TEST_APPS}}/**/build/test_app_*.bin
43+
${{env.ESP_TINYUSB_TEST_APPS}}/**/build/test_app_*.elf
44+
${{env.ESP_TINYUSB_TEST_APPS}}/**/build/flasher_args.json
45+
${{env.ESP_TINYUSB_TEST_APPS}}/**/build/config/sdkconfig.json
46+
if-no-files-found: error
47+
48+
run-target:
49+
name: Run
50+
if: ${{ github.repository_owner == 'espressif' }}
51+
needs: build
52+
strategy:
53+
matrix:
54+
idf_ver: ["release-v5.1", "release-v5.2", "release-v5.3", "release-v5.4", "release-v5.5", "latest"]
55+
idf_target: ["esp32s2"]
56+
runner_tag: ["usb_device"]
57+
runs-on: [self-hosted, linux, docker, "${{ matrix.idf_target }}", "${{ matrix.runner_tag }}"]
58+
container:
59+
image: python:3.11-bookworm
60+
options: --privileged --device-cgroup-rule="c 188:* rmw" --device-cgroup-rule="c 166:* rmw"
61+
env:
62+
ESP_TINYUSB_TEST_APPS: ./esp-usb/device/esp_tinyusb/test_apps
63+
steps:
64+
- uses: actions/checkout@v4
65+
- name: Clone esp-usb repository
66+
run: |
67+
git clone https://github.com/espressif/esp-usb.git
68+
- name: ⚙️ Install System tools
69+
run: |
70+
apt update
71+
apt install -y usbutils
72+
- name: Install Python packages
73+
env:
74+
PIP_EXTRA_INDEX_URL: "https://dl.espressif.com/pypi/"
75+
run: pip install --only-binary cryptography pytest-embedded pytest-embedded-serial-esp pytest-embedded-idf pyserial pyusb
76+
- uses: actions/download-artifact@v4
77+
with:
78+
name: usb_test_app_bin_${{ matrix.idf_ver }}
79+
path: ${{env.ESP_TINYUSB_TEST_APPS}}
80+
- name: Run USB Test App on target
81+
run: pytest ${{env.ESP_TINYUSB_TEST_APPS}} --embedded-services esp,idf --target=${{ matrix.idf_target }} -m ${{ matrix.runner_tag }}
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
name: ESP-IDF USB Device examples
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened, synchronize]
6+
7+
jobs:
8+
build:
9+
strategy:
10+
matrix:
11+
idf_ver: ["release-v5.1", "release-v5.2", "release-v5.3", "release-v5.4", "release-v5.5", "latest"]
12+
fail-fast: false
13+
runs-on: ubuntu-latest
14+
container: espressif/idf:${{ matrix.idf_ver }}
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Install Python dependencies
18+
shell: bash
19+
run: |
20+
. ${IDF_PATH}/export.sh
21+
pip install --no-cache-dir idf-component-manager>=2.1.2 idf-build-apps==2.4.3 pyyaml --upgrade
22+
- name: Build Network USB related examples
23+
shell: bash
24+
run: |
25+
. ${IDF_PATH}/export.sh
26+
export EXAMPLES_PATH="${IDF_PATH}/examples/network/sta2eth"
27+
export MANIFEST_FILE="${IDF_PATH}/examples/network/.build-test-rules.yml"
28+
idf-build-apps find --path ${EXAMPLES_PATH}/ --target esp32s2 --manifest-file ${MANIFEST_FILE}
29+
idf-build-apps build --path ${EXAMPLES_PATH}/ --target esp32s2 --manifest-file ${MANIFEST_FILE}
30+
- name: Build USB Device examples
31+
shell: bash
32+
run: |
33+
. ${IDF_PATH}/export.sh
34+
export EXAMPLES_PATH="${IDF_PATH}/examples/peripherals/usb/device"
35+
export MANIFEST_FILE="${IDF_PATH}/examples/peripherals/.build-test-rules.yml"
36+
python .github/ci/override_managed_component.py tinyusb . ${EXAMPLES_PATH}/tusb_*
37+
idf-build-apps find --path ${EXAMPLES_PATH}/ --recursive --target esp32s2 --manifest-file ${MANIFEST_FILE}
38+
idf-build-apps build --path ${EXAMPLES_PATH}/ --recursive --target esp32s2 --manifest-file ${MANIFEST_FILE}
39+
- uses: actions/upload-artifact@v4
40+
with:
41+
# We upload only the USB Device example binaries to run them on the target
42+
name: usb_device_tusb_apps_bin_${{ matrix.idf_ver }}
43+
path: |
44+
/opt/esp/idf/examples/peripherals/usb/device/tusb_*/build/bootloader/bootloader.bin
45+
/opt/esp/idf/examples/peripherals/usb/device/tusb_*/build/partition_table/partition-table.bin
46+
/opt/esp/idf/examples/peripherals/usb/device/tusb_*/build/tusb_*.bin
47+
/opt/esp/idf/examples/peripherals/usb/device/tusb_*/build/tusb_*.elf
48+
/opt/esp/idf/examples/peripherals/usb/device/tusb_*/build/flasher_args.json
49+
/opt/esp/idf/examples/peripherals/usb/device/tusb_*/build/config/sdkconfig.json
50+
if-no-files-found: error
51+
run-target:
52+
name: Run USB Device examples
53+
if: ${{ github.repository_owner == 'espressif' }}
54+
needs: build
55+
strategy:
56+
fail-fast: false
57+
matrix:
58+
idf_ver: ["release-v5.3", "release-v5.4", "release-v5.5" , "latest"]
59+
idf_target: ["esp32s2"]
60+
runner_tag: ["usb_device"]
61+
runs-on: [self-hosted, linux, docker, "${{ matrix.idf_target }}", "${{ matrix.runner_tag }}"]
62+
container:
63+
image: espressif/idf:${{ matrix.idf_ver }}
64+
options: --privileged --device-cgroup-rule="c 188:* rmw" --device-cgroup-rule="c 166:* rmw"
65+
steps:
66+
- name: ⚙️ Install System tools
67+
run: |
68+
apt update
69+
apt install net-tools
70+
- name: ⚙️ Install Python packages
71+
env:
72+
PIP_EXTRA_INDEX_URL: "https://dl.espressif.com/pypi/"
73+
run: |
74+
cd ${IDF_PATH}
75+
. ./export.sh
76+
pip install --no-cache-dir --only-binary cryptography pytest-embedded pytest-embedded-serial-esp pytest-embedded-jtag pytest-embedded-idf pyserial pyusb python-gitlab minio idf-build-apps idf_ci pytest_ignore_test_results pytest-timeout netifaces
77+
- uses: actions/download-artifact@v4
78+
with:
79+
name: usb_device_tusb_apps_bin_${{ matrix.idf_ver }}
80+
path: /opt/esp/idf/examples/peripherals/usb/device
81+
- name: Run USB Test App on target
82+
run: |
83+
cd ${IDF_PATH}
84+
. ./export.sh
85+
export EXAMPLES_PATH="${IDF_PATH}/examples/peripherals/usb/device"
86+
pytest ${EXAMPLES_PATH} --target ${{ matrix.idf_target }} -m ${{ matrix.runner_tag }} --ignore-result-cases=*ncm_example
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: ESP IoT Solution - USB Device Examples
2+
3+
on:
4+
pull_request:
5+
types: [opened, reopened, synchronize]
6+
7+
jobs:
8+
build:
9+
strategy:
10+
matrix:
11+
idf_ver: ["release-v5.3", "release-v5.4", "release-v5.5", "latest"]
12+
name: ["usb_uart_bridge"]
13+
runs-on: ubuntu-latest
14+
container: espressif/idf:${{ matrix.idf_ver }}
15+
env:
16+
ESP_IOT_PATH: esp-iot-solution
17+
MANIFEST_PATH: esp-iot-solution/examples/.build-rules.yml
18+
EXAMPLE_PATH: esp-iot-solution/examples/usb/device/${{ matrix.name }}
19+
steps:
20+
- uses: actions/checkout@v4
21+
with:
22+
submodules: 'true'
23+
- name: Clone esp-iot-solution repository
24+
run: |
25+
git clone https://github.com/espressif/esp-iot-solution.git
26+
- name: Build
27+
shell: bash
28+
run: |
29+
. ${IDF_PATH}/export.sh
30+
pip install --no-cache-dir idf-component-manager>=2.1.2 idf-build-apps==2.4.3 pyyaml --upgrade
31+
python .github/ci/override_managed_component.py tinyusb . ${{ env.EXAMPLE_PATH }}/
32+
idf-build-apps find --paths ${{ env.EXAMPLE_PATH }} --target all --manifest-file ${{ env.MANIFEST_PATH }} --manifest-rootpath ${{ env.ESP_IOT_PATH }}
33+
idf-build-apps build --paths ${{ env.EXAMPLE_PATH }} --target all --manifest-file ${{ env.MANIFEST_PATH }} --manifest-rootpath ${{ env.ESP_IOT_PATH }}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Push TinyUSB to Espressif Component Service
2+
3+
# If the commit is tagged, it will be uploaded. Other scenario silently fail.
4+
on:
5+
push:
6+
tags:
7+
- v*
8+
9+
jobs:
10+
upload_components:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Upload components to component service
16+
uses: espressif/upload-components-ci-action@v2
17+
with:
18+
components: "tinyusb: ."
19+
version: ${{ github.ref_name }}
20+
namespace: "espressif"
21+
api_token: ${{ secrets.IDF_COMPONENT_API_TOKEN }}

CMakeLists.txt

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
idf_build_get_property(target IDF_TARGET)
2+
3+
if(${target} STREQUAL "esp32s3")
4+
set(tusb_mcu "OPT_MCU_ESP32S3")
5+
set(tusb_family "esp32sx")
6+
elseif(${target} STREQUAL "esp32s2")
7+
set(tusb_mcu "OPT_MCU_ESP32S2")
8+
set(tusb_family "esp32sx")
9+
elseif(${target} STREQUAL "esp32p4")
10+
set(tusb_mcu "OPT_MCU_ESP32P4")
11+
set(tusb_family "esp32px")
12+
elseif(${target} STREQUAL "esp32h4")
13+
set(tusb_mcu "OPT_MCU_ESP32H4")
14+
set(tusb_family "esp32sx")
15+
endif()
16+
17+
set(compile_options
18+
"-DCFG_TUSB_MCU=${tusb_mcu}"
19+
)
20+
21+
idf_component_get_property(freertos_include freertos ORIG_INCLUDE_PATH)
22+
23+
set(includes_private
24+
"src/"
25+
"src/device"
26+
"lib/networking" # For RNDIS definitions
27+
)
28+
29+
set(includes_public
30+
"src/"
31+
# The FreeRTOS API include convention in tinyusb is different from esp-idf
32+
"${freertos_include}"
33+
)
34+
35+
set(srcs
36+
"src/class/cdc/cdc_device.c"
37+
"src/class/hid/hid_device.c"
38+
"src/class/midi/midi_device.c"
39+
"src/class/msc/msc_device.c"
40+
"src/class/vendor/vendor_device.c"
41+
"src/class/audio/audio_device.c"
42+
"src/class/video/video_device.c"
43+
"src/class/bth/bth_device.c"
44+
"src/class/usbtmc/usbtmc_device.c"
45+
# NET class
46+
"src/class/net/ecm_rndis_device.c"
47+
"lib/networking/rndis_reports.c"
48+
"src/class/net/ncm_device.c"
49+
# DFU
50+
"src/class/dfu/dfu_device.c"
51+
"src/class/dfu/dfu_rt_device.c"
52+
# Common, device-mode related
53+
"src/portable/synopsys/dwc2/dcd_dwc2.c"
54+
"src/portable/synopsys/dwc2/dwc2_common.c"
55+
"src/common/tusb_fifo.c"
56+
"src/device/usbd_control.c"
57+
"src/device/usbd.c"
58+
"src/tusb.c"
59+
)
60+
61+
set(requirements_private
62+
esp_netif # required by rndis_reports.c: #include "netif/ethernet.h"
63+
)
64+
65+
if(${target} STREQUAL "esp32p4")
66+
list(APPEND requirements_private
67+
esp_mm # required by dcd_dwc2.c: #include "esp_cache.h"
68+
)
69+
endif()
70+
71+
idf_component_register(SRCS ${srcs}
72+
INCLUDE_DIRS ${includes_public}
73+
PRIV_INCLUDE_DIRS ${includes_private}
74+
PRIV_REQUIRES ${requirements_private}
75+
)
76+
77+
target_compile_options(${COMPONENT_LIB} PUBLIC ${compile_options})
78+
79+
# when no builtin class driver is enabled, an uint8_t data compared with `BUILTIN_DRIVER_COUNT` will always be false
80+
set_source_files_properties("src/device/usbd.c" PROPERTIES COMPILE_FLAGS "-Wno-type-limits")

README.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Espressif TinyUSB component
2+
3+
[![Component Registry](https://components.espressif.com/components/espressif/tinyusb/badge.svg)](https://components.espressif.com/components/espressif/tinyusb)
4+
![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)
5+
[![ESP-IDF USB Device examples](https://github.com/espressif/tinyusb/actions/workflows/build_and_run_idf_examples.yml/badge.svg?branch=release%2Fv0.19)](https://github.com/espressif/tinyusb/actions/workflows/build_and_run_idf_examples.yml)
6+
7+
## Overview
8+
9+
This repository is Espressif’s maintained fork of [TinyUSB](https://github.com/hathach/tinyusb), integrated with the ESP-IDF build system. It exists to provide ESP users with timely TinyUSB updates, as upstream releases occur too infrequently to match Espressif’s hardware cadence. README from the upstream TinyUSB can be found in [hathach/tinyusb/README](https://github.com/hathach/tinyusb/blob/master/README.rst).
10+
11+
Only Device part of TinyUSB stack is supported. For Host mode, please refer to [espressif/usb](https://components.espressif.com/components/espressif/usb) component.
12+
13+
#### Examples
14+
15+
USB Device examples based on TinyUSB are present in [esp-idf](https://github.com/espressif/esp-idf/tree/master/examples/peripherals/usb/device).
16+
17+
## How to use
18+
19+
There are two options of using TinyUSB component with Espressif's SoCs:
20+
21+
### 1. Use component via [esp_tinyusb](https://components.espressif.com/components/espressif/esp_tinyusb)
22+
23+
[Espressif TinyUSB additions](https://github.com/espressif/esp-usb/tree/master/device/esp_tinyusb) (esp_tinyusb) provide several preconfigured features to use benefits of TinyUSB stack faster.
24+
25+
To use [Espressif TinyUSB additions](https://github.com/espressif/esp-usb/tree/master/device/esp_tinyusb), add ``idf_component.yml`` to your main component with the following content::
26+
27+
```yaml
28+
## IDF Component Manager Manifest File
29+
dependencies:
30+
esp_tinyusb: "^2.0.0" # Automatically update minor releases
31+
```
32+
33+
Or simply run:
34+
```sh
35+
idf.py add-dependency "esp_tinyusb^2.0.0"
36+
```
37+
38+
Then, the Espressif TinyUSB component will be added automatically during resolving dependencies by the component manager.
39+
40+
### 2. Using standalone TinyUSB
41+
42+
Use this option for custom TinyUSB applications.
43+
In this case you will have to provide configuration header file ``tusb_config.h``. More information about TinyUSB configuration can be found [in official TinyUSB documentation](https://docs.tinyusb.org/en/latest/reference/getting_started.html).
44+
45+
You will also have to tell TinyUSB where to find the configuration file. This can be achieved by adding following CMake snippet to your main component's ``CMakeLists.txt``:
46+
47+
```cmake
48+
idf_component_get_property(tusb_lib espressif__tinyusb COMPONENT_LIB)
49+
target_include_directories(${tusb_lib} PRIVATE path_to_your_tusb_config)
50+
```
51+
52+
Again, you can add this component to your project by adding ``idf_component.yml`` file:
53+
54+
```yaml
55+
## IDF Component Manager Manifest File
56+
dependencies:
57+
tinyusb: "~0.19.0" # TinyUSB does not guarantee backward compatibility
58+
```
59+
60+
Or simply run:
61+
```sh
62+
idf.py add-dependency "tinyusb~0.19.0"
63+
```

idf_component.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
description: TinyUSB ported to Espressif's SoCs
2+
url: https://docs.tinyusb.org/en/latest/
3+
documentation: "https://docs.tinyusb.org/en/latest/"
4+
repository: "https://github.com/espressif/tinyusb.git"
5+
issues: "https://github.com/hathach/tinyusb/issues"
6+
dependencies:
7+
idf: '>=5.0' # IDF 4.x contains TinyUSB as submodule
8+
files:
9+
exclude:
10+
- "docs/**/*"
11+
- "tools/**/*"
12+
- "lib/embedded-cli/**/*"
13+
- "lib/fatfs/**/*"
14+
- "lib/SEGGER_RTT/**/*"
15+
targets:
16+
- esp32s2
17+
- esp32s3
18+
- esp32p4
19+
- esp32h4
20+
tags:
21+
- usb
22+
- usb_device

sbom.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
supplier: 'Organization: Espressif Systems (Shanghai) CO LTD'
2+
originator: 'Person: Ha Thach <[email protected]>'

0 commit comments

Comments
 (0)