Bug in HS USB device driver for STM32F4xxx (Middleware)

There's a nasty bug hidden in USBD_HS_STM32F4xx.c driver code.
It ALWAYS enables on-chip HSUSB PHY even if device is configured to use external PHY,
making PB15 wrongly routed to PHY instead of another configured peripheral (SPI2 MOSI in my case).

Fix is very simple:

static int32_t USBD_DeviceConnect (void) {
  if (!(otg_hs_state & OTG_HS_USBD_DRIVER_POWERED) ) { return ARM_DRIVER_ERROR; }
  if (  otg_hs_state & OTG_HS_USBD_DRIVER_CONNECTED) { return ARM_DRIVER_OK; }

  OTG->DCTL    &= ~OTG_HS_DCTL_SDIS;    // Soft disconnect disabled
#ifndef RTE_USB_OTG_HS_PHY
  OTG->GCCFG   |=  OTG_HS_GCCFG_PWRDWN;
#endif

  otg_hs_state |=  OTG_HS_USBD_DRIVER_CONNECTED;
  return ARM_DRIVER_OK;
}

It caused me a lot of headache, so I would like to share it with anyone that might have the similar
problem.

Parents
  • Does

    static int32_t USBD_DeviceConnect (void) {
    
      if ((otg_hs_state & OTG_HS_USBD_DRIVER_POWERED) == 0U) { return ARM_DRIVER_ERROR; }
    
      OTG->DCTL    &= ~OTG_HS_DCTL_SDIS;    // Soft disconnect disabled
    #ifndef MX_USB_OTG_HS_ULPI_D7_Pin
      OTG->GCCFG   |=  OTG_HS_GCCFG_PWRDWN; // Disable power down
    #endif
    
      return ARM_DRIVER_OK;
    }
    

    From the brand new STM32F4 DFP 2.5.0 solve this for you?

    I need to know as we're on the starting line of a new project where this might matter...

Reply
  • Does

    static int32_t USBD_DeviceConnect (void) {
    
      if ((otg_hs_state & OTG_HS_USBD_DRIVER_POWERED) == 0U) { return ARM_DRIVER_ERROR; }
    
      OTG->DCTL    &= ~OTG_HS_DCTL_SDIS;    // Soft disconnect disabled
    #ifndef MX_USB_OTG_HS_ULPI_D7_Pin
      OTG->GCCFG   |=  OTG_HS_GCCFG_PWRDWN; // Disable power down
    #endif
    
      return ARM_DRIVER_OK;
    }
    

    From the brand new STM32F4 DFP 2.5.0 solve this for you?

    I need to know as we're on the starting line of a new project where this might matter...

Children
More questions in this forum