Skip to content

Commit 21cbd5c

Browse files
authored
Merge pull request #2379 from hierophect/update-tusb
Update Tinyusb
2 parents e6fd513 + 8e38ca1 commit 21cbd5c

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

ports/stm32f4/boards/stm32f411ce_blackpill/mpconfigboard.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#define FLASH_PAGE_SIZE (0x4000)
3434

3535
#define BOARD_OSC_DIV 25
36+
#define BOARD_NO_VBUS
3637

3738
// On-board flash
3839
// #define SPI_FLASH_MOSI_PIN (&pin_PA07)

ports/stm32f4/supervisor/usb.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,33 @@
3232
#include "lib/mp-readline/readline.h"
3333
#include "stm32f4xx_hal.h"
3434

35+
#include "py/mpconfig.h"
36+
3537
#include "common-hal/microcontroller/Pin.h"
3638

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+
3762
void init_usb_hardware(void) {
3863
//TODO: if future chips overload this with options, move to peripherals management.
3964

@@ -79,7 +104,9 @@ void init_usb_hardware(void) {
79104
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
80105
never_reset_pin_number(0, 8);
81106
#endif
82-
107+
83108
/* Peripheral clock enable */
84109
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
110+
111+
init_usb_vbus_sense();
85112
}

0 commit comments

Comments
 (0)