Showing results for 
Search instead for 
Did you mean: 

STM32 with usb HUB and multiple STM32 devices

Associate II


I been trying to set up a stm32F405 mcu usb host with a hub onto which 4x stm32 device is connected. I would use these 4 devices to send data to the main mcu periodicaly at 50Hz, and to have the data transfer syncronised from the 4 devices to be one after each other. When it is gatehred fromn all 4x the data is sent to PC.

Any idea how this could be programmed becouse I have limited knowledge  on this subject more precise I just started with it.

I read through most of the references which are related to the USB and possible hub solutions but could not find any usable information on, how to set up and use.

Can you give me sme guidance or some cinde ofn reference code or relation description how it should be done.

How Can I comunicate with the four device separately?
How to address each device?
How to receive data ready interrupt through usb to read from a specific device?
How to enumerate the devices?
How to communicate in bouh ways?
How to receive bulk data transfer from the external devices?


Pavel A.

Unfortunately the F4 USB host library provided by ST does not support hubs. If you manage to implement the hub functionality (or get a better USB Host library with hub class) what you describe should be possible.

You can also use other interfaces that are easier to do (UARTs, SPI...)

If all this still looks too hard or confusing, convince someone to help you.

Associate II

Thanks for the feedback.

Later I found some referece for code, not yet understanding fully:
I atached some connection graph, two versions from which will be chosen to be used.

One is to use, one interface and connect to it 4 usb devices, and to use csip select and interrupt lines to read from the usb line, not shure if this is possible. ther is another theory to just use the usb lines witout the extra control pins, not shure if it works.

And a second one which uses a hub in between the host and 4 devices.

UART - looks good and easier, but it looks slow to transfer data I have only 20ms to gather all the data from the 4x  external devices and send it off to pc.I would need at least 12mbit/s USB FS speeds to get the data in time.
SPI - also good but on longer cables I cant go higher than 4mhz for 2meter usb cable need to have a master transmitter and a return clock for a slave receive, on the host side and a lot of signaling cables cables.

Lead III

Honestly, that's too much for a beginner. But sure you can try, learn, but that will take some time.
And using other people's source code is perfectly okay, but if you don't know what's going on, debugging will be ... hard.

Anyway, the connection in the first pic on the left will not work, USB is a host managed bus that uses a point-to-point protocol, you cannot just connect 4 devices to the same port. 
Or was that different once with USB 1 ?


If you are using the internal PHY of the STM32, check the ERRATA document, most of the MCUs have a design error and may not be able to operate with the HUB correctly.

Pavel A.

@RBacs.1 The STM32F4 hub-related errata is for low-speed devices. STM32 itself in device mode is a full-speed device, so hopefully this errata doesn't apply. Long ago I've tried to reuse that project , with some success - but we've abandoned it.

As for other options:  UART with DMA  can be viable. Note that the "peripheral" STM32's can massage the data to reduce size.   SPI: there are hardware solutions to extend the wire length. There are other solutions for high speed over a long cable, with SPI connection to the MCU. Consult with a good hardware designer.


I used this library as a base to implement support for more than one HID interface. I also failed to implement HUB support, even using the original version of the FW_F4 package.

I left a suggestion for improvement in the repository:

About the Errata, I don't know if the HUB starts operations at low speed and then goes to full speed if available, if so, low speed problem may affect full speed.

No. Full speed is the "normal" case, low speed in fact is an afterthought requiring"extra attention" where the bug is.

+1 for seeking other solution.


Pavel A.

Hmm maybe the simple connection (no hub) of D+/D- may work, since the host and devices here do not need to be standard USB. A kind of multiplexer? Enumeration can be much simpler, no need to detect hot plug, read and parse descriptors... I don't know what is this thing, but here it is:



"4 devices to send data to the main mcu"

Would it be possible to use SPI port instead of USB to communicate between STM32?

The connection between the main MCU and the PC would remain via the USB port.

- Remembering that for commercial purposes it is necessary to register a license for the MCU operating in USB Device mode (perhaps that is why many people prefer to use dedicated chips such as FTDI).

If all slave devices are going to be present it could use Daisy-chain mode (it might be more work to do the communication, but it still should be less work than implementing USB HUB in STM32). If one of the slave devices is not present, a jumper on the data line (COPI-CIOP) would be necessary.


The other way of using SPI would be simpler to implement, but uses more pins, to activate each slave device.


Image source:

If slave devices need to be removable, maybe USB connectors can be used, but using SPI port, USB 3.0 connector line has more data paths as well.