diff --git a/stmhal/boards/NETDUINO_PLUS_2/mpconfigboard.h b/stmhal/boards/NETDUINO_PLUS_2/mpconfigboard.h index 6de5a72c05..99d79d870e 100644 --- a/stmhal/boards/NETDUINO_PLUS_2/mpconfigboard.h +++ b/stmhal/boards/NETDUINO_PLUS_2/mpconfigboard.h @@ -36,3 +36,6 @@ #define MICROPY_HW_LED_OTYPE (GPIO_MODE_OUTPUT_PP) #define MICROPY_HW_LED_ON(pin) (pin->gpio->BSRRL = pin->pin_mask) #define MICROPY_HW_LED_OFF(pin) (pin->gpio->BSRRH = pin->pin_mask) + +// USB VBUS detect pin +#define MICROPY_HW_USB_VBUS_DETECT_PIN (pin_A9) diff --git a/stmhal/boards/PYBV10/mpconfigboard.h b/stmhal/boards/PYBV10/mpconfigboard.h index d4645e84fb..48c40e9936 100644 --- a/stmhal/boards/PYBV10/mpconfigboard.h +++ b/stmhal/boards/PYBV10/mpconfigboard.h @@ -38,3 +38,6 @@ #define MICROPY_HW_SDCARD_DETECT_PIN (pin_A8) #define MICROPY_HW_SDCARD_DETECT_PULL (GPIO_PULLUP) #define MICROPY_HW_SDCARD_DETECT_PRESENT (GPIO_PIN_RESET) + +// USB VBUS detect pin +#define MICROPY_HW_USB_VBUS_DETECT_PIN (pin_A9) diff --git a/stmhal/boards/PYBV3/mpconfigboard.h b/stmhal/boards/PYBV3/mpconfigboard.h index fdb45f4652..1afc5e8c76 100644 --- a/stmhal/boards/PYBV3/mpconfigboard.h +++ b/stmhal/boards/PYBV3/mpconfigboard.h @@ -37,3 +37,6 @@ #define MICROPY_HW_SDCARD_DETECT_PIN (pin_C13) #define MICROPY_HW_SDCARD_DETECT_PULL (GPIO_PULLDOWN) #define MICROPY_HW_SDCARD_DETECT_PRESENT (GPIO_PIN_SET) + +// USB VBUS detect pin +#define MICROPY_HW_USB_VBUS_DETECT_PIN (pin_A9) diff --git a/stmhal/boards/PYBV4/mpconfigboard.h b/stmhal/boards/PYBV4/mpconfigboard.h index 4355d6531f..a72da6f528 100644 --- a/stmhal/boards/PYBV4/mpconfigboard.h +++ b/stmhal/boards/PYBV4/mpconfigboard.h @@ -37,3 +37,6 @@ #define MICROPY_HW_SDCARD_DETECT_PIN (pin_A8) #define MICROPY_HW_SDCARD_DETECT_PULL (GPIO_PULLUP) #define MICROPY_HW_SDCARD_DETECT_PRESENT (GPIO_PIN_RESET) + +// USB VBUS detect pin +#define MICROPY_HW_USB_VBUS_DETECT_PIN (pin_A9) diff --git a/stmhal/boards/STM32F4DISC/mpconfigboard.h b/stmhal/boards/STM32F4DISC/mpconfigboard.h index ee207e65b2..b2ccefda5f 100644 --- a/stmhal/boards/STM32F4DISC/mpconfigboard.h +++ b/stmhal/boards/STM32F4DISC/mpconfigboard.h @@ -32,3 +32,6 @@ #define MICROPY_HW_LED_OTYPE (GPIO_MODE_OUTPUT_PP) #define MICROPY_HW_LED_ON(pin) (pin->gpio->BSRRL = pin->pin_mask) #define MICROPY_HW_LED_OFF(pin) (pin->gpio->BSRRH = pin->pin_mask) + +// USB VBUS detect pin +#define MICROPY_HW_USB_VBUS_DETECT_PIN (pin_A9) diff --git a/stmhal/usbd_conf.c b/stmhal/usbd_conf.c index 1ffee3fe90..2ff31c9892 100644 --- a/stmhal/usbd_conf.c +++ b/stmhal/usbd_conf.c @@ -71,10 +71,13 @@ void HAL_PCD_MspInit(PCD_HandleTypeDef *hpcd) HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); /* Configure VBUS Pin */ +#if defined(MICROPY_HW_USB_VBUS_DETECT_PIN) + // USB VBUS detect pin is always A9 GPIO_InitStruct.Pin = GPIO_PIN_9; GPIO_InitStruct.Mode = GPIO_MODE_INPUT; GPIO_InitStruct.Pull = GPIO_NOPULL; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); +#endif #if USE_USB_OTG_ID GPIO_InitStruct.Pin = GPIO_PIN_10; @@ -340,8 +343,8 @@ USBD_StatusTypeDef USBD_LL_Init (USBD_HandleTypeDef *pdev) hpcd.Init.phy_itface = PCD_PHY_EMBEDDED; hpcd.Init.Sof_enable = 0; hpcd.Init.speed = PCD_SPEED_FULL; -#if defined(HYDRABUSV10) - hpcd.Init.vbus_sensing_enable = 0; /* No VBUS Sensing on USB0 for HydraBus (VBUS is not connected on GPIOA9) */ +#if !defined(MICROPY_HW_USB_VBUS_DETECT_PIN) + hpcd.Init.vbus_sensing_enable = 0; // No VBUS Sensing on USB0 #else hpcd.Init.vbus_sensing_enable = 1; #endif