summaryrefslogtreecommitdiff
path: root/ports/stm/supervisor/usb.c
diff options
context:
space:
mode:
authorScott Shawcroft <scott@tannewt.org>2020-04-20 18:25:13 -0700
committerScott Shawcroft <scott@tannewt.org>2020-04-20 18:25:13 -0700
commitbebf27e73315386bfd862da46251a5efae56de75 (patch)
tree4bfac7c3b6b0779962cdd637d020a139419a6357 /ports/stm/supervisor/usb.c
parentabd340a8e465fedd2b5d74989440532c767ccf9e (diff)
parenta4d86b96fd1e60b807258a30cd765b48f0372b6d (diff)
Merge remote-tracking branch 'adafruit/master' into lower_power
This isn't perfect and needs a bit more testing.
Diffstat (limited to 'ports/stm/supervisor/usb.c')
-rw-r--r--ports/stm/supervisor/usb.c23
1 files changed, 17 insertions, 6 deletions
diff --git a/ports/stm/supervisor/usb.c b/ports/stm/supervisor/usb.c
index 07246dd4a..fe8dec657 100644
--- a/ports/stm/supervisor/usb.c
+++ b/ports/stm/supervisor/usb.c
@@ -29,7 +29,6 @@
#include "supervisor/usb.h"
#include "lib/utils/interrupt_char.h"
#include "lib/mp-readline/readline.h"
-#include "stm32f4xx_hal.h"
#include "py/mpconfig.h"
@@ -78,41 +77,53 @@ void init_usb_hardware(void) {
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
+ #if CPY_STM32H7
+ GPIO_InitStruct.Alternate = GPIO_AF10_OTG1_FS;
+ #elif CPY_STM32F4 || CPY_STM32F7
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
+ #endif
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
never_reset_pin_number(0, 11);
never_reset_pin_number(0, 12);
/* Configure VBUS Pin */
-#if !(BOARD_NO_VBUS_SENSE)
+ #if !(BOARD_NO_VBUS_SENSE)
GPIO_InitStruct.Pin = GPIO_PIN_9;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
never_reset_pin_number(0, 9);
-#endif
+ #endif
/* This for ID line debug */
GPIO_InitStruct.Pin = GPIO_PIN_10;
GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
+ #if CPY_STM32H7
+ GPIO_InitStruct.Alternate = GPIO_AF10_OTG1_FS;
+ #elif CPY_STM32F4 || CPY_STM32F7
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
+ #endif
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
never_reset_pin_number(0, 10);
-#ifdef STM32F412Zx
+ #ifdef STM32F412Zx
/* Configure POWER_SWITCH IO pin (F412 ONLY)*/
GPIO_InitStruct.Pin = GPIO_PIN_8;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
never_reset_pin_number(0, 8);
-#endif
+ #endif
+ #if CPY_STM32H7
+ HAL_PWREx_EnableUSBVoltageDetector();
+ __HAL_RCC_USB2_OTG_FS_CLK_ENABLE();
+ #else
/* Peripheral clock enable */
- __HAL_RCC_USB_OTG_FS_CLK_DISABLE();
__HAL_RCC_USB_OTG_FS_CLK_ENABLE();
+ #endif
init_usb_vbus_sense();
}