Skip to content

Commit 409b5ff

Browse files
authored
Merge pull request #1 from hathach/hierophect-update-tusb
stm32 explicitily enable/disable vbus sense, fix warning
2 parents d44a758 + ebc2114 commit 409b5ff

File tree

1 file changed

+24
-13
lines changed
  • ports/stm32f4/supervisor

1 file changed

+24
-13
lines changed

ports/stm32f4/supervisor/usb.c

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,29 @@
3636

3737
#include "common-hal/microcontroller/Pin.h"
3838

39+
STATIC void init_usb_vbus_sense(void) {
40+
41+
#ifdef BOARD_NO_VBUS
42+
// Disable VBUS sensing
43+
#ifdef USB_OTG_GCCFG_VBDEN
44+
USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBDEN;
45+
#else
46+
USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_NOVBUSSENS;
47+
USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSBSEN;
48+
USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSASEN;
49+
#endif
50+
#else
51+
// Enable VBUS hardware sensing
52+
#ifdef USB_OTG_GCCFG_VBDEN
53+
USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBDEN;
54+
#else
55+
USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_NOVBUSSENS;
56+
USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBUSBSEN; // B Device sense
57+
#endif
58+
#endif
59+
}
60+
61+
3962
void init_usb_hardware(void) {
4063
//TODO: if future chips overload this with options, move to peripherals management.
4164

@@ -82,20 +105,8 @@ void init_usb_hardware(void) {
82105
never_reset_pin_number(0, 8);
83106
#endif
84107

85-
#ifdef BOARD_NO_VBUS
86-
disable_usb_vbus();
87-
#endif
88-
89108
/* Peripheral clock enable */
90109
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
91-
}
92110

93-
STATIC void disable_usb_vbus(void) {
94-
#ifdef USB_OTG_GCCFG_VBDEN
95-
USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBDEN;
96-
#else
97-
USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_NOVBUSSENS;
98-
USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSBSEN;
99-
USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSASEN;
100-
#endif
111+
init_usb_vbus_sense();
101112
}

0 commit comments

Comments
 (0)