Inreasing USB-Serial-Buffer Teensy 3.2

Status
Not open for further replies.

WS2812B

Member
How the title already suggests, I want to increase the size of the USB-Serial-Buffer of a Teensy 3.2.

I already found threads, in which the hardware UART-Buffers were possible to increase but is it also possible to increase the USB-Buffer?
And if yes, how?

Am I correct that the default size is 64 bytes?

I am aiming to arround 1024 bytes or bigger.
 
Yes. Just edit usb_desc.h. Look for this line:

Code:
  #define NUM_USB_BUFFERS       12

Don't go over 31. The memory management uses a bitmask, which imposes an upper limit.

Each buffer is 64 bytes, which corresponds to the USB full speed maximum packet size. You can't increase the packets beyond 64 bytes, because that is built into the USB protocol and USB hardware on both Teensy and your PC.

Now, having (hopefully) answered your question, I'd like to mention the fact that USB is complicated. It has true end-to-end flow control baked into the protocol at a fairly low level. Optimizing performance can be tricky. Simple techniques like bigger buffers, which often work well for simpler protocols, don't always give the desired results with USB. Often the best ways to optimize aren't obvious, and they almost always require carefully considering the application on both sides of the USB cable (which we know nothing about from your short question).

Here's some benchmarking that was done several years ago when Teensy 3.0 was the highest Teensy model.

https://www.pjrc.com/teensy/benchmark_usb_serial_receive.html

Hopefully you can see from these results that performance tends to vary quite a lot. The theoretically fastest hardware (in that old test, Arduino Due) can perform poorly when the code isn't carefully optimized, and the slowest hardware (Teensy 2.0 & Arduino Leonardo) can either be slow or quite fast. Careful code optimization is by far the most critical factor to USB performance. It's not like simpler protocols.
 
Yes. Just edit usb_desc.h. Look for this line:

Code:
  #define NUM_USB_BUFFERS       12

Don't go over 31. The memory management uses a bitmask, which imposes an upper limit.

Each buffer is 64 bytes, which corresponds to the USB full speed maximum packet size. You can't increase the packets beyond 64 bytes, because that is built into the USB protocol and USB hardware on both Teensy and your PC.

Now, having (hopefully) answered your question, I'd like to mention the fact that USB is complicated. It has true end-to-end flow control baked into the protocol at a fairly low level. Optimizing performance can be tricky. Simple techniques like bigger buffers, which often work well for simpler protocols, don't always give the desired results with USB. Often the best ways to optimize aren't obvious, and they almost always require carefully considering the application on both sides of the USB cable (which we know nothing about from your short question).

Here's some benchmarking that was done several years ago when Teensy 3.0 was the highest Teensy model.

https://www.pjrc.com/teensy/benchmark_usb_serial_receive.html

Hopefully you can see from these results that performance tends to vary quite a lot. The theoretically fastest hardware (in that old test, Arduino Due) can perform poorly when the code isn't carefully optimized, and the slowest hardware (Teensy 2.0 & Arduino Leonardo) can either be slow or quite fast. Careful code optimization is by far the most critical factor to USB performance. It's not like simpler protocols.

You answered my question, Thank You.

The application for the buffer is not that performance/speed-dependent. The USB is only used for a simple console-based MMI (ManMachineInterface).

Just to be sure: I am correct, that this line with
#define NUM_USB_BUFFERS 12
results in a buffer size of 12 * 64 = 768 bytes?
 
When you edit the code, pay attention of the memory usage summary Arduino shows when you compile.


Just to be sure: I am correct, that this line with
#define NUM_USB_BUFFERS 12
results in a buffer size of 12 * 64 = 768 bytes?

Yes, sort of. The buffers are shared for transmit and receive, and the driver on your PC side may not fully utilize max size packets, so the end result is "it depends".
 
Status
Not open for further replies.
Back
Top