From 3e83108f1c6a00c63d57e252ff81232414ca4343 Mon Sep 17 00:00:00 2001 From: Krishna Mohan Dani Date: Fri, 6 Aug 2021 19:09:36 +0530 Subject: [PATCH] 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 --- targets/TARGET_STM/USBPhy_STM32.cpp | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/targets/TARGET_STM/USBPhy_STM32.cpp b/targets/TARGET_STM/USBPhy_STM32.cpp index 8dcb420b53b..7f0c8d31420 100644 --- a/targets/TARGET_STM/USBPhy_STM32.cpp +++ b/targets/TARGET_STM/USBPhy_STM32.cpp @@ -20,6 +20,9 @@ #include "USBPhyHw.h" #include "pinmap.h" +#if defined(TARGET_STM32L1) && defined(SYSCFG_PMC_USB_PU) +#include "stm32l1xx_ll_system.h" +#endif /* endpoint conversion macros */ #define EP_TO_LOG(ep) ((ep) & 0xF) @@ -189,15 +192,22 @@ USBPhyHw::~USBPhyHw() } -#if defined(TARGET_STM32F1) +#if defined(TARGET_STM32F1) || defined(SYSCFG_PMC_USB_PU) #include "drivers/DigitalOut.h" void USB_reenumerate() { +#if defined(SYSCFG_PMC_USB_PU) + // Manage internal pullups manually + LL_SYSCFG_DisableUSBPullUp(); + wait_us(10000); // 10ms + LL_SYSCFG_EnableUSBPullUp(); +#else // Force USB_DP pin (with external pull up) to 0 mbed::DigitalOut usb_dp_pin(USB_DP, 0) ; wait_us(10000); // 10ms +#endif } #endif @@ -282,9 +292,10 @@ void USBPhyHw::init(USBPhyEvents *events) hpcd.Init.speed = PCD_SPEED_FULL; __HAL_RCC_USB_CLK_ENABLE(); + map = PinMap_USB_FS; -#if defined(TARGET_STM32F1) +#if defined(TARGET_STM32F1) || defined(SYSCFG_PMC_USB_PU) // USB_DevConnect is empty USB_reenumerate(); #endif @@ -407,7 +418,7 @@ void USBPhyHw::connect() // Initializes the USB controller registers USB_DevInit(hpcd.Instance, hpcd.Init); // hpcd.Init not used -#if defined(TARGET_STM32F1) +#if defined(TARGET_STM32F1) || defined(SYSCFG_PMC_USB_PU) // USB_DevConnect is empty USB_reenumerate(); #endif