stm32 explicitily enable/disable vbus sense, fix warning

This commit is contained in:
hathach 2019-12-17 10:55:19 +07:00
parent d44a758a2d
commit ebc21144b8
No known key found for this signature in database
GPG Key ID: 2FA891220FBFD581

View File

@ -36,6 +36,29 @@
#include "common-hal/microcontroller/Pin.h"
STATIC void init_usb_vbus_sense(void) {
#ifdef BOARD_NO_VBUS
// Disable VBUS sensing
#ifdef USB_OTG_GCCFG_VBDEN
USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBDEN;
#else
USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_NOVBUSSENS;
USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSBSEN;
USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSASEN;
#endif
#else
// Enable VBUS hardware sensing
#ifdef USB_OTG_GCCFG_VBDEN
USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBDEN;
#else
USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_NOVBUSSENS;
USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_VBUSBSEN; // B Device sense
#endif
#endif
}
void init_usb_hardware(void) {
//TODO: if future chips overload this with options, move to peripherals management.
@ -82,20 +105,8 @@ void init_usb_hardware(void) {
never_reset_pin_number(0, 8);
#endif
#ifdef BOARD_NO_VBUS
disable_usb_vbus();
#endif
/* Peripheral clock enable */
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
}
STATIC void disable_usb_vbus(void) {
#ifdef USB_OTG_GCCFG_VBDEN
USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBDEN;
#else
USB_OTG_FS->GCCFG |= USB_OTG_GCCFG_NOVBUSSENS;
USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSBSEN;
USB_OTG_FS->GCCFG &= ~USB_OTG_GCCFG_VBUSASEN;
#endif
init_usb_vbus_sense();
}