Skip to content

Commit 4dd08c4

Browse files
authored
Merge pull request ARMmbed#14990 from ikmdani/stm32l1_usb_enable_pullups
Driver: USB: STM32L1: Managing internal pullups for usb enumeration
2 parents 881b7eb + 3e83108 commit 4dd08c4

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

targets/TARGET_STM/USBPhy_STM32.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020

2121
#include "USBPhyHw.h"
2222
#include "pinmap.h"
23+
#if defined(TARGET_STM32L1) && defined(SYSCFG_PMC_USB_PU)
24+
#include "stm32l1xx_ll_system.h"
25+
#endif
2326

2427
/* endpoint conversion macros */
2528
#define EP_TO_LOG(ep) ((ep) & 0xF)
@@ -189,15 +192,22 @@ USBPhyHw::~USBPhyHw()
189192

190193
}
191194

192-
#if defined(TARGET_STM32F1)
195+
#if defined(TARGET_STM32F1) || defined(SYSCFG_PMC_USB_PU)
193196

194197
#include "drivers/DigitalOut.h"
195198

196199
void USB_reenumerate()
197200
{
201+
#if defined(SYSCFG_PMC_USB_PU)
202+
// Manage internal pullups manually
203+
LL_SYSCFG_DisableUSBPullUp();
204+
wait_us(10000); // 10ms
205+
LL_SYSCFG_EnableUSBPullUp();
206+
#else
198207
// Force USB_DP pin (with external pull up) to 0
199208
mbed::DigitalOut usb_dp_pin(USB_DP, 0) ;
200209
wait_us(10000); // 10ms
210+
#endif
201211
}
202212
#endif
203213

@@ -282,9 +292,10 @@ void USBPhyHw::init(USBPhyEvents *events)
282292
hpcd.Init.speed = PCD_SPEED_FULL;
283293

284294
__HAL_RCC_USB_CLK_ENABLE();
295+
285296
map = PinMap_USB_FS;
286297

287-
#if defined(TARGET_STM32F1)
298+
#if defined(TARGET_STM32F1) || defined(SYSCFG_PMC_USB_PU)
288299
// USB_DevConnect is empty
289300
USB_reenumerate();
290301
#endif
@@ -407,7 +418,7 @@ void USBPhyHw::connect()
407418
// Initializes the USB controller registers
408419
USB_DevInit(hpcd.Instance, hpcd.Init); // hpcd.Init not used
409420

410-
#if defined(TARGET_STM32F1)
421+
#if defined(TARGET_STM32F1) || defined(SYSCFG_PMC_USB_PU)
411422
// USB_DevConnect is empty
412423
USB_reenumerate();
413424
#endif

0 commit comments

Comments
 (0)