Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions .github/ci/override_managed_component.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#!/usr/bin/env python
#
# SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0

import sys
import argparse
import yaml
from pathlib import Path
from glob import glob
from idf_component_tools.manager import ManifestManager


def override_with_local_component(component, local_path, app):
app_path = Path(app)

absolute_local_path = Path(local_path).absolute()
if not absolute_local_path.exists():
print('[Error] {} path does not exist'.format(local_path))
raise Exception
if not app_path.exists():
print('[Error] {} path does not exist'.format(app_path))
raise Exception

print('[Info] Processing app {}'.format(app))
manager = ManifestManager(app_path / 'main', 'app')
if '/' not in component:
# Prepend with default namespace
component = 'espressif/' + component

try:
manifest_tree = yaml.safe_load(Path(manager.path).read_text())
manifest_tree['dependencies'][component] = {
'version': '*',
'override_path': str(absolute_local_path)
}
with open(manager.path, 'w') as f:
yaml.dump(manifest_tree, f, allow_unicode=True, Dumper=yaml.SafeDumper)
except KeyError:
print('[Error] {} app does not depend on {}'.format(app, component))
raise KeyError

def override_with_local_component_all(component, local_path, apps):
# Process wildcard, e.g. "app_prefix_*"
apps_with_glob = list()
for app in apps:
apps_with_glob += glob(app)

# Go through all collected apps
for app in apps_with_glob:
try:
override_with_local_component(component, local_path, app)
except:
print("[Error] Could not process app {}".format(app))
return -1
return 0


if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('component', help='Existing component that the app depends on')
parser.add_argument('local_path', help='Path to component that will be used instead of the managed version')
parser.add_argument('apps', nargs='*', help='List of apps to process')
args = parser.parse_args()
sys.exit(override_with_local_component_all(args.component, args.local_path, args.apps))
81 changes: 81 additions & 0 deletions .github/workflows/build_and_run_esp_usb_test_apps.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: ESP-USB Test Apps

on:
pull_request:
types: [opened, reopened, synchronize]

jobs:
build:
name: Build
strategy:
matrix:
idf_ver: ["release-v5.1", "release-v5.2", "release-v5.3", "release-v5.4", "release-v5.5", "latest"]
runs-on: ubuntu-latest
container: espressif/idf:${{ matrix.idf_ver }}
env:
ESP_USB_MANIFEST: ./esp-usb/.build-test-rules.yml
ESP_TINYUSB_TEST_APPS: ./esp-usb/device/esp_tinyusb/test_apps
steps:
- uses: actions/checkout@v4
with:
submodules: 'true'
- name: Clone esp-usb repository
run: |
git clone https://github.com/espressif/esp-usb.git
- name: Build
shell: bash
run: |
. ${IDF_PATH}/export.sh
pip install --no-cache-dir idf-component-manager>=2.1.2 idf-build-apps pyyaml --upgrade
export PEDANTIC_FLAGS="-DIDF_CI_BUILD -Werror -Werror=deprecated-declarations -Werror=unused-variable -Werror=unused-but-set-variable -Werror=unused-function"
export EXTRA_CFLAGS="${PEDANTIC_FLAGS} -Wstrict-prototypes"
export EXTRA_CXXFLAGS="${PEDANTIC_FLAGS}"
python .github/ci/override_managed_component.py tinyusb . ${{ env.ESP_TINYUSB_TEST_APPS }}/*/
idf-build-apps find --path ${{ env.ESP_TINYUSB_TEST_APPS }}/ --recursive --target esp32s2 --manifest-file ${{ env.ESP_USB_MANIFEST }}
idf-build-apps build --path ${{ env.ESP_TINYUSB_TEST_APPS }}/ --recursive --target esp32s2 --manifest-file ${{ env.ESP_USB_MANIFEST }}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Build only for esp32s2 ? Since you are using build-test-rules.yml from esp-usb you can set --target all and the SOC_CAPS will sort the targets.

Copy link

@roma-jam roma-jam Oct 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we also have the network example in the build step, apply --target all is relevant only for usb_test_apps.
Enabling the same in the esp_idf_examples will lead to build the sta2eth example for all supported targets, not only the one relevant for us.

UPD:

part of the log from the last run (duration of the step ~6 minutes):

(cmake) App /opt/esp/idf/examples/network/sta2eth/, target esp32, sdkconfig (default), build in /opt/esp/idf/examples/network/sta2eth/build
45
(cmake) App /opt/esp/idf/examples/network/sta2eth/, target esp32c2, sdkconfig (default), build in /opt/esp/idf/examples/network/sta2eth/build
46
(cmake) App /opt/esp/idf/examples/network/sta2eth/, target esp32c3, sdkconfig (default), build in /opt/esp/idf/examples/network/sta2eth/build
47
(cmake) App /opt/esp/idf/examples/network/sta2eth/, target esp32c6, sdkconfig (default), build in /opt/esp/idf/examples/network/sta2eth/build
48
(cmake) App /opt/esp/idf/examples/network/sta2eth/, target esp32s2, sdkconfig (default), build in /opt/esp/idf/examples/network/sta2eth/build
49
(cmake) App /opt/esp/idf/examples/network/sta2eth/, target esp32s3, sdkconfig (default), build in /opt/esp/idf/examples/network/sta2eth/build

- uses: actions/upload-artifact@v4
with:
name: usb_test_app_bin_${{ matrix.idf_ver }}
path: |
${{env.ESP_TINYUSB_TEST_APPS}}/**/build/bootloader/bootloader.bin
${{env.ESP_TINYUSB_TEST_APPS}}/**/build/partition_table/partition-table.bin
${{env.ESP_TINYUSB_TEST_APPS}}/**/build/test_app_*.bin
${{env.ESP_TINYUSB_TEST_APPS}}/**/build/test_app_*.elf
${{env.ESP_TINYUSB_TEST_APPS}}/**/build/flasher_args.json
${{env.ESP_TINYUSB_TEST_APPS}}/**/build/config/sdkconfig.json
if-no-files-found: error

run-target:
name: Run
if: ${{ github.repository_owner == 'espressif' }}
needs: build
strategy:
matrix:
idf_ver: ["release-v5.1", "release-v5.2", "release-v5.3", "release-v5.4", "release-v5.5", "latest"]
idf_target: ["esp32s2"]
runner_tag: ["usb_device"]
runs-on: [self-hosted, linux, docker, "${{ matrix.idf_target }}", "${{ matrix.runner_tag }}"]
container:
image: python:3.11-bookworm
options: --privileged --device-cgroup-rule="c 188:* rmw" --device-cgroup-rule="c 166:* rmw"
env:
ESP_TINYUSB_TEST_APPS: ./esp-usb/device/esp_tinyusb/test_apps
steps:
- uses: actions/checkout@v4
- name: Clone esp-usb repository
run: |
git clone https://github.com/espressif/esp-usb.git
- name: ⚙️ Install System tools
run: |
apt update
apt install -y usbutils
- name: Install Python packages
env:
PIP_EXTRA_INDEX_URL: "https://dl.espressif.com/pypi/"
run: pip install --only-binary cryptography pytest-embedded pytest-embedded-serial-esp pytest-embedded-idf pyserial pyusb
- uses: actions/download-artifact@v4
with:
name: usb_test_app_bin_${{ matrix.idf_ver }}
path: ${{env.ESP_TINYUSB_TEST_APPS}}
- name: Run USB Test App on target
run: pytest ${{env.ESP_TINYUSB_TEST_APPS}} --embedded-services esp,idf --target=${{ matrix.idf_target }} -m ${{ matrix.runner_tag }}
86 changes: 86 additions & 0 deletions .github/workflows/build_and_run_idf_examples.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: ESP-IDF USB Device examples

on:
pull_request:
types: [opened, reopened, synchronize]

jobs:
build:
strategy:
matrix:
idf_ver: ["release-v5.1", "release-v5.2", "release-v5.3", "release-v5.4", "release-v5.5", "latest"]
fail-fast: false
runs-on: ubuntu-latest
container: espressif/idf:${{ matrix.idf_ver }}
steps:
- uses: actions/checkout@v4
- name: Install Python dependencies
shell: bash
run: |
. ${IDF_PATH}/export.sh
pip install --no-cache-dir idf-component-manager>=2.1.2 idf-build-apps pyyaml --upgrade
- name: Build Network USB related examples
shell: bash
run: |
. ${IDF_PATH}/export.sh
export EXAMPLES_PATH="${IDF_PATH}/examples/network/sta2eth"
export MANIFEST_FILE="${IDF_PATH}/examples/network/.build-test-rules.yml"
idf-build-apps find --path ${EXAMPLES_PATH}/ --target esp32s2 --manifest-file ${MANIFEST_FILE}
idf-build-apps build --path ${EXAMPLES_PATH}/ --target esp32s2 --manifest-file ${MANIFEST_FILE}
- name: Build USB Device examples
shell: bash
run: |
. ${IDF_PATH}/export.sh
export EXAMPLES_PATH="${IDF_PATH}/examples/peripherals/usb/device"
export MANIFEST_FILE="${IDF_PATH}/examples/peripherals/.build-test-rules.yml"
python .github/ci/override_managed_component.py tinyusb . ${EXAMPLES_PATH}/tusb_*
idf-build-apps find --path ${EXAMPLES_PATH}/ --recursive --target esp32s2 --manifest-file ${MANIFEST_FILE}
idf-build-apps build --path ${EXAMPLES_PATH}/ --recursive --target esp32s2 --manifest-file ${MANIFEST_FILE}
- uses: actions/upload-artifact@v4
with:
# We upload only the USB Device example binaries to run them on the target
name: usb_device_tusb_apps_bin_${{ matrix.idf_ver }}
path: |
/opt/esp/idf/examples/peripherals/usb/device/tusb_*/build/bootloader/bootloader.bin
/opt/esp/idf/examples/peripherals/usb/device/tusb_*/build/partition_table/partition-table.bin
/opt/esp/idf/examples/peripherals/usb/device/tusb_*/build/tusb_*.bin
/opt/esp/idf/examples/peripherals/usb/device/tusb_*/build/tusb_*.elf
/opt/esp/idf/examples/peripherals/usb/device/tusb_*/build/flasher_args.json
/opt/esp/idf/examples/peripherals/usb/device/tusb_*/build/config/sdkconfig.json
if-no-files-found: error
run-target:
name: Run USB Device examples
if: ${{ github.repository_owner == 'espressif' }}
needs: build
strategy:
fail-fast: false
matrix:
idf_ver: ["release-v5.3", "release-v5.4", "release-v5.5" , "latest"]
idf_target: ["esp32s2"]
runner_tag: ["usb_device"]
runs-on: [self-hosted, linux, docker, "${{ matrix.idf_target }}", "${{ matrix.runner_tag }}"]
container:
image: espressif/idf:${{ matrix.idf_ver }}
options: --privileged --device-cgroup-rule="c 188:* rmw" --device-cgroup-rule="c 166:* rmw"
steps:
- name: ⚙️ Install System tools
run: |
apt update
apt install net-tools
- name: ⚙️ Install Python packages
env:
PIP_EXTRA_INDEX_URL: "https://dl.espressif.com/pypi/"
run: |
cd ${IDF_PATH}
. ./export.sh
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
- uses: actions/download-artifact@v4
with:
name: usb_device_tusb_apps_bin_${{ matrix.idf_ver }}
path: /opt/esp/idf/examples/peripherals/usb/device
- name: Run USB Test App on target
run: |
cd ${IDF_PATH}
. ./export.sh
export EXAMPLES_PATH="${IDF_PATH}/examples/peripherals/usb/device"
pytest ${EXAMPLES_PATH} --target ${{ matrix.idf_target }} -m ${{ matrix.runner_tag }} --ignore-result-cases=*ncm_example
33 changes: 33 additions & 0 deletions .github/workflows/build_iot_examples.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: ESP IoT Solution - USB Device Examples

on:
pull_request:
types: [opened, reopened, synchronize]

jobs:
build:
strategy:
matrix:
idf_ver: ["release-v5.3", "release-v5.4", "release-v5.5", "latest"]
name: ["usb_uart_bridge"]
runs-on: ubuntu-latest
container: espressif/idf:${{ matrix.idf_ver }}
env:
ESP_IOT_PATH: esp-iot-solution
MANIFEST_PATH: esp-iot-solution/examples/.build-rules.yml
EXAMPLE_PATH: esp-iot-solution/examples/usb/device/${{ matrix.name }}
steps:
- uses: actions/checkout@v4
with:
submodules: 'true'
- name: Clone esp-iot-solution repository
run: |
git clone https://github.com/espressif/esp-iot-solution.git
- name: Build
shell: bash
run: |
. ${IDF_PATH}/export.sh
pip install --no-cache-dir idf-component-manager>=2.1.2 idf-build-apps pyyaml --upgrade
python .github/ci/override_managed_component.py tinyusb . ${{ env.EXAMPLE_PATH }}/
idf-build-apps find --paths ${{ env.EXAMPLE_PATH }} --target all --manifest-file ${{ env.MANIFEST_PATH }} --manifest-rootpath ${{ env.ESP_IOT_PATH }}
idf-build-apps build --paths ${{ env.EXAMPLE_PATH }} --target all --manifest-file ${{ env.MANIFEST_PATH }} --manifest-rootpath ${{ env.ESP_IOT_PATH }}
21 changes: 21 additions & 0 deletions .github/workflows/upload_component.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Push TinyUSB to Espressif Component Service

# If the commit is tagged, it will be uploaded. Other scenario silently fail.
on:
push:
tags:
- v*

jobs:
upload_components:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Upload components to component service
uses: espressif/upload-components-ci-action@v2
with:
components: "tinyusb: ."
version: ${{ github.ref_name }}
namespace: "espressif"
api_token: ${{ secrets.IDF_COMPONENT_API_TOKEN }}
80 changes: 80 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
idf_build_get_property(target IDF_TARGET)

if(${target} STREQUAL "esp32s3")
set(tusb_mcu "OPT_MCU_ESP32S3")
set(tusb_family "esp32sx")
elseif(${target} STREQUAL "esp32s2")
set(tusb_mcu "OPT_MCU_ESP32S2")
set(tusb_family "esp32sx")
elseif(${target} STREQUAL "esp32p4")
set(tusb_mcu "OPT_MCU_ESP32P4")
set(tusb_family "esp32px")
elseif(${target} STREQUAL "esp32h4")
set(tusb_mcu "OPT_MCU_ESP32H4")
set(tusb_family "esp32sx")
endif()

set(compile_options
"-DCFG_TUSB_MCU=${tusb_mcu}"
)

idf_component_get_property(freertos_include freertos ORIG_INCLUDE_PATH)

set(includes_private
"src/"
"src/device"
"lib/networking" # For RNDIS definitions
)

set(includes_public
"src/"
# The FreeRTOS API include convention in tinyusb is different from esp-idf
"${freertos_include}"
)

set(srcs
"src/class/cdc/cdc_device.c"
"src/class/hid/hid_device.c"
"src/class/midi/midi_device.c"
"src/class/msc/msc_device.c"
"src/class/vendor/vendor_device.c"
"src/class/audio/audio_device.c"
"src/class/video/video_device.c"
"src/class/bth/bth_device.c"
"src/class/usbtmc/usbtmc_device.c"
# NET class
"src/class/net/ecm_rndis_device.c"
"lib/networking/rndis_reports.c"
"src/class/net/ncm_device.c"
# DFU
"src/class/dfu/dfu_device.c"
"src/class/dfu/dfu_rt_device.c"
# Common, device-mode related
"src/portable/synopsys/dwc2/dcd_dwc2.c"
"src/portable/synopsys/dwc2/dwc2_common.c"
"src/common/tusb_fifo.c"
"src/device/usbd_control.c"
"src/device/usbd.c"
"src/tusb.c"
)

set(requirements_private
esp_netif # required by rndis_reports.c: #include "netif/ethernet.h"
)

if(${target} STREQUAL "esp32p4")
list(APPEND requirements_private
esp_mm # required by dcd_dwc2.c: #include "esp_cache.h"
)
endif()

idf_component_register(SRCS ${srcs}
INCLUDE_DIRS ${includes_public}
PRIV_INCLUDE_DIRS ${includes_private}
PRIV_REQUIRES ${requirements_private}
)

target_compile_options(${COMPONENT_LIB} PUBLIC ${compile_options})

# when no builtin class driver is enabled, an uint8_t data compared with `BUILTIN_DRIVER_COUNT` will always be false
set_source_files_properties("src/device/usbd.c" PROPERTIES COMPILE_FLAGS "-Wno-type-limits")
Loading