Skip to content

Commit 2a994a3

Browse files
committed
add stm32u5, stm32h7rs support
Signed-off-by: HiFiPhile <admin@hifiphile.com>
1 parent 27ea4d1 commit 2a994a3

File tree

3 files changed

+128
-50
lines changed

3 files changed

+128
-50
lines changed
Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
board:mimxrt1060_evk
2-
board:mimxrt1064_evk
3-
board:mcb1800
41
family:espressif
5-
mcu:CH32V20X
6-
mcu:ra6m5
7-
mcu:MAX3421
2+
mcu:STM32F2
83
mcu:STM32F4
4+
mcu:STM32U5
95
mcu:STM32F7
106
mcu:STM32H7
11-
mcu:ESP32P4
7+
mcu:STM32H7RS

hw/bsp/stm32h7rs/family.c

Lines changed: 56 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -356,16 +356,6 @@ void board_init(void) {
356356
GPIO_InitStruct.Pull = GPIO_NOPULL;
357357
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
358358
HAL_GPIO_Init(GPIOM, &GPIO_InitStruct);
359-
360-
// Enable VBUS sense (B device) via pin PM14
361-
USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBDEN;
362-
#else
363-
// Disable VBUS sense (B device)
364-
USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBDEN;
365-
366-
// B-peripheral session valid override enable
367-
USB_OTG_FS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOEN;
368-
USB_OTG_FS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOVAL;
369359
#endif // vbus sense
370360
#endif
371361

@@ -387,21 +377,6 @@ void board_init(void) {
387377
GPIO_InitStruct.Pull = GPIO_NOPULL;
388378
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_HS;
389379
HAL_GPIO_Init(GPIOM, &GPIO_InitStruct);
390-
391-
// Enable VBUS sense (B device) via pin PM9
392-
USB_OTG_HS->GCCFG |= USB_OTG_GCCFG_VBDEN;
393-
#else
394-
// Disable VBUS sense (B device)
395-
USB_OTG_HS->GCCFG &= ~USB_OTG_GCCFG_VBDEN;
396-
397-
#if CFG_TUD_ENABLED && BOARD_TUD_RHPORT == 1
398-
// B-peripheral session valid override enable
399-
USB_OTG_HS->GCCFG |= USB_OTG_GCCFG_VBVALEXTOEN;
400-
USB_OTG_HS->GCCFG |= USB_OTG_GCCFG_VBVALOVAL;
401-
#else
402-
USB_OTG_HS->GCCFG |= USB_OTG_GCCFG_PULLDOWNEN;
403-
#endif
404-
405380
#endif
406381
#endif
407382

@@ -412,6 +387,62 @@ void board_init(void) {
412387
#endif
413388
}
414389

390+
#if CFG_TUD_ENABLED
391+
void tud_pre_init_cb(uint8_t rhport) {
392+
if (rhport == 0) {
393+
#if OTG_FS_VBUS_SENSE && BOARD_TUD_RHPORT == 0
394+
// Enable VBUS sense (B device) via pin PM14
395+
USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBDEN;
396+
#else
397+
// Disable VBUS sense (B device)
398+
USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBDEN;
399+
400+
// B-peripheral session valid override enable
401+
USB_OTG_FS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOEN;
402+
USB_OTG_FS->GOTGCTL |= USB_OTG_GOTGCTL_BVALOVAL;
403+
#endif
404+
} else if (rhport == 1) {
405+
#if OTG_HS_VBUS_SENSE && BOARD_TUD_RHPORT == 1
406+
// Enable VBUS sense (B device) via pin PM9
407+
USB_OTG_HS->GCCFG |= USB_OTG_GCCFG_VBDEN;
408+
#else
409+
// Disable VBUS sense (B device)
410+
USB_OTG_HS->GCCFG &= ~USB_OTG_GCCFG_VBDEN;
411+
412+
// B-peripheral session valid override enable
413+
USB_OTG_HS->GCCFG |= USB_OTG_GCCFG_VBVALEXTOEN;
414+
USB_OTG_HS->GCCFG |= USB_OTG_GCCFG_VBVALOVAL;
415+
416+
// Disable pull-downs
417+
USB_OTG_HS->GCCFG &= ~USB_OTG_GCCFG_PULLDOWNEN;
418+
#endif
419+
}
420+
}
421+
#endif
422+
423+
#if CFG_TUH_ENABLED
424+
void tuh_pre_init_cb(uint8_t rhport) {
425+
if (rhport == 0) {
426+
// Disable VBUS sense (B device)
427+
USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBDEN;
428+
429+
// Disaable session valid override
430+
USB_OTG_FS->GOTGCTL &= ~USB_OTG_GOTGCTL_BVALOEN;
431+
USB_OTG_FS->GOTGCTL &= ~USB_OTG_GOTGCTL_BVALOVAL;
432+
} else if (rhport == 1) {
433+
// Disable VBUS sense (B device)
434+
USB_OTG_HS->GCCFG &= ~USB_OTG_GCCFG_VBDEN;
435+
436+
// Disaable session valid override
437+
USB_OTG_HS->GOTGCTL &= ~USB_OTG_GCCFG_VBVALEXTOEN;
438+
USB_OTG_HS->GOTGCTL &= ~USB_OTG_GCCFG_VBVALOVAL;
439+
440+
// Enable pull-downs
441+
USB_OTG_HS->GCCFG |= USB_OTG_GCCFG_PULLDOWNEN;
442+
}
443+
}
444+
#endif
445+
415446
//--------------------------------------------------------------------+
416447
// Board porting API
417448
//--------------------------------------------------------------------+

hw/bsp/stm32u5/family.c

Lines changed: 69 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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
5460
void OTG_FS_IRQHandler(void) {
55-
tud_int_handler(0);
61+
tusb_int_handler(0, true);
5662
}
5763

64+
#endif
65+
#ifdef USB_OTG_HS
5866
void 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

Comments
 (0)