Skip to content

Commit

Permalink
Merge pull request ARMmbed#14990 from ikmdani/stm32l1_usb_enable_pullups
Browse files Browse the repository at this point in the history
Driver: USB: STM32L1: Managing internal pullups for usb enumeration
  • Loading branch information
0xc0170 authored Aug 12, 2021
2 parents 881b7eb + 3e83108 commit 4dd08c4
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions targets/TARGET_STM/USBPhy_STM32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4dd08c4

Please sign in to comment.