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
1 change: 1 addition & 0 deletions drivers/usb/udc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ zephyr_library_sources(udc_common.c)
zephyr_library_include_directories(${ZEPHYR_BASE}/drivers/usb/common/)

zephyr_library_sources_ifdef(CONFIG_UDC_DWC2 udc_dwc2.c)
zephyr_library_sources_ifdef(CONFIG_UDC_DWC3 udc_dwc3.c)
zephyr_library_sources_ifdef(CONFIG_UDC_NRF udc_nrf.c)
zephyr_library_sources_ifdef(CONFIG_UDC_KINETIS udc_kinetis.c)
zephyr_library_sources_ifdef(CONFIG_UDC_SKELETON udc_skeleton.c)
Expand Down
1 change: 1 addition & 0 deletions drivers/usb/udc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ module-str = usb drv
source "subsys/logging/Kconfig.template.log_config"

source "drivers/usb/udc/Kconfig.dwc2"
source "drivers/usb/udc/Kconfig.dwc3"
source "drivers/usb/udc/Kconfig.nrf"
source "drivers/usb/udc/Kconfig.kinetis"
source "drivers/usb/udc/Kconfig.skeleton"
Expand Down
33 changes: 33 additions & 0 deletions drivers/usb/udc/Kconfig.dwc3
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# SPDX-FileCopyrightText: Copyright tinyVision.ai Inc.
# SPDX-License-Identifier: Apache-2.0

config UDC_DWC3
bool "Synopsys USB device controller driver"
default y
select NOCACHE_MEMORY if ARCH_HAS_NOCACHE_MEMORY_SUPPORT
Copy link
Copy Markdown

@piterzhang piterzhang Mar 12, 2026

Choose a reason for hiding this comment

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

Suggested change
select NOCACHE_MEMORY if ARCH_HAS_NOCACHE_MEMORY_SUPPORT
select NOCACHE_MEMORY if ARCH_HAS_NOCACHE_MEMORY_SUPPORT
select UDC_DRIVER_HAS_HIGH_SPEED_SUPPORT

UDC_DRIVER_HAS_HIGH_SPEED_SUPPORT ;USB APP use it

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

imo, this should be set by the application itself. either this or superspeed

Copy link
Copy Markdown

@piterzhang piterzhang Mar 12, 2026

Choose a reason for hiding this comment

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

@natto1784
My understanding is that if the controller layer does not support high speed, the application layer cannot enable this macro. I tried enabling it in the webusb application but couldn't find a way to do so. Without configuring this option, the webusb application only compiles the Full Speed (FS) configuration into the ELF, but dwc3 runs in High Speed (HS), causing a mismatch error. Later, I saw this option used in Kconfig.dwc2, and after attempting to add it to dwc3's Kconfig, it passed.

The macro used by the application layer is USBD_SUPPORTS_HIGH_SPEED, and it is used as follows in include/zephyr/usb/usbd.h:

#define USBD_DEFINE_CLASS(class_name, class_api, class_priv, class_v_reqs)	\
	static struct usbd_class_data class_name = {				\
		.name = STRINGIFY(class_name),					\
		.api = class_api,						\
		.v_reqs = class_v_reqs,						\
		.priv = class_priv,						\
	};									\
	static STRUCT_SECTION_ITERABLE_ALTERNATE(				\
		usbd_class_fs, usbd_class_node, class_name##_fs) = {		\
		.c_data = &class_name,						\
	};									\
	IF_ENABLED(USBD_SUPPORTS_HIGH_SPEED, (					\
	static STRUCT_SECTION_ITERABLE_ALTERNATE(				\
		usbd_class_hs, usbd_class_node, class_name##_hs) = {		\
		.c_data = &class_name,						\
	};									\
	))									\
	IF_ENABLED(USBD_SUPPORTS_SUPER_SPEED, (					\
	static STRUCT_SECTION_ITERABLE_ALTERNATE(				\
		usbd_class_ss, usbd_class_node, class_name##_ss) = {		\
		.c_data = &class_name,						\
	};									\
	))

Additionally: If it's convenient for you, you can configure your board to HS, compile the webusb application, and try it. This should reproduce my error.

Copy link
Copy Markdown
Contributor Author

@josuah josuah Mar 12, 2026

Choose a reason for hiding this comment

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

Good catch about UDC_DRIVER_HAS_HIGH_SPEED_SUPPORT. Adding it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

should be set by the application itself

Maybe CONFIG_UDC_DRIVER_HIGH_SPEED_SUPPORT_ENABLED?

select UDC_BUF_FORCE_NOCACHE
depends on DT_HAS_SNPS_DWC3_ENABLED
help
Synopsys DWC3 USB device controller driver.

if UDC_DWC3

config UDC_DWC3_EVENTS_NUM
int "Number of events in the event ring buffer"
default 16
help
It is typically not needed to increase the number of events, but
if it were to happen due to some rare condition, increasing this
number could be useful.

config UDC_DWC3_TRB_NUM
int "Number of buffers for each non-control endpoint"
default 4
range 3 32
help
This is a general knob for the number of buffers present for each
endpoint. This does not affect control endpoints. The default is
enough for most conditions, but for performance and debug purposes,
increasing could reveal useful.

endif # UDC_DWC3
2,048 changes: 2,048 additions & 0 deletions drivers/usb/udc/udc_dwc3.c

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions drivers/usb/udc/udc_dwc3_qemu.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* SPDX-FileCopyrightText: Copyright The Zephyr Project Contributors
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef ZEPHYR_DRIVERS_USB_UDC_DWC3_QEMU_H
#define ZEPHYR_DRIVERS_USB_UDC_DWC3_QEMU_H

struct udc_dwc3_qemu_data {
uint32_t custom_content;
};

struct udc_dwc3_qemu_config {
uint32_t custom_content;
};

int udc_dwc3_qemu_init(const struct device *const dev)
{
const struct udc_dwc3_config *const config = dev->config;
struct udc_dwc3_qemu_data *const quirk_data = config->quirk_data;
const struct udc_dwc3_qemu_config *const quirk_config = config->quirk_config;

LOG_DBG("Example of quirk for init(): data=0x%x config=0x%x",
quirk_data->custom_content, quirk_config->custom_content);

return 0;
}

const struct udc_dwc3_vendor_quirks udc_dwc3_vendor_quirks = {
.init = udc_dwc3_qemu_init,
};

#define UDC_DWC3_QUIRK_DEFINE(n) \
static struct udc_dwc3_qemu_config udc_dwc3_quirk_config_##n = { \
.custom_content = 0x1234 \
}; \
static struct udc_dwc3_qemu_data udc_dwc3_quirk_data_##n = { \
.custom_content = 0x1234 \
};

#endif /* ZEPHYR_DRIVERS_USB_UDC_DWC3_VENDOR_QUIRKS_H */
22 changes: 22 additions & 0 deletions dts/bindings/usb/snps,dwc3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# SPDX-FileCopyrightText: Copyright tinyVision.ai Inc.
# SPDX-License-Identifier: Apache-2.0

description: |
Synopsys DWC3 Controller in device mode

compatible: "snps,dwc3"

include: usb-ep.yaml

properties:
reg:
required: true

interrupts:
required: true

num-in-endpoints:
required: true

num-out-endpoints:
required: true
20 changes: 20 additions & 0 deletions tests/drivers/build_all/usb/boards/qemu_cortex_a53.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* SPDX-FileCopyrightText: Copyright The Zephyr Project Contributors
* SPDX-License-Identifier: Apache-2.0
*/

/* This is only a placeholder, will be removed once this PR matured */

/ {
zephyr_udc0: usb@b0000000 {
compatible = "snps,dwc3";
reg = <0x0 0xb0000000 0x0 0x1000000>;
reg-names = "base";
maximum-speed = "high-speed";
interrupt-parent = <&gic>;
interrupts = <GIC_SPI 42 IRQ_TYPE_LEVEL IRQ_DEFAULT_PRIORITY>;
num-bidir-endpoints = <16>;
num-in-endpoints = <8>;
num-out-endpoints = <8>;
};
};
1 change: 1 addition & 0 deletions tests/drivers/build_all/usb/prj.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
CONFIG_TEST=y
CONFIG_TEST_USERSPACE=y
CONFIG_USB_BC12=y
CONFIG_UDC_DRIVER=y
CONFIG_UHC_DRIVER=y
CONFIG_GPIO=y
CONFIG_USBC_TCPC_DRIVER=y
Loading