Skip to content

samples: subsys: usb: shell: allow host-only operation#105005

Merged
kartben merged 1 commit intozephyrproject-rtos:mainfrom
josuah:usb_shell_suffix
Apr 28, 2026
Merged

samples: subsys: usb: shell: allow host-only operation#105005
kartben merged 1 commit intozephyrproject-rtos:mainfrom
josuah:usb_shell_suffix

Conversation

@josuah
Copy link
Copy Markdown
Contributor

@josuah josuah commented Mar 6, 2026

Update build instructions to allow host-only operation.

Doc build https://builds.zephyrproject.io/zephyr/pr/105005/docs/samples/subsys/usb/shell/README.html#usb-shell

Testing device (hardware):

west build -b nrf52840dk/nrf52840 samples/subsys/usb/shell

[23165.768788] usb 3-1.1.4.4: new full-speed USB device number 14 using xhci_hcd
[23165.859755] usb 3-1.1.4.4: New USB device found, idVendor=2fe3, idProduct=ffff, bcdDevice= 4.03
[23165.859772] usb 3-1.1.4.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[23165.859779] usb 3-1.1.4.4: Product: Zephyr USBD foobaz
[23165.859783] usb 3-1.1.4.4: Manufacturer: ZEPHYR
[23165.859787] usb 3-1.1.4.4: SerialNumber: C1996FC49FA36360

Testing host + virtual (native_sim):

west build -b native_sim/native/64 samples/subsys/usb/shell \
  -DCONF_FILE=prj_host.conf \
  -DEXTRA_DTC_OVERLAY_FILE=virtual.overlay \
  -DCONFIG_SERIAL=y

uart:~$ usbh init  
uart:~$ usbh enable
uart:~$ usbh device list
<no device listed, as expected>

Testing device + host + virtual (native_sim):

west build -b native_sim/native/64 samples/subsys/usb/shell \
  -DEXTRA_CONF_FILE=prj_host.conf \
  -DEXTRA_DTC_OVERLAY_FILE=virtual.overlay \
  -DCONFIG_SERIAL=y
 
uart:~$ usbh init
uart:~$ usbh enable
uart:~$ usbd config add FS1
uart:~$ usbd config add HS1
uart:~$ usbd class register loopback_0 fs 1
uart:~$ usbd class register loopback_0 hs 1
uart:~$ usbd init
uart:~$ usbd enable
uart:~$ usbh device list
uart:~$ usbh device descriptor configuration 1 0

@zephyrbot zephyrbot added area: Samples Samples area: USB Universal Serial Bus labels Mar 6, 2026
@josuah josuah force-pushed the usb_shell_suffix branch 4 times, most recently from c341247 to e708d95 Compare March 6, 2026 22:16
@josuah
Copy link
Copy Markdown
Contributor Author

josuah commented Mar 6, 2026

Force-push:

  • also adjust dependencies and tags

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Mar 6, 2026

tmon-nordic
tmon-nordic previously approved these changes Mar 16, 2026
@github-actions
Copy link
Copy Markdown

This pull request has been marked as stale because it has been open (more than) 30 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 7 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions Bot added the Stale label Apr 16, 2026
@github-actions github-actions Bot closed this Apr 23, 2026
@josuah josuah reopened this Apr 25, 2026
@josuah josuah removed the Stale label Apr 25, 2026
@josuah josuah force-pushed the usb_shell_suffix branch from e708d95 to 6411aa8 Compare April 25, 2026 14:00
@josuah
Copy link
Copy Markdown
Contributor Author

josuah commented Apr 25, 2026

Force-push:

  • Rebase on latest main

Comment thread samples/subsys/usb/shell/README.rst Outdated

For the USB host functionality a supported host controller is required,
currently it is only MAX3421E. The example can be built as follows:
Assuming the board has a supported USB device controller, the example can be
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Assuming the board has a supported USB device controller, the example can be
Assuming the board has a supported USB host controller, the example can be

host not device

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.

Good catch.

.. zephyr-app-commands::
:zephyr-app: samples/subsys/usb/shell
:board: nrf52840dk/nrf52840
:shield: sparkfun_max3421e
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

if we assume that the board ahs a host controller, then the shield should not be needed

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.

Very true, the description does say "assuming the board has a supported USB host controller", picking FRDM-RW612 in the meantime that nRF54LM20's DWC2 is ready.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

still in it

platform_allow:
- nrf52840dk/nrf52840
- frdm_k64f
build_only: true
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

if we take the changes of #105083 for adding the usbh tag

nrf52840dk/nrf52840 and frdm_k64f both don't not have that tag, so it wouldn't be tested

Might be an idea to have two cases of this, one that depends of the usbh tag but without the shield and one for the shield variant but then without the usbh tag, as the original boards don't have a host controller

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.

Good point, there is no tag for shields.

Comment thread samples/subsys/usb/shell/sample.yaml Outdated
- shield
extra_args:
- CONF_FILE="device_and_host_prj.conf"
- CONF_FILE="prj_host.conf"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

if we use the CONF_FILE argument the board specific files in boards are ignored. see https://docs.zephyrproject.org/latest/build/kconfig/setting.html#the-initial-configuration But for qemu boards i need to set

CONFIG_QEMU_EXTRA_FLAGS="-device usb-ccid"

for example (see https://qemu-project.gitlab.io/qemu/system/devices/usb.html) to add usb devices to the bus

Copy link
Copy Markdown
Contributor Author

@josuah josuah Apr 27, 2026

Choose a reason for hiding this comment

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

To avoid skipping board-specific conf, there need to be no -DCONF_FILE, we can only rely on -DEXTRA_CONF_FILE= and -DFILE_SUFFIX=.

I suspect enabling the USB Host/Device controllers might happen in a board-specific way, so this narrows it down to FILE_SUFFIX= to have have per-board host/device variants too.

I will try with this thank you.

@josuah
Copy link
Copy Markdown
Contributor Author

josuah commented Apr 27, 2026

@maass-hamburg does it solve your use-case now?

It should be possible to have a boards/qemu_cortex_m3_host.conf with CONFIG_QEMU_EXTRA_FLAGS="-device usb-ccid" inside.

Comment thread samples/subsys/usb/shell/README.rst Outdated

.. zephyr-app-commands::
:zephyr-app: samples/subsys/usb/shell
:board: frdm_k11f
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.

What board is frdm_k11f?

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 plain typo! In reaction to #105005 (comment) I tried to pick a board with zephyr_uhc0 enabled, and found frdm_k22f.

What board should I target for the host-only operation?

Comment thread samples/subsys/usb/shell/README.rst Outdated
Comment on lines +37 to +38
Assuming the board has **both** a supported USB device and host controller
(i.e. using an USB host shield), the example can be built like:
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.

Suggested change
Assuming the board has **both** a supported USB device and host controller
(i.e. using an USB host shield), the example can be built like:
Assuming the board has a supported USB device and host controller,
the example can be built like:

Also, I want to keep device_and_host, perhaps renamed to prj_device_and_host.conf. The meaning of both is unclear. I also prefer to explicitly describe how prj_*.conf is supposed to be used because things like -DFILE_SUFFIX=both are less accessible.

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.

done

I confirm native_sim works:

$ west twister -s sample.usbh.shell.virtual
...
$ twister-out/native_sim_native_64/host_gnu/samples/subsys/usb/shell/sample.usbh.shell.virtual/zephyr/zephyr.exe
uart connected to pseudotty: /dev/pts/3
*** Booting Zephyr OS build v4.4.0-1127-ga63b0b2b2587 ***

Then connecting to /dev/pts/3 permits communication with the USB host and device shell to

@@ -1,12 +1,13 @@
CONFIG_SHELL=y
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.

What is the point to reorder all the lines? I do not see a good reason and it just makes it harder to review.

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.

I wanted to merge the host and device side back together after splitting them, but now I realize this is already there upstream, so I should use this instead.

Comment thread samples/subsys/usb/shell/sample.yaml Outdated
depends_on:
- usbd
tags:
- usbd
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.

The tag is usb and should not be changed. Should not be mixed with the supported feature usbd this sample depends on. Same applies to usbh.

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.

Thank you for the distinction between features and tags.

extra_args:
- FILE_SUFFIX=host
platform_allow:
- rd_rw612_bga
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.

Could you verify that this board is working?

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.

No as unfortunately not available to the public.

This was used for UVC Host by @AidenHu.

Glad to know which board to use in the meantime this gets ready. Maybe still using the nRF52840 with the shield for now?

(In the meantime, I am hurrying on DWC2 Host...)

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.

Let's keep rd_rw612_bga, we can replace it with integration_platforms later.

Comment thread samples/subsys/usb/shell/sample.yaml Outdated
Comment on lines +28 to +51
tags: usb
extra_args: CONF_FILE="device_and_host_prj.conf"
depends_on:
- usbh
- usbd
tags:
- usbh
- usbd
extra_args:
- FILE_SUFFIX=both
- EXTRA_DTC_OVERLAY_FILE="virtual.conf"
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.

I wanted to replace qemu_contex_m3 with native_sim for a long time. As you are changing it, please replace platform_allow: qemu_cortex_m3 with platform_allow: native_sim. Note, EXTRA_DTC_OVERLAY_FILE should be EXTRA_DTC_OVERLAY_FILE="virtual.overlay". Remove boards/qemu_cortex_m3.* overlays.

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.

I will double-check what the CI is doing, maybe it ignored this so did not raise an error. Sorry for this typo.

In order to allow host-only operation, replace the configuration files
by prj_{host,device,device_and_host}.conf selected by the extra command
line flag -DFILE_SUFFIX={host,device,device_and_host}.
The virtual USB bus is still usable by adding this to any configuration
-DEXTRA_DTC_OVERLAY_FILE=virtual.overlay

Signed-off-by: Josuah Demangeon <josuah.demangeon@nordicsemi.no>
@josuah josuah force-pushed the usb_shell_suffix branch from 310c63c to 59fce8d Compare April 28, 2026 00:30
@sonarqubecloud
Copy link
Copy Markdown

@kartben kartben merged commit ae4cf3b into zephyrproject-rtos:main Apr 28, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Samples Samples area: USB Universal Serial Bus

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants