Skip to content

Commit 951633e

Browse files
committed
usb: add option to initialize USB device support at boot
Possibility to initialize USB device support is useful when only CDC ACM class is enabled and CDC ACM UART is used as backend for console, shell, or logging. Signed-off-by: Johann Fischer <[email protected]>
1 parent b5ab2f1 commit 951633e

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

subsys/usb/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,12 @@ config USB_WORKQUEUE_PRIORITY
152152
priority. This means that any work handler, once started, won't
153153
be preempted by any other thread until finished.
154154

155+
config USB_DEVICE_INITIALIZE_AT_BOOT
156+
bool "Initialize USB device support at boot"
157+
depends on USB_CDC_ACM
158+
help
159+
Use CDC ACM UART as backend for console, shell, or logging.
160+
155161
source "subsys/usb/class/Kconfig"
156162

157163
endif # USB_DEVICE_STACK

subsys/usb/usb_device.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,7 +1529,8 @@ int usb_enable(usb_dc_status_callback status_cb)
15291529
k_mutex_lock(&usb_enable_lock, K_FOREVER);
15301530

15311531
if (usb_dev.enabled == true) {
1532-
ret = 0;
1532+
LOG_WRN("USB device support already enabled");
1533+
ret = -EALREADY;
15331534
goto out;
15341535
}
15351536

@@ -1616,7 +1617,7 @@ static int usb_device_init(const struct device *dev)
16161617
uint8_t *device_descriptor;
16171618

16181619
if (usb_dev.enabled == true) {
1619-
return 0;
1620+
return -EALREADY;
16201621
}
16211622

16221623
/* register device descriptor */
@@ -1628,7 +1629,11 @@ static int usb_device_init(const struct device *dev)
16281629

16291630
usb_set_config(device_descriptor);
16301631

1632+
if (IS_ENABLED(CONFIG_USB_DEVICE_INITIALIZE_AT_BOOT)) {
1633+
return usb_enable(NULL);
1634+
}
1635+
16311636
return 0;
16321637
}
16331638

1634-
SYS_INIT(usb_device_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE);
1639+
SYS_INIT(usb_device_init, POST_KERNEL, CONFIG_APPLICATION_INIT_PRIORITY);

0 commit comments

Comments
 (0)