summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ports/stm32f4/boards/stm32f411ce_blackpill/mpconfigboard.h1
-rw-r--r--ports/stm32f4/supervisor/usb.c29
2 files changed, 29 insertions, 1 deletions
diff --git a/ports/stm32f4/boards/stm32f411ce_blackpill/mpconfigboard.h b/ports/stm32f4/boards/stm32f411ce_blackpill/mpconfigboard.h
index a438b5baa..b8e374f05 100644
--- a/ports/stm32f4/boards/stm32f411ce_blackpill/mpconfigboard.h
+++ b/ports/stm32f4/boards/stm32f411ce_blackpill/mpconfigboard.h
@@ -33,6 +33,7 @@
#define FLASH_PAGE_SIZE (0x4000)
#define BOARD_OSC_DIV 25
+#define BOARD_NO_VBUS
// On-board flash
// #define SPI_FLASH_MOSI_PIN (&pin_PA07)
diff --git a/ports/stm32f4/supervisor/usb.c b/ports/stm32f4/supervisor/usb.c
index f327050f5..23fff1a36 100644
--- a/ports/stm32f4/supervisor/usb.c
+++ b/ports/stm32f4/supervisor/usb.c
@@ -32,8 +32,33 @@
#include "lib/mp-readline/readline.h"
#include "stm32f4xx_hal.h"
+#include "py/mpconfig.h"
+
#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.
@@ -79,7 +104,9 @@ void init_usb_hardware(void) {
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
never_reset_pin_number(0, 8);
#endif
-
+
/* Peripheral clock enable */
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
+
+ init_usb_vbus_sense();
}