Skip to content

Commit 3e83108

Browse files
committed
Driver: USB: STM32L1: Managing internal pullups for usb enumeration
This commit adds internal pullup on DP line for usb enumeration in nucleo_l152re platform. This platform as such does not have usb connector (device). This has been tested with example in https://github.com/ARMmbed/ mbed-os/blob/master/drivers/usb/include/usb/USBMouse.h#L58-L76 and mbed_app.json file "target_overrides": { "*": { "platform.stdio-baud-rate": 115200, "platform.all-stats-enabled": true, "mbed-trace.enable": "0" }, "NUCLEO_L152RE": { "target.device_has_add": ["USBDEVICE"] } } } Signed-off-by: Krishna Mohan Dani <[email protected]>
1 parent d4b1534 commit 3e83108

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)