Skip to content

Commit 8160331

Browse files
committed
[USB] Manage internal pull-up
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 <frederic.pillon@st.com>
1 parent c4f9aaa commit 8160331

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

cores/arduino/stm32/usb/usbd_if.c

+15-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "usbd_if.h"
1111
#include "usbd_cdc_if.h"
12+
#include "stm32yyxx_ll_system.h"
1213

1314
#if !defined(USBD_REENUM_DISABLED)
1415

@@ -73,7 +74,7 @@
7374
#endif /* (defined(USBD_DETACH_PIN) || defined(USBD_ATTACH_PIN)) && defined(USBD_FIXED_PULLUP) */
7475

7576
/* Either of these bits indicate that there are internal pullups */
76-
#if defined(USB_BCDR_DPPU) || defined(USB_OTG_DCTL_SDIS)
77+
#if defined(USB_BCDR_DPPU) || defined(USB_OTG_DCTL_SDIS) || defined(SYSCFG_PMC_USB_PU)
7778
#define USBD_HAVE_INTERNAL_PULLUPS
7879
#endif /* defined(USB_BCDR_DPPU) || defined(USB_OTG_DCTL_SDIS) */
7980

@@ -144,9 +145,22 @@ WEAK void USBD_reenumerate(void)
144145
digitalWriteFast(USBD_PULLUP_CONTROL_PINNAME, USBD_ATTACH_LEVEL);
145146
#endif /* defined(USBD_PULLUP_CONTROL_FLOATING) */
146147
#elif defined(USBD_HAVE_INTERNAL_PULLUPS)
148+
#if defined(SYSCFG_PMC_USB_PU)
149+
/**
150+
* STM32L1xx USB_DevDisconnect() and USB_DevConnect()
151+
* do not manage the internal pull-up, so manage
152+
* internal pull-up manually.
153+
*/
154+
__HAL_RCC_SYSCFG_CLK_ENABLE();
155+
LL_SYSCFG_DisableUSBPullUp();
156+
delay(USBD_ENUM_DELAY);
157+
LL_SYSCFG_EnableUSBPullUp();
158+
159+
#else
147160
USB_DevDisconnect(USBD_USB_INSTANCE);
148161
delay(USBD_ENUM_DELAY);
149162
USB_DevConnect(USBD_USB_INSTANCE);
163+
#endif
150164
#else
151165
#warning "No USB attach/detach method, USB might not be reliable through system resets"
152166
#endif

0 commit comments

Comments
 (0)