diff --git a/drivers/console/uart_console.c b/drivers/console/uart_console.c index 752b81ed52..5d84660f02 100644 --- a/drivers/console/uart_console.c +++ b/drivers/console/uart_console.c @@ -34,9 +34,6 @@ #ifdef CONFIG_UART_CONSOLE_MCUMGR #include "mgmt/serial.h" #endif -#ifdef CONFIG_USB_UART_CONSOLE -#include -#endif static struct device *uart_console_dev; @@ -598,31 +595,9 @@ static int uart_console_init(struct device *arg) ARG_UNUSED(arg); + /* Claim console device */ uart_console_dev = device_get_binding(CONFIG_UART_CONSOLE_ON_DEV_NAME); - __ASSERT_NO_MSG(uart_console_dev); - -#if defined(CONFIG_USB_UART_CONSOLE) - int ret; - - ret = usb_enable(NULL); - if (ret != 0) { - return ret; - } - -#if defined(CONFIG_USB_UART_DTR_WAIT) - while (1) { - uint32_t dtr = 0U; - - uart_line_ctrl_get(uart_console_dev, UART_LINE_CTRL_DTR, &dtr); - if (dtr) { - break; - } - } - k_busy_wait(1000000); -#endif -#endif - uart_console_hook_install(); return 0; diff --git a/samples/boards/sensortile_box/src/main.c b/samples/boards/sensortile_box/src/main.c index 9db2d1f115..0f3da04eae 100644 --- a/samples/boards/sensortile_box/src/main.c +++ b/samples/boards/sensortile_box/src/main.c @@ -12,6 +12,8 @@ #include #include #include +#include +#include #include @@ -248,8 +250,21 @@ static void iis3dhhc_config(struct device *iis3dhhc) void main(void) { static struct device *led0, *led1; + struct device *dev = device_get_binding( + CONFIG_UART_CONSOLE_ON_DEV_NAME); int i, on = 1; int cnt = 1; + uint32_t dtr = 0; + + /* Application must enable USB by itself */ + if (usb_enable(NULL)) { + return; + } + + /* Poll if the DTR flag was set, optional */ + while (!dtr) { + uart_line_ctrl_get(dev, UART_LINE_CTRL_DTR, &dtr); + } led0 = device_get_binding(DT_GPIO_LABEL(DT_ALIAS(led0), gpios)); gpio_pin_configure(led0, DT_GPIO_PIN(DT_ALIAS(led0), gpios), diff --git a/samples/subsys/usb/console/src/main.c b/samples/subsys/usb/console/src/main.c index db23e528cd..9698a38f66 100644 --- a/samples/subsys/usb/console/src/main.c +++ b/samples/subsys/usb/console/src/main.c @@ -8,9 +8,24 @@ #include #include #include +#include +#include void main(void) { + struct device *dev = device_get_binding( + CONFIG_UART_CONSOLE_ON_DEV_NAME); + uint32_t dtr = 0; + + if (usb_enable(NULL)) { + return; + } + + /* Poll if the DTR flag was set, optional */ + while (!dtr) { + uart_line_ctrl_get(dev, UART_LINE_CTRL_DTR, &dtr); + } + if (strlen(CONFIG_UART_CONSOLE_ON_DEV_NAME) != strlen("CDC_ACM_0") || strncmp(CONFIG_UART_CONSOLE_ON_DEV_NAME, "CDC_ACM_0",