STM32F7 USB HS Support

Hi @jeromecoutant,

I’m hoping to create a USB high speed device based on an STM32 part.

I want to use a STM32F723 because it includes the HS PHY.

I’ve got a 32F723EDISCOVERY and created a custom target because it isn’t a target that is currently supported by Mbed OS .

I’ve got a simple test app running that demonstrates USB FS working.

Unfortunately getting USB HS working is a bit trickier and I was hoped you might be able to offer some advice.

There’s a problem in USBPhy_STM32.cpp. If you look at line 197 you’ll see the same preprocessor command appears twice, i.e. line 209 can never be included in the compilation. If this section of code was ever included it would be a problem because it doesn’t assign map.

Was the intention to provide the code needed to support an embedded HS PHY?

I think what I need is something like:

#if (MBED_CONF_TARGET_USB_SPEED == USE_USB_OTG_HS)
    ...
#elif (MBED_CONF_TARGET_USB_SPEED == USE_USB_OTG_HS_EMBEDDED_PHY)
    hpcd.Instance = USB_OTG_HS;
    hpcd.Init.phy_itface = USB_OTG_HS_EMBEDDED_PHY;
    hpcd.Init.Sof_enable = 1;
    hpcd.Init.speed = PCD_SPEED_HIGH;
    map = PinMap_USB_HS;

But USB_OTG_HS_EMBEDDED_PHY probably should not be used here because it comes from stm32f7xx_ll_usb.h.

I don’t understand the significance of the USE_USB_HS_IN_FS configuration option. Was it intended to be related to HS embedded PHY? It’s odd that it doesn’t appear in any of the #ifs because if it was used I think map would not be assigned.

I’ve been trying to refer to the STM32F723E-Discovery examples in STM32CubeF7.

Thanks,
Matt

Hi Matt

You van have a look in DEV_USB Enable DISCO_F429ZI · jeromecoutant/mbed@d5f889b · GitHub

I think I have also seen the issue :slight_smile:

About USE_USB_HS_IN_FS, this mean we are using USB HS pins in FS mode

Jerome

Hi @jeromecoutant

I got my example working on the 32F723EDISCOVERY by forking mbed-os and making a couple of changes.

It wasn’t too difficult really. This works for me. At the moment this is just an experiment not a production project.

diff --git a/targets/TARGET_STM/USBPhy_STM32.cpp b/targets/TARGET_STM/USBPhy_STM32.cpp
index f3b15c88ba..f748dcd9a3 100644
--- a/targets/TARGET_STM/USBPhy_STM32.cpp
+++ b/targets/TARGET_STM/USBPhy_STM32.cpp
@@ -196,13 +196,12 @@ void USBPhyHw::init(USBPhyEvents *events)
 #endif
 #if (MBED_CONF_TARGET_USB_SPEED == USE_USB_OTG_HS)
     hpcd.Instance = USB_OTG_HS;
+    hpcd.Init.phy_itface = USB_OTG_HS_EMBEDDED_PHY;
-    hpcd.Init.phy_itface = PCD_PHY_ULPI;
     hpcd.Init.Sof_enable = 1;
     hpcd.Init.dma_enable = DISABLE;
     hpcd.Init.vbus_sensing_enable = ENABLE;
     hpcd.Init.use_external_vbus = DISABLE;
     hpcd.Init.speed = PCD_SPEED_HIGH;
+    __HAL_RCC_OTGPHYC_CLK_ENABLE();
     __HAL_RCC_USB_OTG_HS_CLK_ENABLE();
     __HAL_RCC_USB_OTG_HS_ULPI_CLK_ENABLE();
     map = PinMap_USB_HS;

In other words, I’ve made the USE_USB_OTG_HS option select the on-chip HS phy.

Obviously this solution isn’t suitable for the upstream.

It feels like MBED_CONF_TARGET_USB_SPEED needs another possibility, USE_USB_OTG_HS_EMBEDDED_PHY perhaps??

In other news, I’ve got the on-chip HS phy working but it didn’t make any difference to the throughput in my simple test. I’m wondering what I have to do to get the extra throughput??

Thanks,
Matt