ESP32-S3 USB OTG - USB Hub support?

tore-espressif
Posts: 19
Joined: Thu Oct 07, 2021 8:11 am

Re: ESP32-S3 USB OTG - USB Hub support?

Postby tore-espressif » Fri Dec 29, 2023 7:17 pm

Hi everyone,
Here's an update about this topic, that should answer all questions mentioned here.

Espressif's USB Host implementation is fully open-source. The only non-public part is the USB peripheral itself (that is 3rd party Synopsys DWC).

The HUB feature must be implemented in esp-idf (open source ESP-IDF codebase), where the rest of USB Host driver is.

There are some notable limitations, when implementing HUB support, that are coming from the USB peripheral. ESP32-S2 and S3 implements 'smaller' version of the USB peripheral, to save chip size and manufacturing costs. In practice, it has following implications:

1. Limited number of USB channels - 8: Only 8 endpoints (including EP0s) can be active at the same time. Small USB devices typically implement EP0 and 2 additional endpoints (1 IN and 1 OUT). The USB HUB also has EP0 and 1 IN endpoint. In this example scenario, only 2 USB devices can be active at the same time.

2. Small Receive FIFO - 512 bytes: 512 bytes is borderline enough for one streaming (high-bandwidth) FullSpeed device. It will not be possible to stream from 2 USB camera at the same time on S2/3 (at reasonable definition of the video).

Other usecases, such as ESP->HUB->CDC device or ESP->HUB->2xHID device are feasible.

Current status
We have an internal work-in-progress branch that adds support for HUBs. Currently you can hot-plug devices, HUBs and run all the current examples (HID, CDC, UVC, MSC) through USB HUB, even with multiple layer HUBs.
We have not merged it yet (and made it public), because the feature requires more testing and reviews.
If there is anyone willing to test/contribute we can make the branch public on GitHub so you can start prototyping faster.

Side note: Porting to TinyUSB Host should be possible, but we don't plan to support it.

moefear85
Posts: 44
Joined: Sun Sep 05, 2021 4:55 pm

Re: ESP32-S3 USB OTG - USB Hub support?

Postby moefear85 » Sat Dec 30, 2023 11:34 pm

Why not just open it up as beta and let anyone/everyone test at their leisure? That's effectively how things are anyways with the rest of esp-idf, everybody heads to the issues section to report problems. I don't think it makes sense to require anyone/someone to proclaim themselves as official testers in order for the HUB code to be open-sourced (if its on a private branch, then it's effectively closed-source or no-source).

devlat
Posts: 15
Joined: Thu Oct 29, 2020 9:33 am

Re: ESP32-S3 USB OTG - USB Hub support?

Postby devlat » Sat Jan 20, 2024 10:29 am

Can you please be more specific what is meant by " Only 8 endpoints (including EP0s) can be active at the same time" ?
Especially in the context of HID devices. You mean only 8 endpoints can have scheduled IN/OUT transactions inside one 1 ms frame?
Or is this some enumeration limit, i.e. 3rd HID device may not be enumerated at all?

tore-espressif
Posts: 19
Joined: Thu Oct 07, 2021 8:11 am

Re: ESP32-S3 USB OTG - USB Hub support?

Postby tore-espressif » Tue Jan 23, 2024 7:55 am

You mean only 8 endpoints can have scheduled IN/OUT transactions inside one 1 ms frame?
Yes, this is a HW limitation. Each active endpoint must have a HW implementation (channel). There are 8 such implementations (channels) in ESP32-S2/S3.
Or is this some enumeration limit, i.e. 3rd HID device may not be enumerated at all?
Again yes, this is a software/hardware limitation. In current implementation, each endpoint of a connected device is assigned to a channel. So the host driver will fail to open a device if it has run out of channels. In theory, the HW channels could be reused (recycled) to serve multiple endpoints in round-robin fashion. This is fairly complex and lower-priority at this moment.

Just for completeness, the upcoming ESP32-P4 will have 16 High Speed channels.

devlat
Posts: 15
Joined: Thu Oct 29, 2020 9:33 am

Re: ESP32-S3 USB OTG - USB Hub support?

Postby devlat » Tue Jan 23, 2024 8:02 pm

>In theory, the HW channels could be reused (recycled) to serve multiple endpoints in round-robin fashion. This is fairly complex and lower-priority at this moment.

Actually, this was the point of my question. For example, if IN endpoint reports 4 ms interval we should allocate HW channel and query it once per 4 frames only, and in other frames this channel could be reused for other endpoints. Alas, your answer tells me i want "too much" and all channels are allocated statically during enumeration time, not dynamically per frame.
Also sometimes we may have to deal with composite devices with lot of endpoints on different interfaces, but we may want to use
only some of them. Would it be possible for application layer to make decision for which endpoint we need to allocate HW channels and which can be skipped? This at least could partially solve the issue with lack of channels.
Anyway, thank you for explanation! This helps a lot.

JimmyPedersen
Posts: 21
Joined: Sun Nov 15, 2015 4:14 am

Re: ESP32-S3 USB OTG - USB Hub support?

Postby JimmyPedersen » Thu Jan 25, 2024 4:08 pm

With the Beta USB-Hub support would it be possible to just read the VID/PID + serial from a large number (20 devices total ie. HUBs connected to HUB with multiple devices in each) of connected USB devices (Phones in this case) and detect insertion/removal ?
If so I'm very interested in testing this out as we have a customer interested in this.
Kind regards
Jimmy

marks_cheider
Posts: 3
Joined: Tue Aug 15, 2023 7:25 am

Re: ESP32-S3 USB OTG - USB Hub support?

Postby marks_cheider » Mon Jan 29, 2024 7:19 am

Hi everybody. Any news?

maaamc
Posts: 7
Joined: Tue Feb 13, 2024 2:28 pm

Re: ESP32-S3 USB OTG - USB Hub support?

Postby maaamc » Tue Feb 13, 2024 2:31 pm

tore-espressif wrote:
Fri Dec 29, 2023 7:17 pm
Hi everyone,
Here's an update about this topic, that should answer all questions mentioned here.

Espressif's USB Host implementation is fully open-source. The only non-public part is the USB peripheral itself (that is 3rd party Synopsys DWC).

The HUB feature must be implemented in esp-idf (open source ESP-IDF codebase), where the rest of USB Host driver is.

There are some notable limitations, when implementing HUB support, that are coming from the USB peripheral. ESP32-S2 and S3 implements 'smaller' version of the USB peripheral, to save chip size and manufacturing costs. In practice, it has following implications:

1. Limited number of USB channels - 8: Only 8 endpoints (including EP0s) can be active at the same time. Small USB devices typically implement EP0 and 2 additional endpoints (1 IN and 1 OUT). The USB HUB also has EP0 and 1 IN endpoint. In this example scenario, only 2 USB devices can be active at the same time.

2. Small Receive FIFO - 512 bytes: 512 bytes is borderline enough for one streaming (high-bandwidth) FullSpeed device. It will not be possible to stream from 2 USB camera at the same time on S2/3 (at reasonable definition of the video).

Other usecases, such as ESP->HUB->CDC device or ESP->HUB->2xHID device are feasible.

Current status
We have an internal work-in-progress branch that adds support for HUBs. Currently you can hot-plug devices, HUBs and run all the current examples (HID, CDC, UVC, MSC) through USB HUB, even with multiple layer HUBs.
We have not merged it yet (and made it public), because the feature requires more testing and reviews.
If there is anyone willing to test/contribute we can make the branch public on GitHub so you can start prototyping faster.

Side note: Porting to TinyUSB Host should be possible, but we don't plan to support it.

Hi, where can i find the beta code or may be the stable one to use devices through hubs ?
thanks.

tore-espressif
Posts: 19
Joined: Thu Oct 07, 2021 8:11 am

Re: ESP32-S3 USB OTG - USB Hub support?

Postby tore-espressif » Wed Feb 14, 2024 8:28 am

Would it be possible for application layer to make decision for which endpoint we need to allocate HW channels and which can be skipped? This at least could partially solve the issue with lack of channels.
This is how it works now! Upon device connection only EP0 is allocated, which must be present for successful device enumeration. After that, the application is responsible for selection which USB functions from the composite device (that is which USB interface and endpoints) it wants to use, only those are allocated.
With the Beta USB-Hub support would it be possible to just read the VID/PID + serial from a large number (20 devices total ie. HUBs connected to HUB with multiple devices in each) of connected USB devices (Phones in this case) and detect insertion/removal
This should be possible, although we haven't tested with 20 devices. The nested HUBs work fine in our initial tests. The Beta support would mean here, that if you unplug too many devices and/or HUBs at the same time, we occasionally see crashes.

We aim to prepare a beta branch for public testing within a week

maaamc
Posts: 7
Joined: Tue Feb 13, 2024 2:28 pm

Re: ESP32-S3 USB OTG - USB Hub support?

Postby maaamc » Thu Feb 15, 2024 8:25 am

tore-espressif wrote:
Wed Feb 14, 2024 8:28 am
Would it be possible for application layer to make decision for which endpoint we need to allocate HW channels and which can be skipped? This at least could partially solve the issue with lack of channels.
This is how it works now! Upon device connection only EP0 is allocated, which must be present for successful device enumeration. After that, the application is responsible for selection which USB functions from the composite device (that is which USB interface and endpoints) it wants to use, only those are allocated.
With the Beta USB-Hub support would it be possible to just read the VID/PID + serial from a large number (20 devices total ie. HUBs connected to HUB with multiple devices in each) of connected USB devices (Phones in this case) and detect insertion/removal
This should be possible, although we haven't tested with 20 devices. The nested HUBs work fine in our initial tests. The Beta support would mean here, that if you unplug too many devices and/or HUBs at the same time, we occasionally see crashes.

We aim to prepare a beta branch for public testing within a week
Thank you for your answer.
Actually, I'm developing on esp-iot-bridge framework and I want to access hubs and devices through wifi using a wireless nic example, is it possible to integrate it inside? if so, how?

Who is online

Users browsing this forum: No registered users and 43 guests