|
| 1 | +.. zephyr:code-sample:: usb-cdc-acm |
| 2 | + :name: USB CDC-ACM |
| 3 | + :relevant-api: usbd_api _usb_device_core_api uart_interface |
| 4 | + |
| 5 | + Use USB CDC-ACM driver to implement a serial port echo. |
| 6 | + |
| 7 | +Overview |
| 8 | +******** |
| 9 | + |
| 10 | +This sample app demonstrates use of a USB Communication Device Class (CDC) |
| 11 | +Abstract Control Model (ACM) driver provided by the Zephyr project. |
| 12 | +Received data from the serial port is echoed back to the same port |
| 13 | +provided by this driver. |
| 14 | +This sample can be found under :zephyr_file:`samples/subsys/usb/cdc_acm` in the |
| 15 | +Zephyr project tree. |
| 16 | + |
| 17 | +Requirements |
| 18 | +************ |
| 19 | + |
| 20 | +This project requires an USB device driver, which is available for multiple |
| 21 | +boards supported in Zephyr. |
| 22 | + |
| 23 | +Building and Running |
| 24 | +******************** |
| 25 | + |
| 26 | +Reel Board |
| 27 | +=========== |
| 28 | + |
| 29 | +To see the console output of the app, open a serial port emulator and |
| 30 | +attach it to the USB to TTL Serial cable. Build and flash the project: |
| 31 | + |
| 32 | +.. zephyr-app-commands:: |
| 33 | + :zephyr-app: samples/subsys/usb/cdc_acm |
| 34 | + :board: reel_board |
| 35 | + :goals: flash |
| 36 | + :compact: |
| 37 | + |
| 38 | +Running |
| 39 | +======= |
| 40 | + |
| 41 | +Plug the board into a host device, for example, a PC running Linux. |
| 42 | +The board will be detected as shown by the Linux dmesg command: |
| 43 | + |
| 44 | +.. code-block:: console |
| 45 | +
|
| 46 | + usb 9-1: new full-speed USB device number 112 using uhci_hcd |
| 47 | + usb 9-1: New USB device found, idVendor=8086, idProduct=f8a1 |
| 48 | + usb 9-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3 |
| 49 | + usb 9-1: Product: CDC-ACM |
| 50 | + usb 9-1: Manufacturer: Intel |
| 51 | + usb 9-1: SerialNumber: 00.01 |
| 52 | + cdc_acm 9-1:1.0: ttyACM1: USB ACM device |
| 53 | +
|
| 54 | +The app prints on serial output (UART1), used for the console: |
| 55 | + |
| 56 | +.. code-block:: console |
| 57 | +
|
| 58 | + Wait for DTR |
| 59 | +
|
| 60 | +Open a serial port emulator, for example minicom |
| 61 | +and attach it to detected CDC ACM device: |
| 62 | + |
| 63 | +.. code-block:: console |
| 64 | +
|
| 65 | + minicom --device /dev/ttyACM1 |
| 66 | +
|
| 67 | +The app should respond on serial output with: |
| 68 | + |
| 69 | +.. code-block:: console |
| 70 | +
|
| 71 | + DTR set, start test |
| 72 | + Baudrate detected: 115200 |
| 73 | +
|
| 74 | +And on ttyACM device, provided by zephyr USB device stack: |
| 75 | + |
| 76 | +.. code-block:: console |
| 77 | +
|
| 78 | + Send characters to the UART device |
| 79 | + Characters read: |
| 80 | +
|
| 81 | +The characters entered in serial port emulator will be echoed back. |
| 82 | + |
| 83 | +Troubleshooting |
| 84 | +=============== |
| 85 | + |
| 86 | +If the ModemManager runs on your operating system, it will try |
| 87 | +to access the CDC ACM device and maybe you can see several characters |
| 88 | +including "AT" on the terminal attached to the CDC ACM device. |
| 89 | +You can add or extend the udev rule for your board to inform |
| 90 | +ModemManager to skip the CDC ACM device. |
| 91 | +For this example, it would look like this: |
| 92 | + |
| 93 | +.. code-block:: none |
| 94 | +
|
| 95 | + ATTRS{idVendor}=="8086" ATTRS{idProduct}=="f8a1", ENV{ID_MM_DEVICE_IGNORE}="1" |
| 96 | +
|
| 97 | +You can use |
| 98 | +``/lib/udev/rules.d/77-mm-usb-device-blacklist.rules`` as reference. |
0 commit comments