diff options
author | David Sidrane <david_s5@nscdg.com> | 2016-08-09 18:53:24 +0300 |
---|---|---|
committer | Karl Palsson <karlp@tweak.net.au> | 2017-01-11 01:32:20 +0300 |
commit | cf80e2bd5e19eadd8fe0e8719070fc59070a3459 (patch) | |
tree | 81bf1a1763579cf660d7476b66328c53db446c05 /lib/usb | |
parent | 6b5edeb091caa97568aeaabd6e9e3a6de7d0f9da (diff) |
stm32f4: USB support for newer OTG cores
Support for the conflicting bit definitions for vbus sensing on core id
version 0x2000+
Reviewed-by: Karl Palsson <karlp@tweak.net.au>
Diffstat (limited to 'lib/usb')
-rw-r--r-- | lib/usb/usb_f107.c | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/usb/usb_f107.c b/lib/usb/usb_f107.c index 1620482b..7f7902cc 100644 --- a/lib/usb/usb_f107.c +++ b/lib/usb/usb_f107.c @@ -54,11 +54,7 @@ const struct _usbd_driver stm32f107_usb_driver = { static usbd_device *stm32f107_usbd_init(void) { rcc_periph_clock_enable(RCC_OTGFS); - OTG_FS_GINTSTS = OTG_GINTSTS_MMIS; - OTG_FS_GUSBCFG |= OTG_GUSBCFG_PHYSEL; - /* Enable VBUS sensing in device mode and power down the PHY. */ - OTG_FS_GCCFG |= OTG_GCCFG_VBUSBSEN | OTG_GCCFG_PWRDWN; /* Wait for AHB idle. */ while (!(OTG_FS_GRSTCTL & OTG_GRSTCTL_AHBIDL)); @@ -66,9 +62,21 @@ static usbd_device *stm32f107_usbd_init(void) OTG_FS_GRSTCTL |= OTG_GRSTCTL_CSRST; 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; + } else { + /* Enable VBUS sensing in device mode and power up the PHY. */ + OTG_FS_GCCFG |= OTG_GCCFG_VBUSBSEN | OTG_GCCFG_PWRDWN; + } + /* Explicitly enable DP pullup (not all cores do this by default) */ + OTG_FS_DCTL &= ~OTG_DCTL_SDIS; + /* Force peripheral only mode. */ OTG_FS_GUSBCFG |= OTG_GUSBCFG_FDMOD | OTG_GUSBCFG_TRDT_MASK; + OTG_FS_GINTSTS = OTG_GINTSTS_MMIS; + /* Full speed device. */ OTG_FS_DCFG |= OTG_DCFG_DSPD; |