diff --git a/samples/subsys/usb/shell/README.rst b/samples/subsys/usb/shell/README.rst index a9e2f20087d..09a57d25206 100644 --- a/samples/subsys/usb/shell/README.rst +++ b/samples/subsys/usb/shell/README.rst @@ -22,6 +22,28 @@ built like: :goals: flash :compact: +For the USB host functionality a supported host controller is required, +currently it is only MAX3421E. The example can be built as follows: + +.. zephyr-app-commands:: + :zephyr-app: samples/subsys/usb/shell + :board: nrf52840dk_nrf52840 + :shield: sparkfun_max3421e + :gen-args: -DCONFIG_UHC_DRIVER=y -DCONFIG_USB_HOST_STACK=y + :goals: flash + :compact: + +It is theoretically possible to build USB support using virtual USB controllers +for all platforms, eventually the devicetree overlay has to be adjusted slightly if +the platform has already defined or not `zephyr_uhc0` or `zephyr_udc0` nodelabels. + +.. zephyr-app-commands:: + :zephyr-app: samples/subsys/usb/shell + :board: nrf52840dk_nrf52840 + :gen-args: -DOVERLAY_CONFIG=virtual.conf -DDTC_OVERLAY_FILE=virtual.overlay + :goals: flash + :compact: + Sample shell interaction ======================== @@ -34,5 +56,30 @@ Sample shell interaction dev: added USB class foobaz to configuration 1 uart:~$ usbd init dev: USB initialized + uart:~$ usbh init + host: USB host initialized + uart:~$ usbh enable + host: USB host enabled + [611:00:28.620,000] usbd_core: VBUS detected event + uart:~$ usbh bus resume + host: USB bus resumed uart:~$ usbd enable + host: USB device connected dev: USB enabled + uart:~$ usbh device descriptor device 0 + host: transfer finished 0x20006250, err 0 + 00000000: 80 06 00 01 00 00 12 00 |........ | + bLength 18 + bDescriptorType 1 + bcdUSB 200 + bDeviceClass 239 + bDeviceSubClass 2 + bDeviceProtocol 1 + bMaxPacketSize0 64 + idVendor 2fe3 + idProduct ffff + bcdDevice 301 + iManufacturer 1 + iProduct 2 + iSerial 3 + bNumConfigurations 1 diff --git a/samples/subsys/usb/shell/boards/qemu_cortex_m3.conf b/samples/subsys/usb/shell/boards/qemu_cortex_m3.conf new file mode 100644 index 00000000000..58132f17be8 --- /dev/null +++ b/samples/subsys/usb/shell/boards/qemu_cortex_m3.conf @@ -0,0 +1,5 @@ +# Copyright (c) 2022 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_UHC_DRIVER=y +CONFIG_USB_HOST_STACK=y diff --git a/samples/subsys/usb/shell/boards/qemu_cortex_m3.overlay b/samples/subsys/usb/shell/boards/qemu_cortex_m3.overlay new file mode 100644 index 00000000000..5136e0a0b47 --- /dev/null +++ b/samples/subsys/usb/shell/boards/qemu_cortex_m3.overlay @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + zephyr_uhc0: uhc_vrt0 { + compatible = "zephyr,uhc-virtual"; + + zephyr_udc0: udc_vrt0 { + compatible = "zephyr,udc-virtual"; + num-bidir-endpoints = <8>; + maximum-speed = "high-speed"; + }; + + udc1: udc_vrt1 { + compatible = "zephyr,udc-virtual"; + num-bidir-endpoints = <8>; + maximum-speed = "full-speed"; + }; + }; +}; diff --git a/samples/subsys/usb/shell/device_and_host_prj.conf b/samples/subsys/usb/shell/device_and_host_prj.conf new file mode 100644 index 00000000000..04127e7de58 --- /dev/null +++ b/samples/subsys/usb/shell/device_and_host_prj.conf @@ -0,0 +1,12 @@ +CONFIG_SHELL=y +CONFIG_USB_DEVICE_STACK_NEXT=y +CONFIG_USBD_SHELL=y + +CONFIG_USB_HOST_STACK=y +CONFIG_USBH_SHELL=y + +CONFIG_LOG=y +CONFIG_USBD_LOG_LEVEL_WRN=y +CONFIG_USBH_LOG_LEVEL_WRN=y +CONFIG_UDC_DRIVER_LOG_LEVEL_WRN=y +CONFIG_UHC_DRIVER_LOG_LEVEL_WRN=y diff --git a/samples/subsys/usb/shell/sample.yaml b/samples/subsys/usb/shell/sample.yaml index 7a1ce2bbf8f..2c9efe63f6d 100644 --- a/samples/subsys/usb/shell/sample.yaml +++ b/samples/subsys/usb/shell/sample.yaml @@ -6,3 +6,18 @@ tests: depends_on: usb_device harness: keyboard tags: usb + sample.usbh.shell: + depends_on: usb_device + tags: usb shield + extra_args: CONF_FILE="device_and_host_prj.conf" + SHIELD="sparkfun_max3421e" + platform_allow: nrf52840dk_nrf52840 frdm_k64f + build_only: true + sample.usbh.shell.virtual: + depends_on: usb_device + tags: usb + extra_args: CONF_FILE="device_and_host_prj.conf" + OVERLAY_CONFIG="virtual.conf" + DTC_OVERLAY_FILE="virtual.overlay" + platform_allow: qemu_cortex_m3 + build_only: true diff --git a/samples/subsys/usb/shell/virtual.conf b/samples/subsys/usb/shell/virtual.conf new file mode 100644 index 00000000000..58132f17be8 --- /dev/null +++ b/samples/subsys/usb/shell/virtual.conf @@ -0,0 +1,5 @@ +# Copyright (c) 2022 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +CONFIG_UHC_DRIVER=y +CONFIG_USB_HOST_STACK=y diff --git a/samples/subsys/usb/shell/virtual.overlay b/samples/subsys/usb/shell/virtual.overlay new file mode 100644 index 00000000000..fe0be4060be --- /dev/null +++ b/samples/subsys/usb/shell/virtual.overlay @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2022 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/delete-node/ &zephyr_udc0; + +/ { + zephyr_uhc0: uhc_vrt0 { + compatible = "zephyr,uhc-virtual"; + + zephyr_udc0: udc_vrt0 { + compatible = "zephyr,udc-virtual"; + num-bidir-endpoints = <8>; + maximum-speed = "high-speed"; + }; + + udc1: udc_vrt1 { + compatible = "zephyr,udc-virtual"; + num-bidir-endpoints = <8>; + maximum-speed = "full-speed"; + }; + }; +};