diff --git a/samples/subsys/usb/console/src/main.c b/samples/subsys/usb/console/src/main.c index 5decdb4ee900..6df51e2dbe82 100644 --- a/samples/subsys/usb/console/src/main.c +++ b/samples/subsys/usb/console/src/main.c @@ -7,19 +7,88 @@ #include #include #include +#include #include BUILD_ASSERT(DT_NODE_HAS_COMPAT(DT_CHOSEN(zephyr_console), zephyr_cdc_acm_uart), "Console device is not ACM CDC UART device"); +#if IS_ENABLED(CONFIG_USB_DEVICE_STACK_NEXT) +USBD_CONFIGURATION_DEFINE(config_1, + USB_SCD_SELF_POWERED, + 200); + +USBD_DESC_LANG_DEFINE(sample_lang); +USBD_DESC_STRING_DEFINE(sample_mfr, "ZEPHYR", 1); +USBD_DESC_STRING_DEFINE(sample_product, "Zephyr USBD ACM console", 2); +USBD_DESC_STRING_DEFINE(sample_sn, "0123456789ABCDEF", 3); + +USBD_DEVICE_DEFINE(sample_usbd, + DEVICE_DT_GET(DT_NODELABEL(zephyr_udc0)), + 0x2fe3, 0x0001); + +static int enable_usb_device_next(void) +{ + int err; + + err = usbd_add_descriptor(&sample_usbd, &sample_lang); + if (err) { + return err; + } + + err = usbd_add_descriptor(&sample_usbd, &sample_mfr); + if (err) { + return err; + } + + err = usbd_add_descriptor(&sample_usbd, &sample_product); + if (err) { + return err; + } + + err = usbd_add_descriptor(&sample_usbd, &sample_sn); + if (err) { + return err; + } + + err = usbd_add_configuration(&sample_usbd, &config_1); + if (err) { + return err; + } + + err = usbd_register_class(&sample_usbd, "cdc_acm_0", 1); + if (err) { + return err; + } + + err = usbd_init(&sample_usbd); + if (err) { + return err; + } + + err = usbd_enable(&sample_usbd); + if (err) { + return err; + } + + return 0; +} +#endif /* IS_ENABLED(CONFIG_USB_DEVICE_STACK_NEXT) */ + void main(void) { const struct device *const dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_console)); uint32_t dtr = 0; +#if IS_ENABLED(CONFIG_USB_DEVICE_STACK_NEXT) + if (enable_usb_device_next()) { + return; + } +#else if (usb_enable(NULL)) { return; } +#endif /* Poll if the DTR flag was set */ while (!dtr) { diff --git a/samples/subsys/usb/console/usbd_next_prj.conf b/samples/subsys/usb/console/usbd_next_prj.conf new file mode 100644 index 000000000000..36076b593adb --- /dev/null +++ b/samples/subsys/usb/console/usbd_next_prj.conf @@ -0,0 +1,10 @@ +CONFIG_USB_DEVICE_STACK_NEXT=y + +CONFIG_STDOUT_CONSOLE=y +CONFIG_SERIAL=y +CONFIG_UART_LINE_CTRL=y +CONFIG_USBD_CDC_ACM_CLASS=y + +CONFIG_LOG=y +CONFIG_USBD_LOG_LEVEL_WRN=y +CONFIG_UDC_DRIVER_LOG_LEVEL_WRN=y