drivers: usb: stm32: usb_write size on bulk transfer problematic #49017
-
Describe the bug
Notice: The packets seem to arrive to the host, but don't get detected, till one of those two options happen. Expected behavior Impact Environment (please complete the following information):
Additional context |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 2 replies
-
@JonathanVanWin, thanks for raising the point, but if Zephyr driver is not guilty can you please raise the point directly to https://github.com/STMicroelectronics/STM32CubeF4 ? Thanks |
Beta Was this translation helpful? Give feedback.
-
Hi @erwango, it seems that in order to solve the bug, the hal should take care of transfers that don't finish with a short packet, send a Zero length packet.
|
Beta Was this translation helpful? Give feedback.
-
I agree that the end of transfer is signaled from the the device side by a packet shorter than wMaxPacketSize. That said I disagree that it should be done in the HAL (or if so it should be made optional as you might want to do bulk transfers bigger than the RAM buffers). IMHO this is the responsibility of the application, which is the only one to know if the current data being sent is part of a bigger transfer or not. At least this is how this is done in Zephyr where Note that the CDC ACM case is a bit tricky as a ZLP packet is interpreted by some host OS as the end of the transmission. That's why Zephyr prefer to send a short packet followed by another short packet instead of a ZLP for this class.
OS behaves differently on that aspect, but basically you can't expect bulk transfers to be received continuously on the host side. From the application point of view the way the data of a bulk transfer is chunked physically doesn't matter, so the data is usually passed to the application when the transfer is complete (i.e. the request size is reached or a short packet or a ZLP is received). You should either split those transfers in smaller ones (possibly sending a short packet or a ZLP) or look at interrupt or isochronous endpoint depending on your application. |
Beta Was this translation helpful? Give feedback.
-
From the above quoted, what makes you think that a bulk transfer consisting of multiples of endpoint MPS, should always be terminated with a ZLP? And that this is always interpreted as successful? It depends on your host application, and there are applications that simply expect a stream (without ZLP in between). Unfortunately, you do not tell us how your host application does USB requests and neither what you use on Zephyr side (usb_write(), usb_transfer()). IMO this should be converted to a discussion. |
Beta Was this translation helpful? Give feedback.
-
Converting to discussion |
Beta Was this translation helpful? Give feedback.
I agree that the end of transfer is signaled from the the device side by a packet shorter than wMaxPacketSize. That said I disagree that it should be done in the HAL (or if so it should be made optional as you might want to do bulk transfers bigger than the RAM buffers). IMHO this is the responsibility of the application, which is the only one to know if the current data being sent is part of a bigger transfer or not. At least this is how this is done in Zephyr where
usb_transfer()
send send a ZLP by default if needed, but has theUSB_TRANS_NO_ZLP