cancel
Showing results for 
Search instead for 
Did you mean: 

Does USB host library support multiple devices through a hub?

infoinfo991
Associate III
Posted on July 14, 2013 at 22:32

Does the free ''STM32F105/7, STM32F2 and STM32F4 USB on-the-go Host and device library (UM1021)'' support reading data from a USB keyboard and USB mouse that are connected through a USB hub?

If not, does anybody know where I can get some free source code that does?

#usb
5 REPLIES 5
tsuneo
Senior
Posted on July 16, 2013 at 16:35

ST's host stack doesn't support hub yet.

I don't have hub code on ST's stack, 'cause I've written my original stack for our paid job 😉

If you would like to write the hub code, I could help you.

1) Enumeration of a hub, which directly connects to STM32F host port.

- This is the easiest part, existing stack code is applied almost as is.

- Get hub descriptor, to know the number of ports.

- Power up hub ports.

- Poll hub's status (interrupt IN) endpoint, to detect hub port status change (connection / disconnection)

2) Device enumeration over a hub port

- Hub's status EP reports change on one of hub port

- Using Get_Port_Status(), firmware knows device connection at the port

- after 100ms (or more) delay,

- bus reset is put to the segment of the port using Set_Port_Feature (PORT_RESET)

- Now that the device is connected to the main trunk of the bus.

- Run enumeration sequence, as usual, as if the device would directly connects to the host

- - Get_Descriptor(Device), Set_Address, Get_Descriptor(Config) and Set_Configuration

I posted more detailed summary on this post.

http://www.microchip.com/forums/fb.ashx?m=523499

Tsuneo

infoinfo991
Associate III
Posted on July 16, 2013 at 21:10

Thanks for the tip Tsuneo

To implement those sequence of events you've outlined, should I be using ST's provided files and add to them? Or should I start from scratch? I've sort of already started to read through the reference manual and write out my own code. I've recently obtained a JLink and will obtain a hardware USB analyzer soon. This should make it easier.

This is just a hobby project, but I'm debating between NXP and ST or maybe use AVR with MAX3421E. ST is the most difficult in terms of software but good in terms of hardware. I'm not sure if I should ''vote with my wallet'' and punish ST for not providing as much code.

edit:

I have begun to restructure the code, encapsulating some global variables into structs, and passing struct pointers into callback functions that need to know the originating device. The hardcoded device address has been replaced with something dynamic. I think I know what to do. From this point.
tsuneo
Senior
Posted on July 17, 2013 at 19:45

> To implement those sequence of events you've outlined, should I be using ST's provided files and add to them?

Yes, with a little modification of a ST's host example, the first step, the enumeration of hub itself, should be done. But you have to write 300-400 lines of code to implement the rest.

> This is just a hobby project, but I'm debating between NXP and ST or maybe use AVR with MAX3421E.

Arduino USB Host Shield (AVR with MAX3421E) is the easiest option, because it has already supported hub.

http://www.circuitsathome.com/arduino_usb_host_shield_projects

Tsuneo

infoinfo991
Associate III
Posted on July 19, 2013 at 07:45

I'm learning a lot while doing this coding.

The existing HID implementation doesn't support multiple interfaces. The deeper code for Get/Set Descriptor just assigns 0 to wIndex, I had to add more parameters to those functions so I can specify an interface number

I think I'll stick with ST since the dual OTG interface plus hub setup offers the lowest latency over all of my other options. A setup with multiple MAX3421E running on a slow AVR has the highest latency. out of all of my options

microstone
Associate
Posted on August 20, 2013 at 16:53

Hi Tsuneo,

Thank you for your detail steps on the hub port setup.

I met a problem after reset the port, in the STM32F2xx official usb stack, it uses USBH_GetDescriptor (pdev, phost, ..) to get the usb device descriptor.  After the hub port reset, the new device plugged into hub port is put to default address 0.  However, I cannot find any way to set the dev address back to 0, you know we need to set the device address to 1(or else) during the first round of enumeration. 

I also tried to create new host handlers, allocate new channel and tx/rx fifo for the new host, but after sending the ''GetDescriptor'' setup packet, there is no response.

In the AVR with Max3421e source code, I notice it uses ''regWr (rPERADDR, addr);'' to set the peripheral address.

So how do we do that in STM32 usb stack?