Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
107 changes: 107 additions & 0 deletions .github/workflows/twister_uhc_build_and_run.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: USB UHC Driver Test (esp32s3)

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

permissions:
contents: read

jobs:
twister-tests:
if: startsWith(github.head_ref, 'pr-add-') || github.event_name == 'workflow_dispatch'
runs-on: [self-hosted, docker, esp32s3, usb_host]

strategy:
matrix:
zephyr_ver: ["v0.29.2"]

container:
image: ghcr.io/zephyrproject-rtos/ci:${{ matrix.zephyr_ver }}
options: >-
--volume=/etc/zephyr:/etc/zephyr:ro
--device=/dev/ttyACM0

steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
path: ws/zephyr
fetch-depth: 0

- name: Setup Python deps (west + twister requirements)
shell: bash
run: |
python3 -m venv "$GITHUB_WORKSPACE/ws/.venv"
. "$GITHUB_WORKSPACE/ws/.venv/bin/activate"
pip install -U pip wheel esptool pyserial
pip install -r "$GITHUB_WORKSPACE/ws/zephyr/scripts/requirements.txt" \
-r "$GITHUB_WORKSPACE/ws/zephyr/scripts/requirements-build-test.txt"

- name: West init/update/export (modules + blobs)
shell: bash
run: |
. "$GITHUB_WORKSPACE/ws/.venv/bin/activate"
cd "$GITHUB_WORKSPACE/ws"

if [ ! -d .west ]; then
west init -l zephyr
fi

west update hal_espressif
west blobs fetch hal_espressif
west zephyr-export

- name: Locate Zephyr SDK in container
shell: bash
run: |
for d in /opt/zephyr-sdk* /opt/toolchains/zephyr-sdk* /usr/local/zephyr-sdk*; do
if [ -d "$d" ]; then
echo "Found Zephyr SDK at $d"
echo "ZEPHYR_SDK_INSTALL_DIR=$d" >> "$GITHUB_ENV"
break
fi
done

- name: Clean previous Twister output
shell: bash
run: |
rm -rf "$GITHUB_WORKSPACE/twister-out"
rm -rf "$GITHUB_WORKSPACE"/twister-out.*

- name: Build and run on hardware
shell: bash
env:
PYTEST_DISABLE_PLUGIN_AUTOLOAD: "1"
ZEPHYR_TOOLCHAIN_VARIANT: zephyr
run: |
git config --global --add safe.directory "$GITHUB_WORKSPACE/ws/zephyr"

. "$GITHUB_WORKSPACE/ws/.venv/bin/activate"
cd "$GITHUB_WORKSPACE/ws/zephyr"

west twister -T tests/drivers/uhc --list-tests

west twister \
-T tests/drivers/uhc \
-p esp32s3_devkitc/esp32s3/procpu \
-s drivers.usb.uhc \
--device-testing \
--device-serial /dev/ttyACM0 \
--flash-before \
--west-runner=esp32 \
--log-level debug \
-j 1 \
--outdir "$GITHUB_WORKSPACE/twister-out"

- name: Upload Twister reports
if: always()
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # v6.0.0
with:
name: twister-reports
path: |
twister-out/**/twister_harness.log
twister-out/twister.xml
twister-out/twister_report.xml
twister-out/twister.json
4 changes: 4 additions & 0 deletions boards/nordic/nrf54lm20dk/nrf54lm20_a_b_cpuapp_common.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ temp_sensor: &temp {
status = "okay";
};

zephyr_uhc0: &usbhs {
status = "okay";
};

zephyr_udc0: &usbhs {
status = "okay";
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ supported:
- pwm
- spi
- usbd
- usbh
- watchdog
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ supported:
- pwm
- spi
- usbd
- usbh
- watchdog
vendor: nordic
sysbuild: true
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ supported:
- pwm
- spi
- usbd
- usbh
- watchdog
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ supported:
- pwm
- spi
- usbd
- usbh
- watchdog
vendor: nordic
sysbuild: true
6 changes: 6 additions & 0 deletions drivers/usb/common/usb_dwc2_hw.h
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,13 @@ USB_DWC2_SET_FIELD_DEFINE(gnptxfsiz_nptxfstaddr, GNPTXFSIZ_NPTXFSTADDR)
#define USB_DWC2_GGPIO_STM32_PWRDWN BIT(USB_DWC2_GGPIO_STM32_PWRDWN_POS)

/* GSNPSID register */
#define USB_DWC2_GSNPSID_REV_2_92A 0x4F54292AUL
#define USB_DWC2_GSNPSID_REV_4_20A 0x4F54420AUL
#define USB_DWC2_GSNPSID_REV_5_00A 0x4F54500AUL
#define USB_DWC2_GSNPSID_REV_POS 0UL
#define USB_DWC2_GSNPSID_REV_MASK (0xFFFFUL << USB_DWC2_GSNPSID_REV_POS)

USB_DWC2_GET_FIELD_DEFINE(gsnpsid_rev, GSNPSID_REV)

/* GHWCFG1 register */
#define USB_DWC2_GHWCFG1 0x0044UL
Expand Down
2 changes: 2 additions & 0 deletions drivers/usb/uhc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
# SPDX-License-Identifier: Apache-2.0

zephyr_library()
zephyr_library_include_directories(${ZEPHYR_BASE}/drivers/usb/common/)

zephyr_library_sources(uhc_common.c)
zephyr_library_sources_ifdef(CONFIG_UHC_DWC2 uhc_dwc2.c)
zephyr_library_sources_ifdef(CONFIG_UHC_MAX3421E uhc_max3421e.c)
zephyr_library_sources_ifdef(CONFIG_UHC_VIRTUAL uhc_virtual.c)
zephyr_library_sources_ifdef(CONFIG_UHC_NXP_EHCI uhc_mcux_common.c uhc_mcux_ehci.c)
Expand Down
1 change: 1 addition & 0 deletions drivers/usb/uhc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ module = UHC_DRIVER
module-str = uhc drv
source "subsys/logging/Kconfig.template.log_config"

source "drivers/usb/uhc/Kconfig.dwc2"
source "drivers/usb/uhc/Kconfig.max3421e"
source "drivers/usb/uhc/Kconfig.virtual"
source "drivers/usb/uhc/Kconfig.mcux"
Expand Down
100 changes: 100 additions & 0 deletions drivers/usb/uhc/Kconfig.dwc2
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Copyright (c) 2026 Roman Leonov <jam_roma@yahoo.com>
# SPDX-License-Identifier: Apache-2.0

config UHC_DWC2
bool "DWC2 USB host controller driver"
depends on DT_HAS_SNPS_DWC2_ENABLED
default y
select EVENTS
select REGULATOR
help
DWC2 USB host controller driver.

if UHC_DWC2

config UHC_DWC2_MAX_CHANNELS
int "UHC DWC2 driver maximum supported number of channels"
default 16
range 1 16
help
Number of channels driver can support.
Reduce this value to save memory.
Increase to support more concurrent transfers.

config UHC_DRIVER_HIGH_SPEED_SUPPORT_ENABLED
bool "UHC DWC2 High speed"
default y if SOC_SERIES_NRF54LX
help
Enables HS support code if the SoC/board can support it.

config UHC_DWC2_STACK_SIZE
int "UHC DWC2 driver thread stack size"
default 512
help
DWC2 driver thread stack size.

config UHC_DWC2_THREAD_PRIORITY
int "UHC DWC2 driver thread priority"
default 8
help
DWC2 driver thread priority.

config UHC_DWC2_DEBOUNCE_DELAY_MS
int "Debounce delay in ms"
default 250
help
On connection of a USB device, the USB 2.0 specification requires
a "debounce interval with a minimum duration of 100ms" to allow the connection to stabilize
(see USB 2.0 chapter 7.1.7.3 for more details).
During the debounce interval, no new connection/disconnection events are registered.

The default value is set to 250 ms to be safe.

config UHC_DWC2_RESET_HOLD_MS
int "Reset hold in ms"
default 50
help
Root-port reset hold time in milliseconds.

USB 2.0 requires ordinary reset signaling to be asserted for at least
10 ms, but reset issued from a root port must last at least 50 ms..

The default value is set to 50 ms.

config UHC_DWC2_RESET_RECOVERY_MS
int "Reset recovery delay in ms"
default 30
help
Post-reset recovery delay in milliseconds.

USB 2.0 requires system software to allow at least 10 ms for reset
recovery after the port stops driving reset, before the attached
device is expected to respond to data transfers.

The attached device may ignore data transfers during this recovery
interval.

The default value is set to 30 ms.

config UHC_DWC2_SET_ADDR_DELAY_MS
int "Delay after set device address"
default 10
help
"After successful completion of the Status stage, the device is allowed a SetAddress()
recovery interval of 2 ms. At the end of this interval, the device must be able to accept
Setup packets addressed to the new address. Also, at the end of the recovery interval, the
device must not respond to tokens sent to the old address (unless, of course, the old and new
address is the same)." See USB 2.0 chapter 9.2.6.3 for more details.

The default value is set to 10 ms to be safe.

config UHC_DWC2_USBHS_VBUS_READY_TIMEOUT
int "USBHS VBUS ready event timeout in ms"
depends on SOC_SERIES_NRF54L
default 0
help
VBUS ready event timeout for the USBHS variant of DWC2 found on nRF MCUs.
If the VBUS is not ready and the Nordic USBHS controller is used, the udc_enable() is
blocked for this amount of time. Set it to zero to wait forever.

endif # UHC_DWC2
Loading
Loading