README.rst
1.. zephyr:code-sample:: usb-shell
2 :name: USB shell
3 :relevant-api: usbd_api
4
5 Use shell commands to interact with USB device stack.
6
7Overview
8********
9
10The sample enables new experimental USB device support and the shell function.
11It is primarily intended to aid in the development and testing of USB controller
12drivers and new USB support.
13
14Building and flashing
15*********************
16
17Assuming the board has a supported USB device controller, the example can be
18built like:
19
20.. zephyr-app-commands::
21 :zephyr-app: samples/subsys/usb/shell
22 :board: reel_board
23 :goals: flash
24 :compact:
25
26For the USB host functionality a supported host controller is required,
27currently it is only MAX3421E. The example can be built as follows:
28
29.. zephyr-app-commands::
30 :zephyr-app: samples/subsys/usb/shell
31 :board: nrf52840dk/nrf52840
32 :shield: sparkfun_max3421e
33 :gen-args: -DCONFIG_UHC_DRIVER=y -DCONFIG_USB_HOST_STACK=y
34 :goals: flash
35 :compact:
36
37It is theoretically possible to build USB support using virtual USB controllers
38for all platforms, eventually the devicetree overlay has to be adjusted slightly if
39the platform has already defined or not ``zephyr_uhc0`` or ``zephyr_udc0`` nodelabels.
40
41.. zephyr-app-commands::
42 :zephyr-app: samples/subsys/usb/shell
43 :board: nrf52840dk/nrf52840
44 :gen-args: -DEXTRA_CONF_FILE=virtual.conf -DDTC_OVERLAY_FILE=virtual.overlay
45 :goals: flash
46 :compact:
47
48Sample shell interaction
49========================
50
51.. code-block:: console
52
53 uart:~$ usbd defaults
54 dev: USB descriptors initialized
55 uart:~$ usbd config add 1
56 uart:~$ usbd class add foobaz 1
57 dev: added USB class foobaz to configuration 1
58 uart:~$ usbd init
59 dev: USB initialized
60 uart:~$ usbh init
61 host: USB host initialized
62 uart:~$ usbh enable
63 host: USB host enabled
64 [611:00:28.620,000] <wrn> usbd_core: VBUS detected event
65 uart:~$ usbh bus resume
66 host: USB bus resumed
67 uart:~$ usbd enable
68 host: USB device connected
69 dev: USB enabled
70 uart:~$ usbh device descriptor device 0
71 host: transfer finished 0x20006250, err 0
72 00000000: 80 06 00 01 00 00 12 00 |........ |
73 bLength 18
74 bDescriptorType 1
75 bcdUSB 200
76 bDeviceClass 239
77 bDeviceSubClass 2
78 bDeviceProtocol 1
79 bMaxPacketSize0 64
80 idVendor 2fe3
81 idProduct ffff
82 bcdDevice 301
83 iManufacturer 1
84 iProduct 2
85 iSerial 3
86 bNumConfigurations 1
87