Is USB control transfers used for anything else ? - Page 1
Forum section: electronics / projects

author: metebalci
author_rank: Frequent Contributor
timestamp: December 01, 2023, 02:13:07 pm
content: For a request-response type communication (not time sensitive etc.), I guess both control and bulk transfers can be used. I wonder if control transfers are used in actual device implementations other than the default endpoint 0, or always bulk is used since control does not probably bring something extra ?

author: ataradov
author_rank: Super Contributor
timestamp: December 01, 2023, 04:29:35 pm
content: Control transfers can only be issues to the EP0. There is no way to send them over any other endpoint and non-0 endpoints should not have control type.But the data transfer over the control endpoint is used a lot. For example DFU (firmware update) class does all its communications over the control endpoint. This allows for very small bootloaders, since all the descriptors are small and the whole bunch of code related to normal communications can be removed.

author: metebalci
author_rank: Frequent Contributor
timestamp: December 01, 2023, 04:42:21 pm
content: Thanks for mentioning DFU, I didnt know that.I believe control transfers do not need to be ep0 only, I mean at least spec does not prevent it. But not sure if it is used, how it is used etc.I think what you mean is standard requests only work in ep0, but a control transfer type ep (not sure about 0 but anything else possible) can be used for normal data transfers as well, and maybe that is what you mean these need ZLP like other transfer types bulk etc.

author: ataradov
author_rank: Super Contributor
timestamp: December 01, 2023, 04:53:00 pm
content: I don't see any specific restrictions on setting the endpoint type to Control for a non-zero endpoint, but I don't know if that will ever work in practice. I think most implementations assume that there will only be one control endpoint, and is is endpoint 0.EP0 itself can be used for general data transfer like any other endpoint.

author: ataradov
author_rank: Super Contributor
timestamp: December 01, 2023, 05:03:38 pm
content: Ok, the spec mentions in one place "For all other control endpoints.....", so I guess it is possible to have control endpoint at non-0 index. This would be pretty bizarre, I have never seen this is done and I assume you will run int all sorts of issues with support for this. Pretty much everyone assumes EP0 and only EP0 to be a control endpoint.Even looking at the libusb API, libusb_control_transfer(), which sends the SETUP-type transfer, does not take endpoint index, so you can only issue SETUP transactions to the ep0.And I don't think there is a way to generate just an IN/OUT transfer to the control endpoint not as a part of the data stage of the SETUP transfer. All APIs infer the direction from the endpoint index, but the control endpoint uses the same index for both directions and the actual direction is derived from the SETUP packet.So, it looks like even arbitrary exchange is not that easy. And this is why everyone (including DFU) uses SETUP transfers with vendor or class request types. You still get arbitrary payloads, just as a part of the data stage of the SETUP transfer. Plus you get a nice way to send additional request parameters in the fields of the setup packet.

author: metebalci
author_rank: Frequent Contributor
timestamp: December 01, 2023, 07:48:30 pm
content: Good point about libusb.So the control transfer uses so called a message pipe, whereas others use stream pipe. Message pipe implies a structure and my understanding and guess was that this structure is this setup-data-status thing. So I think any endpoint can be control transfer type (I understand it might be very uncommon and unsupported) but then they still have to use the same structure. That is actually why I asked if there is a point using this because something with similar functionality for request reply type communication can be done with bulk and I guess it is more easy to use just plain IN and OUT and app defined messages.

author: ataradov
author_rank: Super Contributor
timestamp: December 01, 2023, 07:53:12 pm
content: Yes, this seems to be the case.And yes, for sure use plain bulk endpoints for non-0 index. I would expect a nightmare of incompatibilities if you try to use control endpoint on a non-0 index.There is nothing wrong with using EP0 for general command transfer, I do it all the time. Sure, it comes as a SETUP and then IN /OUT combo, but that's not a big deal. And again, you get the added benefit of the fields in the setup data. So if you are transferring simple commands, you may not need any data payload at all.

author: SiliconWizard
author_rank: Super Contributor
timestamp: December 01, 2023, 11:21:04 pm
content: I'm sure the USB controllers of many, if not most, MCUs do not support control endpoints other than 0, so you may not have a lot of luck even trying that in practice, unless you implement your own controller or find a chip that can do that.Note that control endpoints can only transfer 64 bytes (IIRC), so if you're using that for all your data transfers on anything > USB LS or FS, you're not going to get fantastic throughput. But I guess the typical use cases do not require much, like DFU.

author: metebalci
author_rank: Frequent Contributor
timestamp: December 02, 2023, 04:35:57 am
content: Quote from: SiliconWizard on December 01, 2023, 11:21:04 pmOK I understand, I should not think about non-ep0 control transfers then.BULK in FS is also limited to 64 bytes, but I got the point.