Skip to content

drivers: usb: uhc_dwc2: add initial support#102967

Open
roma-jam wants to merge 1 commit intozephyrproject-rtos:mainfrom
roma-jam-lab:pr-add-dwc2-uhc-channels-init
Open

drivers: usb: uhc_dwc2: add initial support#102967
roma-jam wants to merge 1 commit intozephyrproject-rtos:mainfrom
roma-jam-lab:pr-add-dwc2-uhc-channels-init

Conversation

@roma-jam
Copy link
Copy Markdown
Contributor

@roma-jam roma-jam commented Jan 27, 2026

Description

This is initial support of Synopsys DWC2 controller as a USB Host (esp32 vendor quirks included, so it might be tested on esp32s3).

These changes allow to init dwc2 as a host and enumerate attached USB device and utilize the Control Endpoint to get device information (for example, via shell example command: usbh device info) for different devices.

nRF54LM20 support

With vendor quirks #95723 it works with Full-speed devices as well, so the code might be tested on the nRF54LM20-DK board.

Limitations

  • Not handling any errors during the transfer. If the transfer has finished with an error, there will be LOG_ERR() output followed by LOG_WRN() which reveals where handling is absent.
  • Uses only one channel - channel number 0. Additional logic to claim vacant channel on uhc_dwc2_enqueue will be added as a follow-up.
  • Supports only Control transfer. Bulk, Interrupt and Isochronous transfers will be added as a follow-up.
  • High-speed is not working on nRF54. Will be fixed in the follow-up.
  • Supports only Buffer DMA mode (Slave or Scatter Gather also might be added, but esp32s3 and nRF54 both have DMA)
  • Does not synchronize cache (marked as TODO: in the code, where it should be done)
  • Does not support Hub connection (when device is a downstream device of the external hub)

And some other small limitations, that marked as TODOs in the code and can be solved in the future as a follow-up (with test coverage or without. "With" is better IMHO).

Testing with usbh shell on ESP32S3

  1. From the /samples/subsys/usb/shell folder, run
$ west build -b esp32s3_devkitc/esp32s3/procpu -- \
 -DCONFIG_SHELL=y \
 -DCONFIG_USB_HOST_STACK=y \
 -DCONFIG_USBH_SHELL=y \
 -DCONFIG_UDC_DWC2=n 

and get:

... 

Successfully created ESP32-S3 image.

then run:

$ west flash --esp-device /dev/ttyACM0 && west espressif monitor -p /dev/ttyACM0

and the the common usbh shell commands are available:

...

*** Booting Zephyr OS build 18c5216bfc70 ***
uart:~$ usbh init 
host: USB host initialized
uart:~$ usbh enable 
host: USB host enabled
[00:00:04.638,000] <inf> usbh_dev: New device with address 1 state 2
[00:00:04.640,000] <inf> usbh_dev: Configuration 1 bNumInterfaces 3
uart:~$ usbh device list 
1
uart:~$ usbh device info 1
Device Descriptor:
  bLength                        18
  bDescriptorType                 1
  bcdUSB                       2.00
  bDeviceClass                  239
  bDeviceSubClass                 2
  bDeviceProtocol                 1
  bMaxPacketSize0                64
  idVendor                   0x1E45
  idProduct                  0x8022
  bcdDevice                   58.01
  iManufacturer                   3
  iProduct                        1
  iSerial                         2
  bNumConfigurations              1
  Configuration Descriptor:
    bLength                         9
    bDescriptorType                 2
    wTotalLength               0x0144
    bNumInterfaces                  2
    bConfigurationValue             1
    iConfiguration                  4
    bmAttributes                 0x80
    bMaxPower                     500 mA
    Interface Association:
      bLength                         8
    ...

Related

@roma-jam roma-jam force-pushed the pr-add-dwc2-uhc-channels-init branch from 01ebd5f to f63106f Compare January 27, 2026 15:38
@josuah josuah linked an issue Jan 27, 2026 that may be closed by this pull request
@roma-jam roma-jam force-pushed the pr-add-dwc2-uhc-channels-init branch from f63106f to cbcf576 Compare January 28, 2026 08:38
@roma-jam roma-jam changed the title [WIP] drivers: usb: uhc: Added channels logic [part5] [WIP] drivers: usb: uhc: Added channels initial logic [part5] Jan 28, 2026
@roma-jam roma-jam force-pushed the pr-add-dwc2-uhc-channels-init branch 2 times, most recently from abe9038 to 3d06d02 Compare February 20, 2026 11:33
@roma-jam roma-jam force-pushed the pr-add-dwc2-uhc-channels-init branch 3 times, most recently from 1df627f to aae36b7 Compare March 2, 2026 13:04
@roma-jam roma-jam changed the title [WIP] drivers: usb: uhc: Added channels initial logic [part5] drivers: usb: uhc: Added channels initial logic [part5] Mar 2, 2026
@roma-jam roma-jam marked this pull request as ready for review March 2, 2026 13:22
@zephyrbot zephyrbot added area: USB Universal Serial Bus area: Samples Samples area: Devicetree Binding PR modifies or adds a Device Tree binding area: Xtensa Xtensa Architecture platform: ESP32 Espressif ESP32 labels Mar 2, 2026
Comment thread drivers/usb/uhc/uhc_dwc2.c Outdated
Comment thread drivers/usb/uhc/uhc_dwc2.c Outdated
Comment thread drivers/usb/uhc/uhc_dwc2.c Outdated
Comment thread drivers/usb/uhc/uhc_dwc2.c Outdated
Comment thread drivers/usb/uhc/uhc_dwc2.c Outdated
Comment thread drivers/usb/uhc/uhc_dwc2.c Outdated
Comment thread drivers/usb/uhc/uhc_dwc2.c Outdated
Comment thread drivers/usb/uhc/uhc_dwc2.c Outdated
@roma-jam roma-jam force-pushed the pr-add-dwc2-uhc-channels-init branch 2 times, most recently from fcef282 to 17805b7 Compare April 30, 2026 12:15
Comment thread drivers/usb/uhc/uhc_dwc2.c Outdated
Copy link
Copy Markdown
Contributor

@josuah josuah left a comment

Choose a reason for hiding this comment

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

Some review pass to detail a bit more the ability to remove local definitions already provided in drivers/usb/common/usb_dwc2_hw.h.

Comment thread drivers/usb/uhc/uhc_dwc2.c Outdated
Comment thread drivers/usb/uhc/uhc_dwc2.c Outdated
Comment thread drivers/usb/uhc/uhc_dwc2.c Outdated
Comment thread drivers/usb/uhc/uhc_dwc2.c Outdated
Comment thread drivers/usb/uhc/uhc_dwc2.c
Comment thread drivers/usb/uhc/uhc_dwc2.c Outdated
Comment thread drivers/usb/uhc/uhc_dwc2.c Outdated
@roma-jam roma-jam force-pushed the pr-add-dwc2-uhc-channels-init branch 4 times, most recently from 8727bd1 to 32a4575 Compare April 30, 2026 23:40
Comment thread drivers/usb/uhc/uhc_dwc2.c
@roma-jam roma-jam force-pushed the pr-add-dwc2-uhc-channels-init branch from 32a4575 to fbaa637 Compare May 1, 2026 13:04
Comment thread drivers/usb/uhc/uhc_dwc2.c
@roma-jam roma-jam force-pushed the pr-add-dwc2-uhc-channels-init branch 3 times, most recently from 4321f55 to 5c9e0be Compare May 1, 2026 13:49
Comment thread dts/bindings/usb/snps,dwc2.yaml
@josuah
Copy link
Copy Markdown
Contributor

josuah commented May 1, 2026

I think I do not have any other modification to propose than those already opened.

It works with nRF54LM20 on this branch, and I anticipate it would also work on other platforms.

The driver is clearly a lot more robust than anything I could be coming-up with myself, and fixed many bugs due to my lack of deep understanding of DWC2 beyond the manual.

Thank you once again for bearing in, and for all of your help and expertise on this driver!

I will pursue with ISO support on top of it and stay reactive, i.e. rebase the nRF54LM20 branch frequently to keep testing things still work as you go.

Note: Control transfers only

Add initial usb host driver for Synopsys DWC2 with vendor quirks.

Signed-off-by: Roman Leonov <jam_roma@yahoo.com>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 4, 2026


err = 0;
} else {
LOG_ERR("Thread channel%d unhanlded evetns: %08Xh", channel->index, events);
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.

Suggested change
LOG_ERR("Thread channel%d unhanlded evetns: %08Xh", channel->index, events);
LOG_ERR("Thread channel%d unhandled events: %08Xh", channel->index, events);

@roma-jam
Copy link
Copy Markdown
Contributor Author

roma-jam commented May 4, 2026

Hi everyone,

this PR is ready for the review and the incoming code might be tested with esp32s3 or nrf54lm20 (full-speed only for now).

For more details, please refer to the PR description.

uint32_t ghwcfg2 = sys_read32((mem_addr_t)&dwc2->ghwcfg2);

if (usb_dwc2_get_ghwcfg2_hsphytype(ghwcfg2) == 0) {
dwc2_hal_config_hcfg_fsls(dwc2);
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.

This is a PHY clock selection, so it won't change after configuration.
Might be moved to/inside the dwc2_hal_init_host()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Devicetree Binding PR modifies or adds a Device Tree binding area: Samples Samples area: USB Universal Serial Bus area: Xtensa Xtensa Architecture platform: ESP32 Espressif ESP32

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DWC2 USB Host controller (UHC)

7 participants