Skip to content

Commit

Permalink
Disable VBUS sensing
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelbl committed Oct 18, 2020
1 parent 08c5f2a commit 2b603ff
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 2 additions & 0 deletions include/libopencm3/usb/dwc/otg_common.h
Expand Up @@ -99,6 +99,8 @@
#define OTG_GOTGCTL_HSHNPEN (1 << 10)
#define OTG_GOTGCTL_HNPRQ (1 << 9)
#define OTG_GOTGCTL_HNGSCS (1 << 8)
#define OTG_GOTGCTL_BVALOVAL (1 << 7)
#define OTG_GOTGCTL_BVALOEN (1 << 6)
#define OTG_GOTGCTL_SRQ (1 << 1)
#define OTG_GOTGCTL_SRQSCS (1 << 0)

Expand Down
17 changes: 13 additions & 4 deletions lib/usb/usb_f107.c
Expand Up @@ -17,6 +17,12 @@
* along with this library. If not, see <http://www.gnu.org/licenses/>.
*/

/*
* USB full-speed driver and peripheral initialization for STM32
* F1, F2 and F4 series with a OTG full-speed USB peripheral.
* The code support USB device mode only.
*/

#include <string.h>
#include <libopencm3/cm3/common.h>
#include <libopencm3/stm32/tools.h>
Expand Down Expand Up @@ -63,11 +69,14 @@ static usbd_device *stm32f107_usbd_init(void)
while (OTG_FS_GRSTCTL & OTG_GRSTCTL_CSRST);

if (OTG_FS_CID >= OTG_CID_HAS_VBDEN) {
/* Enable VBUS detection in device mode and power up the PHY. */
OTG_FS_GCCFG |= OTG_GCCFG_VBDEN | OTG_GCCFG_PWRDWN;
/* Disable VBUS sensing and power up the PHY. */
OTG_FS_GCCFG |= OTG_GCCFG_PWRDWN;
OTG_FS_GCCFG &= ~OTG_GCCFG_VBDEN;
OTG_FS_GOTGCTL |= OTG_GOTGCTL_BVALOEN| OTG_GOTGCTL_BVALOVAL;
} else {
/* Enable VBUS sensing in device mode and power up the PHY. */
OTG_FS_GCCFG |= OTG_GCCFG_VBUSBSEN | OTG_GCCFG_PWRDWN;
/* Disable VBUS sensing and power up the PHY. */
OTG_FS_GCCFG |= OTG_GCCFG_NOVBUSSENS | OTG_GCCFG_PWRDWN;
OTG_FS_GCCFG &= ~(OTG_GCCFG_VBUSBSEN | OTG_GCCFG_VBUSASEN);
}
/* Explicitly enable DP pullup (not all cores do this by default) */
OTG_FS_DCTL &= ~OTG_DCTL_SDIS;
Expand Down

0 comments on commit 2b603ff

Please sign in to comment.