@@ -51,14 +51,24 @@ TU_ATTR_UNUSED static void Error_Handler(void) {
5151//--------------------------------------------------------------------+
5252// Forward USB interrupt events to TinyUSB IRQ Handler
5353//--------------------------------------------------------------------+
54+ #ifdef USB_DRD_FS
55+ void USB_IRQHandler (void ) {
56+ tusb_int_handler (0 , true);
57+ }
58+ #endif
59+ #ifdef USB_OTG_FS
5460void OTG_FS_IRQHandler (void ) {
55- tud_int_handler ( 0 );
61+ tusb_int_handler ( 0 , true );
5662}
5763
64+ #endif
65+ #ifdef USB_OTG_HS
5866void OTG_HS_IRQHandler (void ) {
59- tud_int_handler ( 0 );
67+ tusb_int_handler ( 0 , true );
6068}
6169
70+ #endif
71+
6272//--------------------------------------------------------------------+
6373// MACRO TYPEDEF CONSTANT ENUM
6474//--------------------------------------------------------------------+
@@ -172,16 +182,6 @@ void board_init(void) {
172182 GPIO_InitStruct .Mode = GPIO_MODE_INPUT ;
173183 GPIO_InitStruct .Pull = GPIO_NOPULL ;
174184 HAL_GPIO_Init (GPIOA , & GPIO_InitStruct );
175-
176- // Enable VBUS sense (B device) via pin PA9
177- USB_OTG_FS -> GCCFG |= USB_OTG_GCCFG_VBDEN ;
178- #else
179- // Disable VBUS sense (B device) via pin PA9
180- USB_OTG_FS -> GCCFG &= ~USB_OTG_GCCFG_VBDEN ;
181-
182- // B-peripheral session valid override enable
183- USB_OTG_FS -> GOTGCTL |= USB_OTG_GOTGCTL_BVALOEN ;
184- USB_OTG_FS -> GOTGCTL |= USB_OTG_GOTGCTL_BVALOVAL ;
185185 #endif // vbus sense
186186
187187 /* Enable USB power on Pwrctrl CR2 register */
@@ -210,15 +210,66 @@ void board_init(void) {
210210
211211 /*Configuring the SYSCFG registers OTG_HS PHY*/
212212 HAL_SYSCFG_EnableOTGPHY (SYSCFG_OTG_HS_PHY_ENABLE );
213+ #endif // USB_OTG_FS
214+ }
213215
214- // Disable VBUS sense (B device)
215- USB_OTG_HS -> GCCFG &= ~USB_OTG_GCCFG_VBDEN ;
216+ #if CFG_TUD_ENABLED
217+ void tud_pre_init_cb (uint8_t rhport ) {
218+ (void ) rhport ;
219+ #ifdef USB_OTG_FS
220+ #if defined(OTG_FS_VBUS_SENSE ) && OTG_FS_VBUS_SENSE
221+ // Enable VBUS sense (B device) via pin PM14
222+ USB_OTG_FS -> GCCFG |= USB_OTG_GCCFG_VBDEN ;
223+ #else
224+ // Disable VBUS sense (B device)
225+ USB_OTG_FS -> GCCFG &= ~USB_OTG_GCCFG_VBDEN ;
216226
217- // B-peripheral session valid override enable
218- USB_OTG_HS -> GCCFG |= USB_OTG_GCCFG_VBVALEXTOEN ;
219- USB_OTG_HS -> GCCFG |= USB_OTG_GCCFG_VBVALOVAL ;
220- #endif // USB_OTG_FS
227+ // B-peripheral session valid override enable
228+ USB_OTG_FS -> GOTGCTL |= USB_OTG_GOTGCTL_BVALOEN ;
229+ USB_OTG_FS -> GOTGCTL |= USB_OTG_GOTGCTL_BVALOVAL ;
230+ #endif
231+ #elif defined USB_OTG_HS
232+ #if defined(OTG_HS_VBUS_SENSE ) && OTG_HS_VBUS_SENSE
233+ // Enable VBUS sense (B device) via pin PM9
234+ USB_OTG_HS -> GCCFG |= USB_OTG_GCCFG_VBDEN ;
235+ #else
236+ // Disable VBUS sense (B device)
237+ USB_OTG_HS -> GCCFG &= ~USB_OTG_GCCFG_VBDEN ;
238+
239+ // B-peripheral session valid override enable
240+ USB_OTG_HS -> GCCFG |= USB_OTG_GCCFG_VBVALEXTOEN ;
241+ USB_OTG_HS -> GCCFG |= USB_OTG_GCCFG_VBVALOVAL ;
242+
243+ // Disable pull-downs
244+ USB_OTG_HS -> GCCFG &= ~USB_OTG_GCCFG_PULLDOWNEN ;
245+ #endif
246+ #endif
247+ }
248+ #endif
249+
250+ #if CFG_TUH_ENABLED
251+ void tuh_pre_init_cb (uint8_t rhport ) {
252+ (void ) rhport ;
253+ #ifdef USB_OTG_FS
254+ // Disable VBUS sense (B device)
255+ USB_OTG_FS -> GCCFG &= ~USB_OTG_GCCFG_VBDEN ;
256+
257+ // Disaable session valid override
258+ USB_OTG_FS -> GOTGCTL &= ~USB_OTG_GOTGCTL_BVALOEN ;
259+ USB_OTG_FS -> GOTGCTL &= ~USB_OTG_GOTGCTL_BVALOVAL ;
260+ #elif defined USB_OTG_HS
261+ // Disable VBUS sense (B device)
262+ USB_OTG_HS -> GCCFG &= ~USB_OTG_GCCFG_VBDEN ;
263+
264+ // Disaable session valid override
265+ USB_OTG_HS -> GOTGCTL &= ~USB_OTG_GCCFG_VBVALEXTOEN ;
266+ USB_OTG_HS -> GOTGCTL &= ~USB_OTG_GCCFG_VBVALOVAL ;
267+
268+ // Enable pull-downs
269+ USB_OTG_HS -> GCCFG |= USB_OTG_GCCFG_PULLDOWNEN ;
270+ #endif
221271}
272+ #endif
222273
223274//--------------------------------------------------------------------+
224275// Board porting API
0 commit comments