Skip to content

[USBD] Force re-enumeration #426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cores/arduino/stm32/usb/usbd_conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#ifdef USBCON
/* Includes ------------------------------------------------------------------*/
#include "usbd_core.h"
#include "usbd_if.h"
#include "stm32yyxx_ll_pwr.h"

#ifndef HAL_PCD_MODULE_ENABLED
Expand Down Expand Up @@ -421,6 +422,7 @@ void USBWakeUp_IRQHandler(void)
*/
USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev)
{
USBD_reenumerate();
/* Set common LL Driver parameters */
g_hpcd.Init.dev_endpoints = 4;
g_hpcd.Init.ep0_mps = DEP0CTL_MPS_64;
Expand Down
41 changes: 41 additions & 0 deletions cores/arduino/stm32/usb/usbd_if.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
******************************************************************************
* @file usbd_if.c
* @author fpistm
* @brief USB Device common interface file
******************************************************************************
*/
#ifdef USBCON

#include "usbd_if.h"
/**
* @brief Force to re-enumerate USB
* @param None
* @retval None
*/

void USBD_reenumerate(void)
{
#ifndef USBD_REENUM_DISABLED
/* Re-enumerate the USB */
#ifdef USB_DISC_PIN
pinMode(USB_DISC_PIN, OUTPUT);
digitalWrite(USB_DISC_PIN, LOW);
#else
#ifdef USE_USB_HS_IN_FS
PinName pinDP = USB_OTG_HS_DP;
#elif defined(USB_OTG_FS)
PinName pinDP = USB_OTG_FS_DP;
#else /* USB */
PinName pinDP = USB_DP;
#endif
pin_function(pinDP, STM_PIN_DATA(STM_MODE_OUTPUT_PP, GPIO_NOPULL, 0));
digitalWriteFast(pinDP, LOW);
delay(USBD_ENUM_DELAY);
pin_function(pinDP, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
/*delay(USBD_ENUM_DELAY);*/
#endif /* USB_DISC_PIN */
#endif /* USBD_REENUM_DISABLED */
}

#endif /* USBCON */
32 changes: 32 additions & 0 deletions cores/arduino/stm32/usb/usbd_if.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
******************************************************************************
* @file usbd_if.h
* @author fpistm
* @brief Header file for the usbd_if.c file
******************************************************************************
*/

/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __USBD_IF_H
#define __USBD_IF_H

#ifdef USBCON
/* Includes ------------------------------------------------------------------*/
#include "Arduino.h"

/* Re-enumeration handling*/
#ifndef USBD_ENUM_DELAY
#define USBD_ENUM_DELAY 10
#endif

#ifdef __cplusplus
extern "C" {
#endif

void USBD_reenumerate(void);

#ifdef __cplusplus
}
#endif
#endif /* USBCON */
#endif /* __USBD_IF_H */
3 changes: 3 additions & 0 deletions variants/MAPLEMINI_F103CB/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ extern const PinName digitalPin[];
#define PIN_SERIAL_RX PA10
#define PIN_SERIAL_TX PA9

// USB
#define USB_DISC_PIN PB9

#ifdef __cplusplus
} // extern "C"
#endif
Expand Down