How to properly send bulk packets from vendor device greater than 64 bytes #3053
Replies: 2 comments 3 replies
-
Okay I've partially answered my question. In my application, I'm using a vendor device to emulate and existing hardware device. This device prefixes every message with 2 status bytes, so each data packet is 62 bytes. In all my examples, I was sending this 64 byte packet with 2 prefix and 62 data bytes. TinyUSB then was automatically sending a ZLP, because that's the typical behavior when trying to flush the full buffer. This was breaking how a lot of software parsed incoming data from these devices, making it seem like the firmware was the issue. Writing 1 less data byte and then calling the flush function made this work. I also discovered how to properly increase the buffer size itself. Previously, when I increased the TX buffer size for tinyusb (that's used for the FIFO, not the hardware packet size of USB high speed obviously), I must have not been flushing properly, because in wireshark I was seeing these really slow, big chunks come in. Now, I can write all 500-600 bytes into tinyusb in one write, then flush it one time, which sends out X 64-byte high speed packets seen in wireshark. I have everything working with most parsing software, the most basic being |
Beta Was this translation helpful? Give feedback.
-
Hi @second-string In all of my attempts, the data that comes back (viewed in Wireshark) is completely broken, like the packets are too long/too short, or the data is mixed up between packets (e.g. the 2 status bytes land in the middle of a packet. My general flow is:
As such, I have tried two different approaches, with TinyUSB's TX buffer disabled (set to 0) and enabled (set to 4096):
Consider the following code, being run in a loop with some delay in between iterations (buffer size is 4096): uint8_t packet[64];
packet[0] = 0x31;
packet[1] = 0x60;
tud_vendor_write(packet, 2);
tud_vendor_write_flush(); which yields the following result: Have you found a way to make this work properly? It seems like sending the data without a buffer could be a way to go, but I just couldn't figure out the right way to do it yet. Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm trying to send 500-600 bytes from my custom vendor device back to the host machine, but I can't figure out how to properly chunk it out of the output endpoint. Things I've tried:
tud_vendor_write(buf, 64)
repeatedly, advancing the buf pointer each them. When full packet sent, calltud_vendor_write_flush()
tud_vendor_write(buf, 64)
and thentud_vendor_write_flush()
for every 64 byte chunk until entire packet is donetud_vendor_write(buf, 500)
and thentud_vendor_write_flush()
.while (tud_vendor_write_available() == 0) {}
before callingtud_vendor_write(buf, 64)
andtud_vendor_write_flush()
. But this spins forever and never exits that while loop because it always returns 0None of these are working properly when viewed with Wireshark on the receiving host. Am I supposed to increase the size of the TX FIFO by overriding the default
CFG_TUD_VENDOR_TX_BUFSIZE
of 64 to a higher value? Or am I somehow chunking this data out incorrectly? I feel like I'm missing something simple.Also probably worth noting that all of my calls to
tud_vendor_write
andtud_vendor_write_flush
always return zero, even though this behaviour is all working as expected for packets < 64 bytes length.Beta Was this translation helpful? Give feedback.
All reactions