From ac1003875a0b0a48ae415e0d8f9aa945992c6902 Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Thu, 11 Aug 2016 10:25:42 -1000 Subject: [PATCH] USB Fix:iForce Soft Disconnect The STM32F404 OTG FS has an internal soft pull-up. The HW also has one too. So we need to overcome it to force a soft disconnect. --- src/drivers/boards/tap-v1/tap_init.c | 4 ++++ src/drivers/boards/tap-v1/tap_usb.c | 28 +++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/drivers/boards/tap-v1/tap_init.c b/src/drivers/boards/tap-v1/tap_init.c index d86a9dd01c..e7945942df 100644 --- a/src/drivers/boards/tap-v1/tap_init.c +++ b/src/drivers/boards/tap-v1/tap_init.c @@ -154,6 +154,10 @@ __EXPORT void stm32_boardinitialize(void) stm32_configgpio(GPIO_ADC1_IN10); + /* configure USB interfaces */ + + stm32_usbinitialize(); + /* configure SPI interfaces */ stm32_spiinitialize(); diff --git a/src/drivers/boards/tap-v1/tap_usb.c b/src/drivers/boards/tap-v1/tap_usb.c index 4c9f96007d..3bed1680c5 100644 --- a/src/drivers/boards/tap-v1/tap_usb.c +++ b/src/drivers/boards/tap-v1/tap_usb.c @@ -55,6 +55,10 @@ #include "up_arch.h" #include "stm32.h" #include "board_config.h" +#include "stm32_otgfs.h" + +#define GPIO_DP (GPIO_OUTPUT|GPIO_OPENDRAIN|GPIO_SPEED_50MHz|GPIO_OUTPUT_CLEAR|GPIO_PORTA|GPIO_PIN12) + /************************************************************************************ * Definitions @@ -78,13 +82,31 @@ __EXPORT void stm32_usbinitialize(void) { - /* The OTG FS has an internal soft pull-up */ + /* The OTG FS has an internal soft pull-up. + * The HW also has one too. So we need to overcome it. + * to force a soft disconnect. + */ + + /* Issue the Reset to the OTGFS Block */ + + uint32_t regval = getreg32(STM32_RCC_AHB2RSTR); + regval |= RCC_AHB2RSTR_OTGFSRST; + putreg32(regval, STM32_RCC_AHB2RSTR); + + /* Drive the DP Pin Low */ + + stm32_configgpio(GPIO_DP); + + /* Release the Reset to the OTGFS Block */ + + regval &= ~RCC_AHB2RSTR_OTGFSRST; + + putreg32(regval, STM32_RCC_AHB2RSTR); + /* Configure the OTG FS VBUS sensing GPIO */ -#ifdef CONFIG_STM32_OTGFS px4_arch_configgpio(GPIO_OTGFS_VBUS); -#endif } /************************************************************************************