Skip to content

Commit 3dc530b

Browse files
committed
[USBD] Force re-enumeration
Enumeration delay could be redefined using USBD_ENUM_DELAY To disable re-enumeration define USBD_REENUM_DISABLED Use USB_DISC_PIN if defined. Signed-off-by: Frederic.Pillon <[email protected]>
1 parent 9889a09 commit 3dc530b

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

cores/arduino/stm32/usb/usbd_conf.c

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#ifdef USBCON
2020
/* Includes ------------------------------------------------------------------*/
2121
#include "usbd_core.h"
22+
#include "usbd_if.h"
2223
#include "stm32yyxx_ll_pwr.h"
2324

2425
#ifndef HAL_PCD_MODULE_ENABLED
@@ -421,6 +422,7 @@ void USBWakeUp_IRQHandler(void)
421422
*/
422423
USBD_StatusTypeDef USBD_LL_Init(USBD_HandleTypeDef *pdev)
423424
{
425+
USBD_reenumerate();
424426
/* Set common LL Driver parameters */
425427
g_hpcd.Init.dev_endpoints = 4;
426428
g_hpcd.Init.ep0_mps = DEP0CTL_MPS_64;

cores/arduino/stm32/usb/usbd_if.c

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
******************************************************************************
3+
* @file usbd_if.c
4+
* @author fpistm
5+
* @brief USB Device common interface file
6+
******************************************************************************
7+
*/
8+
#ifdef USBCON
9+
10+
#include "usbd_if.h"
11+
/**
12+
* @brief Force to re-enumerate USB
13+
* @param None
14+
* @retval None
15+
*/
16+
17+
void USBD_reenumerate(void)
18+
{
19+
#ifndef USBD_REENUM_DISABLED
20+
/* Re-enumerate the USB */
21+
#ifdef USB_DISC_PIN
22+
pinMode(USB_DISC_PIN, OUTPUT);
23+
digitalWrite(USB_DISC_PIN, LOW);
24+
#else
25+
#ifdef USE_USB_HS_IN_FS
26+
PinName pinDP = USB_OTG_HS_DP;
27+
#elif defined(USB_OTG_FS)
28+
PinName pinDP = USB_OTG_FS_DP;
29+
#else /* USB */
30+
PinName pinDP = USB_DP;
31+
#endif
32+
pin_function(pinDP, STM_PIN_DATA(STM_MODE_OUTPUT_PP, GPIO_NOPULL, 0));
33+
digitalWriteFast(pinDP, LOW);
34+
delay(USBD_ENUM_DELAY);
35+
pin_function(pinDP, STM_PIN_DATA(STM_MODE_INPUT, GPIO_NOPULL, 0));
36+
/*delay(USBD_ENUM_DELAY);*/
37+
#endif /* USB_DISC_PIN */
38+
#endif /* USBD_REENUM_DISABLED */
39+
}
40+
41+
#endif /* USBCON */

cores/arduino/stm32/usb/usbd_if.h

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
******************************************************************************
3+
* @file usbd_if.h
4+
* @author fpistm
5+
* @brief Header file for the usbd_if.c file
6+
******************************************************************************
7+
*/
8+
9+
/* Define to prevent recursive inclusion -------------------------------------*/
10+
#ifndef __USBD_IF_H
11+
#define __USBD_IF_H
12+
13+
#ifdef USBCON
14+
/* Includes ------------------------------------------------------------------*/
15+
#include "Arduino.h"
16+
17+
/* Re-enumeration handling*/
18+
#ifndef USBD_ENUM_DELAY
19+
#define USBD_ENUM_DELAY 10
20+
#endif
21+
22+
#ifdef __cplusplus
23+
extern "C" {
24+
#endif
25+
26+
void USBD_reenumerate(void);
27+
28+
#ifdef __cplusplus
29+
}
30+
#endif
31+
#endif /* USBCON */
32+
#endif /* __USBD_IF_H */

variants/MAPLEMINI_F103CB/variant.h

+3
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ extern const PinName digitalPin[];
117117
#define PIN_SERIAL_RX PA10
118118
#define PIN_SERIAL_TX PA9
119119

120+
// USB
121+
#define USB_DISC_PIN PB9
122+
120123
#ifdef __cplusplus
121124
} // extern "C"
122125
#endif

0 commit comments

Comments
 (0)