diff --git a/arch/arm/soc/st_stm32/stm32l4/soc.h b/arch/arm/soc/st_stm32/stm32l4/soc.h index eaeb4103c8a..2397331bb32 100644 --- a/arch/arm/soc/st_stm32/stm32l4/soc.h +++ b/arch/arm/soc/st_stm32/stm32l4/soc.h @@ -55,6 +55,11 @@ #include #endif +#ifdef CONFIG_USB +/* Required to remove USB transceiver supply isolation */ +#include +#endif /* CONFIG_USB */ + #endif /* !_ASMLANGUAGE */ #endif /* _STM32L4X_SOC_H_ */ diff --git a/drivers/usb/device/usb_dc_stm32.c b/drivers/usb/device/usb_dc_stm32.c index c545997ea2b..0c23569fca5 100644 --- a/drivers/usb/device/usb_dc_stm32.c +++ b/drivers/usb/device/usb_dc_stm32.c @@ -330,6 +330,21 @@ int usb_dc_attach(void) return ret; } + /* + * Required for at least STM32L4 devices as they electrically + * isolate USB features from VDDUSB. It must be enabled before + * USB can function. Refer to DM00310109, section 5.1.3. + */ +#ifdef PWR_CR2_PVME1 + if (LL_APB1_GRP1_IsEnabledClock(LL_APB1_GRP1_PERIPH_PWR)) { + LL_PWR_EnableVddUSB(); + } else { + LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR); + LL_PWR_EnableVddUSB(); + LL_APB1_GRP1_DisableClock(LL_APB1_GRP1_PERIPH_PWR); + } +#endif /* PWR_CR2_PVME1 */ + return 0; }