Saturday, August 15, 2009

Why is my USB 2.x product so slow

USB stands for Universal Serial Bus. It was conceived by the USB-IF consortium. It was intended as a replacement for the venerable RS-232 port. It was designed to be faster, but sometimes this does not happen.


Even with USB 2.x, which has a 480 Mb/s reported speed, implementers are often surprised that their data throughput is actually slower than RS-232 or even the parallel port. How could this happen?


The reason this can happen is poor utilization of the USB transfer protocol. There are two main data transfer types in USB, isochronous and bulk. The isochronous transfer can achieve the 480 Mbps rate, but this comes at a cost. The isochronous primary emphasis is speed. In order to achieve this data rate, the isochronous protocol makes no guarantees about the data arriving in order, no guarantees of data arriving without errors, and no guarantees about the data arriving at all.


USB bulk transfers are exact opposite. It is important that data arrive as sent and in order sent. In order to achieve this, USB bulk transfers add overhead but this reduces throughput. Let's run the numbers:


Theoretical maximum throughput of USB 2.x for bulk transfers:

480 Mbs = 480 Mb / s = 480 Megabits / second = 503 316 480 bits/seconds



Time in USB 2.x

1 frame = 1 ms

1 uframe = 125 us

8000 uframes / 1 second



Max data payload size of bulk usb 2.x transfer = 512 bytes



Max bytes per frame(Table 5-10, USB 2.0 spec) = 6665

6665 bytes / uframe * 8000 uframes / s = 53248000 bytes / s = 406.2 Mb/s



406.2 Mb/s is fast but this can only be approached if the USB 2.x bulk transfer is used efficiently.


Tips on reaching the max limit of the USB 2.x bulk transfer protocol

  1. Minimize the amount of reading and writing of data. If possible, let data only transfer in one direction. USB 2.x is a half-duplex protocol.
  2. As much as possible, fill the entire transfer to its maximum data payload size of 512 bytes.
  3. Directly connect the USB 2.x peripheral to the host PC's hub.

No comments: