diff --git a/chip/stm32/usb.c b/chip/stm32/usb.c index a0a37524be..b4dfb31fb5 100644 --- a/chip/stm32/usb.c +++ b/chip/stm32/usb.c @@ -326,3 +326,8 @@ void usb_release(void) /* disable USB device clock */ STM32_RCC_APB1ENR &= ~STM32_RCC_PB1_USB; } + +int usb_is_enabled(void) +{ + return (STM32_RCC_APB1ENR & STM32_RCC_PB1_USB) ? 1 : 0; +} diff --git a/chip/stm32/usb_console.c b/chip/stm32/usb_console.c index 6d81a5fa3c..665568a28a 100644 --- a/chip/stm32/usb_console.c +++ b/chip/stm32/usb_console.c @@ -146,6 +146,9 @@ static int usb_wait_console(void) timestamp_t deadline = get_time(); int wait_time_us = 1; + if (!is_enabled || !usb_is_enabled()) + return EC_SUCCESS; + deadline.val += USB_CONSOLE_TIMEOUT_US; /* diff --git a/include/usb_api.h b/include/usb_api.h index dc0a0fd654..193c948fb6 100644 --- a/include/usb_api.h +++ b/include/usb_api.h @@ -21,6 +21,9 @@ */ void usb_init(void); +/* Check if USB peripheral is enabled. */ +int usb_is_enabled(void); + /* * Enable the pullup on the DP line to signal that this device exists to the * host and to start the enumeration process.