samples: usb: console: get CDC ACM UART device from devicetree
Add app.overlay which contains chosen node and cdc-acm-uart node. Rework sample to get CDC ACM UART device from devicetree. Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
This commit is contained in:
parent
020843f249
commit
c3f87d9247
3 changed files with 27 additions and 17 deletions
18
samples/subsys/usb/console/app.overlay
Normal file
18
samples/subsys/usb/console/app.overlay
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021 Nordic Semiconductor ASA
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
/ {
|
||||||
|
chosen {
|
||||||
|
zephyr,console = &cdc_acm_uart0;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
&zephyr_udc0 {
|
||||||
|
cdc_acm_uart0: cdc_acm_uart0 {
|
||||||
|
compatible = "zephyr,cdc-acm-uart";
|
||||||
|
label = "CDC_ACM_0";
|
||||||
|
};
|
||||||
|
};
|
|
@ -1,7 +1,6 @@
|
||||||
CONFIG_USB_DEVICE_STACK=y
|
CONFIG_USB_DEVICE_STACK=y
|
||||||
CONFIG_USB_DEVICE_PRODUCT="Zephyr USB console sample"
|
CONFIG_USB_DEVICE_PRODUCT="Zephyr USB console sample"
|
||||||
CONFIG_USB_UART_CONSOLE=y
|
|
||||||
|
|
||||||
CONFIG_UART_INTERRUPT_DRIVEN=y
|
CONFIG_SERIAL=y
|
||||||
CONFIG_UART_LINE_CTRL=y
|
CONFIG_UART_LINE_CTRL=y
|
||||||
CONFIG_UART_CONSOLE_ON_DEV_NAME="CDC_ACM_0"
|
CONFIG_USB_UART_CONSOLE=y
|
||||||
|
|
|
@ -6,33 +6,26 @@
|
||||||
|
|
||||||
#include <zephyr.h>
|
#include <zephyr.h>
|
||||||
#include <sys/printk.h>
|
#include <sys/printk.h>
|
||||||
#include <sys/util.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <usb/usb_device.h>
|
#include <usb/usb_device.h>
|
||||||
#include <drivers/uart.h>
|
#include <drivers/uart.h>
|
||||||
|
|
||||||
|
BUILD_ASSERT(DT_NODE_HAS_COMPAT(DT_CHOSEN(zephyr_console), zephyr_cdc_acm_uart),
|
||||||
|
"Console device is not ACM CDC UART device");
|
||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
const struct device *dev = device_get_binding(
|
const struct device *dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_console));
|
||||||
CONFIG_UART_CONSOLE_ON_DEV_NAME);
|
|
||||||
uint32_t dtr = 0;
|
uint32_t dtr = 0;
|
||||||
|
|
||||||
if (usb_enable(NULL)) {
|
if (usb_enable(NULL)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Poll if the DTR flag was set, optional */
|
/* Poll if the DTR flag was set */
|
||||||
while (!dtr) {
|
while (!dtr) {
|
||||||
uart_line_ctrl_get(dev, UART_LINE_CTRL_DTR, &dtr);
|
uart_line_ctrl_get(dev, UART_LINE_CTRL_DTR, &dtr);
|
||||||
}
|
/* Give CPU resources to low priority threads. */
|
||||||
|
k_sleep(K_MSEC(100));
|
||||||
if (strlen(CONFIG_UART_CONSOLE_ON_DEV_NAME) !=
|
|
||||||
strlen("CDC_ACM_0") ||
|
|
||||||
strncmp(CONFIG_UART_CONSOLE_ON_DEV_NAME, "CDC_ACM_0",
|
|
||||||
strlen(CONFIG_UART_CONSOLE_ON_DEV_NAME))) {
|
|
||||||
printk("Error: Console device name is not USB ACM\n");
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue