cancel
Showing results for 
Search instead for 
Did you mean: 

Single USB Host to Multiple USB Virtual Ports

LMorr.3
Senior II

Hello,

I have an STM32F373 and have successfully enabled a USB virtual com port.

I currently send data packets from a PC host to the slave device and include a 'deviceId' in the packet data header.

I would  like to support the single PC host communicating with multiple slave devices.   There would be no more than 12 slave devices, and I would like to add new devices. 

I plan on enabling a USB virtual com port for each slave device, and have them ignore packets not addressed to their deviceId.  Each device would only send a response if the packet is addressed to it.  The single host would ensure it only attempts to communicate with 1 device at a time.  

I recall seeing that STM32 allows the USB port to connect to multiple devices in this way. ( not sure though )  

What is the best way to connect each slave device to the USB connection?  Should I just split the 2 USB input (DM,DP) and send them to each slave device directly, or should I investigate a better circuit/components. ( eg. should I worry about current draw, diodes or isolation )

I could also have 1 slave device acting as 'master' for all other slave devices and have the PC host only communicate with that 1 slave device. ( use SPI or USART connection between slave devices instead of USB virtual host )

Lastly, I am looking at a USB hub controller IC, such as the TUSB1046.

Any advice will help.

Thank you,

 

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

A usb hub is going to be the easiest and probably most robust solution. You can create a composite USB device that embeds many different VCPs, but they do not really show up as independent devices and it can be hard find out which is which.

My preferred approach is to have as many devices as you need. Prefix their serial number with some value so you can tell them apart.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

9 REPLIES 9
TDK
Guru

A usb hub is going to be the easiest and probably most robust solution. You can create a composite USB device that embeds many different VCPs, but they do not really show up as independent devices and it can be hard find out which is which.

My preferred approach is to have as many devices as you need. Prefix their serial number with some value so you can tell them apart.

If you feel a post has answered your question, please click "Accept as Solution".
AScha.3
Chief III

Hi,

Basically your idea to connect some USB host and slaves via hubs is possible, BUT :

this is some kind of a network, so why not use something like RS485, UART , SPI, or CAN , whats (all of them ) is widespread used for network ?  And much more easy to realize !

To do it with USB is much more difficult , but ok, if you searching for a real challenge - good idea ! :)

If you feel a post has answered your question, please click "Accept as Solution".

Good to know this is your approach as it seems to be the best solution for my case.  I see benefits like being able to communicate with devices in parallel instead of using device addressing through a 'master' uC using I2C SS or packet header deviceId.  Adding a 'type' prefix to the uC's built-in serial number will allow the client to 'discover' USB devices and build a lookup table for future auto re-connections.

Do you use an external USB hub or do you build a usb hub circuit board ( ie. using TUSB1046 ) and connect devices into that board using custom non-usb cables/connectors?  My 'modules' will sit next to each other and I would like to minimize the USB cables required if possible. ( replacing them with small PCB->PCB cables like I do with my SPI/I2C )

Thanks!

An external hub will certainly be quicker. A custom PCB will take considerably more time/effort. You'd have to weigh if that effort is worth the convenience of a smaller form factor.

If you feel a post has answered your question, please click "Accept as Solution".

True, and at first, the user will only need 1 USB connection so no hub needed.  Even with 2 to 3 USB connections, still most likely no hub.  In my case, the majority of users will have 2 USB cables so it would have been nice to combine then into 1.  Some users will need more than 2 USB connections so using an external hub at that point will not seem like too much additional overheard.

I would be nice for me to add a small USB connector cable in case I even decide to get build a hub pcb and need to connect directly from PCB->PCB.  Have you done this before, and if so, do I just add 1 USB connector in line with my small USB PCB->PCB header?  I have USB protection neat the USB connector right now and assume I'll need to duplicate that protection at my USB PCB->PCB header.  ( and hope the user never connects both at the same time :)

As I understand: every MCU provides a USB VCP UART:

It should work: you get for every MCU a different COM port (it works for me: I can connect several of the same MCU, running the same FW, nothing to do in MCU FW). It just pops up as different COM ports.

The only thing is: the COM ports assigned seem to be a bit random: just changing the USB port changes also the COM port.

An USB hub should work to connect many MCU with USB VCP UART. Just to make sure, that Windows does not have a limitation how many COM ports can be established (or what the highest COM port number is).

Why do you need a "device ID" if USB UART is a dedicated COM port? (to differentiate between different boards)


@tjaekel wrote:

Just to make sure, that Windows does not have a limitation how many COM ports can be established (or what the highest COM port number is).


https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z000000PAhzSAG

 

It is really true: LOL

All the time when I connect the identical MCU (or Nucleo board), with the same chip, the "same" board, same FW... - I get a different COM port. I could see up to COM37 for my VCP UARTs assigned.

A bit "annoying" to change all the time the COM port in UART terminal just for the "identical" different board.

Is there a way to make it fix?
If I plug in a different board (the same type, same FW running), to get the same COM port again?

Or is there a way that MCU (Nucleo board) can "force" to be seen as a particular COM port? (I do not think so.)
(I guess, it is based on some "serial numbers" or "identifiers" during USB enumeration).

Actually a "bad idea" to get always the same COM port with "identical" board and FW: I would not be able to connect several identical boards at the same time. Good to have an "automatic" assignment of COM ports.

Just: how to figure out "which board is which"?
I assume, when using the unique serial number from inside the chip... but where to place it in the USB enumeration (so that I can figure out on Windows "which is which", e.g. showing me which USB VCP is connected to which S/N board)?

The problem with "always a new com port" is not new and to get around , you could:

- use a linux system

- in windows system set in registry, what it should do with "new" com port

(for FTDI serial->USB adapter we had this problem ...)

see

http://liionbms.com/pdf/DisableFTDI_Enumeration.pdf

https://serverfault.com/questions/117898/is-it-possible-to-reset-ftdi-virtual-com-ports-enumeration-we-easily-get-hundre

 

If you feel a post has answered your question, please click "Accept as Solution".