cancel
Showing results for 
Search instead for 
Did you mean: 

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

ron239955_stm1
Associate III

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?

 

1 ACCEPTED SOLUTION

Accepted Solutions
Mohamed_AYED
Associate III

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.

View solution in original post

8 REPLIES 8
Mohamed_AYED
Associate III

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.

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!

 

Mohamed_AYED
Associate III

@ABOUA 

ABOUA
ST Employee

Hi,

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

Regards

I am also trying to do the same but with a U5G9 in dual role.


How should CubeMX be setup for this? Do I check core and controllers for both but leave DEVICE/HOST_SIDE_ONLY true for both?

I'm still working on getting this working, but you'll need to turn off DEVICE_SIDE_ONLY and HOST_SIDE_ONLY so that both host and device side code runs.

Other things I've found that need to be changed:

Adjust your host memory pool sizes to include memory for the device - both have to be allocated from the same pool.

In app_azure_rtos.c: tx_application_define() - comment out the call to tx_byte_pool_create() for the USB device, but keep the call to MX_USB_Device_Init(). It will use the memory pool allocated in the prior step (host initialization).

In app_usbx_device.c: MX_USBX_Device_Init() - comment out the calls to tx_byte_allocate and ux_system_initialize at the beginning of the function

With these changes, I have host working, and device is successfully making it through initialization. I can't get the device to show up on the connected computer yet, but hopefully I'll figure that out soon.

 

Thank you for sharing your findings in such a detailed post, once my hardware arrives I'll give it a shot (end of may).

If you don't mind please reply when you get it working.

I finally got it up and running. I had a problem in my hardware that was quite tricky to find, but now that that's resolved, I'm getting positive results. I haven't tested it extensively yet, but with the above configuration changes, I'm able to read from a thumb drive, and my device appears as a virtual com port when connected to a computer.

The trickiest part of this has been memory pool and buffer allocation. For testing purposes, I could have just thrown a lot of memory at it, and/or used dynamic allocation. But, my project is going to need all the memory it can get, so I want to allocate only what Azure RTOS needs. It seems like STM32CubeMX could do some calculations to get a workable memory pool size based on the user's configuration.