samples: usb: remove cdc_acm_composite sample
Clean up before deprecating legacy device support. Remove cdc_acm_composite sample, which is not much different than cdc_acm, but uses two virtual UART interfaces. Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
This commit is contained in:
parent
b50646b338
commit
cd9dff7d8c
7 changed files with 1 additions and 294 deletions
|
@ -577,7 +577,7 @@ The following Product IDs are currently used:
|
||||||
+====================================================+========+
|
+====================================================+========+
|
||||||
| :zephyr:code-sample:`usb-cdc-acm` | 0x0001 |
|
| :zephyr:code-sample:`usb-cdc-acm` | 0x0001 |
|
||||||
+----------------------------------------------------+--------+
|
+----------------------------------------------------+--------+
|
||||||
| :zephyr:code-sample:`usb-cdc-acm-composite` | 0x0002 |
|
| Reserved (previously: usb-cdc-acm-composite) | 0x0002 |
|
||||||
+----------------------------------------------------+--------+
|
+----------------------------------------------------+--------+
|
||||||
| Reserved (previously: usb-hid-cdc) | 0x0003 |
|
| Reserved (previously: usb-hid-cdc) | 0x0003 |
|
||||||
+----------------------------------------------------+--------+
|
+----------------------------------------------------+--------+
|
||||||
|
|
|
@ -1,8 +0,0 @@
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 3.20.0)
|
|
||||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
|
||||||
project(cdc_acm)
|
|
||||||
|
|
||||||
FILE(GLOB app_sources src/*.c)
|
|
||||||
target_sources(app PRIVATE ${app_sources})
|
|
|
@ -1,64 +0,0 @@
|
||||||
.. zephyr:code-sample:: usb-cdc-acm-composite
|
|
||||||
:name: USB CDC-ACM composite
|
|
||||||
:relevant-api: _usb_device_core_api
|
|
||||||
|
|
||||||
Implement a composite USB device exposing two serial ports using USB CDC-ACM driver.
|
|
||||||
|
|
||||||
Overview
|
|
||||||
********
|
|
||||||
|
|
||||||
This sample app demonstrates use of a USB Communication Device Class (CDC)
|
|
||||||
Abstract Control Model (ACM) driver provided by the Zephyr project in
|
|
||||||
Composite configuration.
|
|
||||||
|
|
||||||
Two serial ports are created when the device is plugged to the PC.
|
|
||||||
Received data from one serial port is sent to another serial port
|
|
||||||
provided by this driver.
|
|
||||||
|
|
||||||
Running
|
|
||||||
*******
|
|
||||||
|
|
||||||
Plug the board into a host device, for example, a PC running Linux.
|
|
||||||
The board will be detected as shown by the Linux dmesg command:
|
|
||||||
|
|
||||||
.. code-block:: console
|
|
||||||
|
|
||||||
usb 1-1.5.4: new full-speed USB device number 28 using ehci-pci
|
|
||||||
usb 1-1.5.4: New USB device found, idVendor=2fe3, idProduct=0002, bcdDevice= 2.03
|
|
||||||
usb 1-1.5.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
|
|
||||||
usb 1-1.5.4: Product: Zephyr CDC ACM Composite sample
|
|
||||||
usb 1-1.5.4: Manufacturer: ZEPHYR
|
|
||||||
usb 1-1.5.4: SerialNumber: 86FE679A598AC47A
|
|
||||||
cdc_acm 1-1.5.4:1.0: ttyACM1: USB ACM device
|
|
||||||
cdc_acm 1-1.5.4:1.2: ttyACM2: USB ACM device
|
|
||||||
|
|
||||||
The app prints on serial output, used for the console:
|
|
||||||
|
|
||||||
.. code-block:: console
|
|
||||||
|
|
||||||
Wait for DTR
|
|
||||||
|
|
||||||
Open a serial port emulator, for example, minicom,
|
|
||||||
and attach it to both detected CDC ACM devices:
|
|
||||||
|
|
||||||
.. code-block:: console
|
|
||||||
|
|
||||||
minicom --device /dev/ttyACM1
|
|
||||||
minicom --device /dev/ttyACM2
|
|
||||||
|
|
||||||
The app should respond on serial output with:
|
|
||||||
|
|
||||||
.. code-block:: console
|
|
||||||
|
|
||||||
DTR set, start test
|
|
||||||
Baudrate detected: 115200
|
|
||||||
Baudrate detected: 115200
|
|
||||||
|
|
||||||
And on ttyACM devices provided by the Zephyr USB device stack:
|
|
||||||
|
|
||||||
.. code-block:: console
|
|
||||||
|
|
||||||
Send characters to another UART device
|
|
||||||
|
|
||||||
The characters entered in one serial port will be sent to another
|
|
||||||
serial port.
|
|
|
@ -1,15 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2021 Nordic Semiconductor ASA
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
&zephyr_udc0 {
|
|
||||||
cdc_acm_uart0 {
|
|
||||||
compatible = "zephyr,cdc-acm-uart";
|
|
||||||
};
|
|
||||||
|
|
||||||
cdc_acm_uart1 {
|
|
||||||
compatible = "zephyr,cdc-acm-uart";
|
|
||||||
};
|
|
||||||
};
|
|
|
@ -1,14 +0,0 @@
|
||||||
CONFIG_STDOUT_CONSOLE=y
|
|
||||||
CONFIG_LOG=y
|
|
||||||
CONFIG_SERIAL=y
|
|
||||||
CONFIG_UART_INTERRUPT_DRIVEN=y
|
|
||||||
CONFIG_UART_LINE_CTRL=y
|
|
||||||
|
|
||||||
CONFIG_USB_DEVICE_STACK=y
|
|
||||||
CONFIG_USB_DEVICE_PRODUCT="Zephyr CDC ACM Composite sample"
|
|
||||||
CONFIG_USB_DEVICE_PID=0x0002
|
|
||||||
CONFIG_USB_CDC_ACM_RINGBUF_SIZE=512
|
|
||||||
CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT=n
|
|
||||||
|
|
||||||
CONFIG_USB_DEVICE_LOG_LEVEL_ERR=y
|
|
||||||
CONFIG_USB_DRIVER_LOG_LEVEL_ERR=y
|
|
|
@ -1,17 +0,0 @@
|
||||||
sample:
|
|
||||||
description: Application with two CDC ACM instances requires at least
|
|
||||||
two OUT and four IN endpoints on the USB device controller.
|
|
||||||
name: CDC ACM Composite USB
|
|
||||||
tests:
|
|
||||||
sample.usb.cdc-acm-composite:
|
|
||||||
depends_on: usb_device
|
|
||||||
tags: usb
|
|
||||||
platform_exclude:
|
|
||||||
- nucleo_f429zi
|
|
||||||
- nucleo_f207zg
|
|
||||||
arch_exclude: posix
|
|
||||||
harness: console
|
|
||||||
harness_config:
|
|
||||||
type: one_line
|
|
||||||
regex:
|
|
||||||
- "Wait for DTR"
|
|
|
@ -1,175 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2016 Intel Corporation
|
|
||||||
*
|
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @file
|
|
||||||
* @brief Sample app for CDC ACM class driver
|
|
||||||
*
|
|
||||||
* Sample app for USB CDC ACM class driver. The received data is echoed back
|
|
||||||
* to the serial port.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <zephyr/device.h>
|
|
||||||
#include <zephyr/drivers/uart.h>
|
|
||||||
#include <zephyr/kernel.h>
|
|
||||||
#include <zephyr/sys/ring_buffer.h>
|
|
||||||
|
|
||||||
#include <zephyr/usb/usb_device.h>
|
|
||||||
#include <zephyr/logging/log.h>
|
|
||||||
LOG_MODULE_REGISTER(cdc_acm_composite, LOG_LEVEL_INF);
|
|
||||||
|
|
||||||
#define RING_BUF_SIZE (64 * 2)
|
|
||||||
|
|
||||||
uint8_t buffer0[RING_BUF_SIZE];
|
|
||||||
uint8_t buffer1[RING_BUF_SIZE];
|
|
||||||
|
|
||||||
struct serial_peer {
|
|
||||||
const struct device *dev;
|
|
||||||
struct serial_peer *data;
|
|
||||||
struct ring_buf rb;
|
|
||||||
};
|
|
||||||
|
|
||||||
#define DEFINE_SERIAL_PEER(node_id) { .dev = DEVICE_DT_GET(node_id), },
|
|
||||||
static struct serial_peer peers[] = {
|
|
||||||
DT_FOREACH_STATUS_OKAY(zephyr_cdc_acm_uart, DEFINE_SERIAL_PEER)
|
|
||||||
};
|
|
||||||
|
|
||||||
BUILD_ASSERT(ARRAY_SIZE(peers) >= 2, "Not enough CDC ACM instances");
|
|
||||||
|
|
||||||
static void interrupt_handler(const struct device *dev, void *user_data)
|
|
||||||
{
|
|
||||||
struct serial_peer *peer = user_data;
|
|
||||||
|
|
||||||
while (uart_irq_update(dev) && uart_irq_is_pending(dev)) {
|
|
||||||
LOG_DBG("dev %p peer %p", dev, peer);
|
|
||||||
|
|
||||||
if (uart_irq_rx_ready(dev)) {
|
|
||||||
uint8_t buf[64];
|
|
||||||
int read;
|
|
||||||
size_t wrote;
|
|
||||||
struct ring_buf *rb = &peer->data->rb;
|
|
||||||
|
|
||||||
read = uart_fifo_read(dev, buf, sizeof(buf));
|
|
||||||
if (read < 0) {
|
|
||||||
LOG_ERR("Failed to read UART FIFO");
|
|
||||||
read = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
wrote = ring_buf_put(rb, buf, read);
|
|
||||||
if (wrote < read) {
|
|
||||||
LOG_ERR("Drop %zu bytes", read - wrote);
|
|
||||||
}
|
|
||||||
|
|
||||||
LOG_DBG("dev %p -> dev %p send %zu bytes",
|
|
||||||
dev, peer->dev, wrote);
|
|
||||||
if (wrote) {
|
|
||||||
uart_irq_tx_enable(peer->dev);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (uart_irq_tx_ready(dev)) {
|
|
||||||
uint8_t buf[64];
|
|
||||||
size_t wrote, len;
|
|
||||||
|
|
||||||
len = ring_buf_get(&peer->rb, buf, sizeof(buf));
|
|
||||||
if (!len) {
|
|
||||||
LOG_DBG("dev %p TX buffer empty", dev);
|
|
||||||
uart_irq_tx_disable(dev);
|
|
||||||
} else {
|
|
||||||
wrote = uart_fifo_fill(dev, buf, len);
|
|
||||||
LOG_DBG("dev %p wrote len %zu", dev, wrote);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void uart_line_set(const struct device *dev)
|
|
||||||
{
|
|
||||||
uint32_t baudrate;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
/* They are optional, we use them to test the interrupt endpoint */
|
|
||||||
ret = uart_line_ctrl_set(dev, UART_LINE_CTRL_DCD, 1);
|
|
||||||
if (ret) {
|
|
||||||
LOG_DBG("Failed to set DCD, ret code %d", ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = uart_line_ctrl_set(dev, UART_LINE_CTRL_DSR, 1);
|
|
||||||
if (ret) {
|
|
||||||
LOG_DBG("Failed to set DSR, ret code %d", ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Wait 1 sec for the host to do all settings */
|
|
||||||
k_busy_wait(1000000);
|
|
||||||
|
|
||||||
ret = uart_line_ctrl_get(dev, UART_LINE_CTRL_BAUD_RATE, &baudrate);
|
|
||||||
if (ret) {
|
|
||||||
LOG_DBG("Failed to get baudrate, ret code %d", ret);
|
|
||||||
} else {
|
|
||||||
LOG_DBG("Baudrate detected: %d", baudrate);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
uint32_t dtr = 0U;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
for (int idx = 0; idx < ARRAY_SIZE(peers); idx++) {
|
|
||||||
if (!device_is_ready(peers[idx].dev)) {
|
|
||||||
LOG_ERR("CDC ACM device %s is not ready",
|
|
||||||
peers[idx].dev->name);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = usb_enable(NULL);
|
|
||||||
if (ret != 0) {
|
|
||||||
LOG_ERR("Failed to enable USB");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
LOG_INF("Wait for DTR");
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
uart_line_ctrl_get(peers[0].dev, UART_LINE_CTRL_DTR, &dtr);
|
|
||||||
if (dtr) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
k_sleep(K_MSEC(100));
|
|
||||||
}
|
|
||||||
|
|
||||||
while (1) {
|
|
||||||
uart_line_ctrl_get(peers[1].dev, UART_LINE_CTRL_DTR, &dtr);
|
|
||||||
if (dtr) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
k_sleep(K_MSEC(100));
|
|
||||||
}
|
|
||||||
|
|
||||||
LOG_INF("DTR set, start test");
|
|
||||||
|
|
||||||
uart_line_set(peers[0].dev);
|
|
||||||
uart_line_set(peers[1].dev);
|
|
||||||
|
|
||||||
peers[0].data = &peers[1];
|
|
||||||
peers[1].data = &peers[0];
|
|
||||||
|
|
||||||
ring_buf_init(&peers[0].rb, sizeof(buffer0), buffer0);
|
|
||||||
ring_buf_init(&peers[1].rb, sizeof(buffer1), buffer1);
|
|
||||||
|
|
||||||
uart_irq_callback_user_data_set(peers[1].dev, interrupt_handler, &peers[0]);
|
|
||||||
uart_irq_callback_user_data_set(peers[0].dev, interrupt_handler, &peers[1]);
|
|
||||||
|
|
||||||
/* Enable rx interrupts */
|
|
||||||
uart_irq_rx_enable(peers[0].dev);
|
|
||||||
uart_irq_rx_enable(peers[1].dev);
|
|
||||||
return 0;
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue