Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: Inreasing USB-Serial-Buffer Teensy 3.2

  1. #1
    Junior Member
    Join Date
    Mar 2018
    Posts
    19

    Inreasing USB-Serial-Buffer Teensy 3.2

    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.

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    18,975
    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/benchmar...l_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.

  3. #3
    Junior Member
    Join Date
    Mar 2018
    Posts
    19
    Quote Originally Posted by PaulStoffregen View Post
    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/benchmar...l_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?

  4. #4
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    18,975
    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".

  5. #5
    Junior Member
    Join Date
    Mar 2018
    Posts
    19
    Ok, Thank You.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •