From af615e9824b5c5181e8b74905819338aed3ffdee Mon Sep 17 00:00:00 2001 From: Frederic Pillon Date: Tue, 9 Feb 2021 11:48:06 +0100 Subject: [PATCH] [USB] Manage internal pull-up MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On STM32L1xx, an internal pull-up resistor (1.5 kΩ) can be connected by software on the USB data + (DP) line. This internal pull-up resistor is enabled if the USB is not in power-down mode and if the USB_PU bit is set. Signed-off-by: Frederic Pillon --- cores/arduino/stm32/usb/usbd_if.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/cores/arduino/stm32/usb/usbd_if.c b/cores/arduino/stm32/usb/usbd_if.c index e579140f72..a68a0ed58e 100644 --- a/cores/arduino/stm32/usb/usbd_if.c +++ b/cores/arduino/stm32/usb/usbd_if.c @@ -9,6 +9,7 @@ #include "usbd_if.h" #include "usbd_cdc_if.h" +#include "stm32yyxx_ll_system.h" #if !defined(USBD_REENUM_DISABLED) @@ -73,7 +74,7 @@ #endif /* (defined(USBD_DETACH_PIN) || defined(USBD_ATTACH_PIN)) && defined(USBD_FIXED_PULLUP) */ /* Either of these bits indicate that there are internal pullups */ -#if defined(USB_BCDR_DPPU) || defined(USB_OTG_DCTL_SDIS) +#if defined(USB_BCDR_DPPU) || defined(USB_OTG_DCTL_SDIS) || defined(SYSCFG_PMC_USB_PU) #define USBD_HAVE_INTERNAL_PULLUPS #endif /* defined(USB_BCDR_DPPU) || defined(USB_OTG_DCTL_SDIS) */ @@ -144,9 +145,22 @@ WEAK void USBD_reenumerate(void) digitalWriteFast(USBD_PULLUP_CONTROL_PINNAME, USBD_ATTACH_LEVEL); #endif /* defined(USBD_PULLUP_CONTROL_FLOATING) */ #elif defined(USBD_HAVE_INTERNAL_PULLUPS) +#if defined(SYSCFG_PMC_USB_PU) + /** + * STM32L1xx USB_DevDisconnect() and USB_DevConnect() + * do not manage the internal pull-up, so manage + * internal pull-up manually. + */ + __HAL_RCC_SYSCFG_CLK_ENABLE(); + LL_SYSCFG_DisableUSBPullUp(); + delay(USBD_ENUM_DELAY); + LL_SYSCFG_EnableUSBPullUp(); + +#else USB_DevDisconnect(USBD_USB_INSTANCE); delay(USBD_ENUM_DELAY); USB_DevConnect(USBD_USB_INSTANCE); +#endif #else #warning "No USB attach/detach method, USB might not be reliable through system resets" #endif