Skip to main content
Explorer
May 1, 2024
Solved

How to use USBX on H7 for simultaneous host and device?

  • May 1, 2024
  • 6 replies
  • 3400 views

I've been trying to get a new project up and running on a custom H743 board, using AzureRTOS for the first time. This board has both USB ports, with FS set up as a device and HS set up as a host, with an external PHY. I have had this same hardware successfully running different firmware with ST's older drivers, and both ports work.

It seems like the code doesn't handle having both device and host ports active, even though CubeMX allows you to set it up that way. I run into some issues with both host and device drivers calling _ux_system_initialize, and that seems to trash some of the host's data structures when called by the device's driver code.

Either I'm missing something, or the code simply doesn't work for this configuration. I hope it's the former. Are there any code examples of running host and device on the same system?

 

    This topic has been closed for replies.
    Best answer by Mohamed_AYED

    Hi @ron239955_stm1 

    Actually generating a project multi instance HOST and Device is not supported with X-CUBE-AZRTOS-H7 pack.

     

    To support dual instance host and device you should flow this steps:

    1. the IRQ handler should be set up to invoke DCD/HCD handler correctly.
    2. ux_system_initialize must be called ONLY once, to manage memory for both host and device.
    3. the other device side initialization hand host side initialization sequence should be the same as what you did as device role only or host side role only.
    4. the HCD and DCD initialization should be called with the correct (different) register base to start up.

    6 replies

    Explorer
    May 2, 2024

    Hi @ron239955_stm1 

    Actually generating a project multi instance HOST and Device is not supported with X-CUBE-AZRTOS-H7 pack.

     

    To support dual instance host and device you should flow this steps:

    1. the IRQ handler should be set up to invoke DCD/HCD handler correctly.
    2. ux_system_initialize must be called ONLY once, to manage memory for both host and device.
    3. the other device side initialization hand host side initialization sequence should be the same as what you did as device role only or host side role only.
    4. the HCD and DCD initialization should be called with the correct (different) register base to start up.
    Explorer
    May 2, 2024

    Ok, thanks for the clarification. As long as USBX can handle it, I should be able to sort it out using your instructions. It would be great if support for this was added to the package at some point. I maintain a list of things that need to be repaired after I generate code from CubeMX and I like to keep that list as short as possible!

     

    Explorer
    May 2, 2024

    @ABOUA 

    ST Employee
    May 3, 2024

    Hi,

    Thanks Mohamed I agree with that sequence, please note that supporting the dual instances is in our todo list :)

    Regards

    Explorer
    April 2, 2025

    Here are some numbers I'm using:

    ThreadX memory pool size: 16384

    FileX memory pool size: 2048

    USBX Host memory pool size 32768

    USBX Device memory pool size 4096

    TX Application thread stack size 8192

    ThreadX timer stack size 1024

    UX thread stack size 2048

    UX host enum thread stack size 2048

    UX host HCD thread stack size 2048

    UX host HNP polling thread stack size 2048

    UX host class storage memory buffer size 8192

    UX host class storage thread stack size 2048

    I haven't turned on caches yet... Not even certain I need them, it's running quite fast as it is.

     

     

    Graduate II
    April 2, 2025

    Hi @ron239955_stm1 

    Thanks for the numbers.... Mine are a lot bigger.  Did you do any analysis (ie fill stacks with 0 and then see how many locations were used over time), or just educated guess?

     

    Explorer
    April 2, 2025

    I had to start by tracing through the code and see where it failed memory allocations, then bumping up the memory numbers appropriately. Then, I used the ThreadX task view in STM32CubeIDE to see how much stack the tasks were actually using and reduced anything that seemed like it had way too much.