user1842354
user1842354

Reputation: 571

When should an USB host send a Zero Length Packet (ZLP) to an OUT bulk pipe function if the host is sending a video stream

Im writing firmware for a USB 2.0 FS host that communicates with a LTE modem via bulk pipes, ppp mode. I am a bit uncertain about the use case for ZLP when the host is streaming data to the device. If i would send a file and the file size % maxPacketsize == 0, i assume that i send the ZLP after the last bytes of the file. In a condition where i am "connected" via ppp to the host and streaming data, will there ever be a need for the ZLP? Or should i send a ZLP for each ppp frame that has length % maxPaketSize == 0?

Thanks

Upvotes: 0

Views: 69

Answers (1)

Codo
Codo

Reputation: 78795

When you send data over a bulk endpoint, you have to assume that the receiver will not immediately act on the data but buffer it until either the buffer is full or it detects that the sender has no more data for the time being.

The latter one is were ZLP packets come in to play. "No more data" is indicated with a USB packet shorter than the maximum packet size declared by the endpoint.

So on a bare metal system (as opposed to a Linux, macOS, Windows system) where the application software deals with each individual USB packet, the application code is usually notified when a packet has been successfully sent and the USB peripheral is ready to accept the next packet. In such code, you should send a ZLP if the previous packet was equal to the maximum packet size and you cannot submit the next packet immediately (as no further data is ready for transmission).

On a full-blown operating system, the operating system usually takes care of this and doesn't give you control over individual USB packets.

Upvotes: 0

Related Questions