• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

boards/11-Mar-2024-32

src/11-Mar-2024-860706

CMakeLists.txtD11-Mar-2024224 96

KconfigD11-Mar-2024164 85

README.rstD11-Mar-20243.7 KiB10775

app.overlayD11-Mar-2024280 1815

prj.confD11-Mar-2024375 1813

sample.yamlD11-Mar-2024193 98

README.rst

1.. _usb_hid-cdc:
2
3USB HID CDC ACM Application
4###########################
5
6Overview
7********
8
9This sample app demonstrates use of multiple USB classes with multiple
10instances. It combines two HID instances and two CDC ACM instances.
11This sample can be found under :zephyr_file:`samples/subsys/usb/hid-cdc` in the
12Zephyr project tree.
13
14Requirements
15************
16
17This project requires an USB device driver and multiple endpoints.
18
19The board hardware must have a push button connected via a GPIO pin. These are
20called "User buttons" on many of Zephyr's :ref:`boards`.
21
22The button must be configured using the ``sw0`` :ref:`devicetree <dt-guide>`
23alias, usually in the :ref:`BOARD.dts file <devicetree-in-out-files>`. You will
24see this error if you try to build this sample for an unsupported board:
25
26.. code-block:: none
27
28   Unsupported board: sw0 devicetree alias is not defined
29
30You may see additional build errors if the ``sw0`` alias exists, but is not
31properly defined.
32
33If the devicetree aliases ``sw1``, ``sw2``, and ``sw3`` are defined, they will
34also be used as additional buttons as described below.
35
36Building and Running
37********************
38
39This sample can be built for multiple boards. To build and flash it
40for the :ref:`nrf52840dk_nrf52840` board:
41
42.. zephyr-app-commands::
43	:zephyr-app: samples/subsys/usb/hid-cdc
44	:board: nrf52840dk_nrf52840
45	:goals: build flash
46	:compact:
47
48After you have built and flashed the sample app image to your board, plug the
49board into a host device, for example, a PC running Linux.
50Two CDC ACM interfaces (for example /dev/ttyACM1 and /dev/ttyACM2)
51and two HID devices will be detected:
52
53.. code-block:: console
54
55	usb 2-2: new full-speed USB device number 3 using ohci-pci
56	usb 2-2: New USB device found, idVendor=2fe3, idProduct=0003, bcdDevice= 2.03
57	usb 2-2: New USB device strings: Mfr=1, Product=2, SerialNumber=3
58	usb 2-2: Product: Zephyr HID and CDC ACM sample
59	usb 2-2: Manufacturer: ZEPHYR
60	usb 2-2: SerialNumber: 86FE679A598AC47A
61	cdc_acm 2-2:1.0: ttyACM1: USB ACM device
62	input: ZEPHYR Zephyr HID and CDC ACM sample as /devices/pci0000:00/0000:00:06.0/usb2/2-2/2-2:1.2/0003:2FE3:0100.0002/input/input8
63	hid-generic 0003:2FE3:0100.0002: input,hidraw1: USB HID v1.10 Mouse [ZEPHYR Zephyr HID and CDC ACM sample] on usb-0000:00:06.0-2/input2
64	cdc_acm 2-2:1.3: ttyACM2: USB ACM device
65	input: ZEPHYR Zephyr HID and CDC ACM sample as /devices/pci0000:00/0000:00:06.0/usb2/2-2/2-2:1.5/0003:2FE3:0100.0003/input/input9
66	hid-generic 0003:2FE3:0100.0003: input,hidraw2: USB HID v1.10 Keyboard [ZEPHYR Zephyr HID and CDC ACM sample] on usb-0000:00:06.0-2/input5
67
68You can now connect to both CDC ACM ports:
69
70.. code-block:: console
71
72	minicom -D /dev/ttyACM1 -b 115200
73
74.. code-block:: console
75
76	minicom -D /dev/ttyACM2 -b 115200
77
78After both ports have been connected to, messages explaining usage of each port will be displayed:
79
80.. code-block:: console
81
82	Welcome to CDC_ACM_0
83	Supported commands:
84	up    - moves the mouse up
85	down  - moves the mouse down
86	right - moves the mouse to right
87	left  - moves the mouse to left
88
89.. code-block:: console
90
91	Welcome to CDC_ACM_1
92	Enter a string and terminate it with ENTER.
93	It will be sent via HID when BUTTON 2 is pressed.
94	You can modify it by sending a new one here.
95
96CDC ACM 0 may be used to control the mouse by typing a command and pressing :kbd:`ENTER`.
97
98CDC ACM 1 is used to control the keyboard - any string typed into it and finished with :kbd:`ENTER` will be saved
99on the device and typed back to the host when BUTTON 2 is pressed.
100
101Buttons have following functions:
102
103- Button 0 moves HID mouse in random direction
104- Button 1 is a left HID mouse button
105- Button 2 types the string sent with CDC ACM 1 using HID keyboard
106- Button 3 is a CAPS LOCK on HID keyboard
107