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

Thread: Teensy 3.6 Serial Buffer

  1. #1
    Junior Member
    Join Date
    Oct 2016
    Posts
    4

    Teensy 3.6 Serial Buffer

    Hi,

    I wonder if anyone could offer some advice. I've just started playing with the Teensy 3.6 and was trying to increase the buffer size for Serial1. Having looked at previous posts I see that Serial1.c is the file to edit. However having altered the RX_BUFFER_SIZE several times with larger values each time there seems to be no difference in the amount of memory the sketch uses. To test this I opened up a new sketch as follows (with no added code):

    void setup() {
    // put your setup code here, to run once:

    }

    void loop() {
    // put your main code here, to run repeatedly:

    }


    Setting RX_BUFFER_SIZE in Serial1.c to any size for example 64 or 64000 the sketch compiles as follows:
    Sketch uses 20,592 bytes (1%) of program storage space. Maximum is 1,048,576 bytes.
    Global variables use 3,968 bytes (1%) of dynamic memory, leaving 258,176 bytes for local variables. Maximum is 262,144 bytes.


    However if I edit Serial3.c and change RX_BUFFER_SIZE to 64000 the sketch compiles as follows:
    Sketch uses 20,600 bytes (1%) of program storage space. Maximum is 1,048,576 bytes.
    Global variables use 67,904 bytes (25%) of dynamic memory, leaving 194,240 bytes for local variables. Maximum is 262,144 bytes.

    Does the value of RX_BUFFER_SIZE in Serial3.c overwrite the values in Serial1.c or am I doing something wrong.


    Thanks in advance.

  2. #2
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,220
    Just a guess, but perhaps the Serial1 stuff isn't being loaded because you aren't referencing it (although I don't know why Serial3 would load).
    Try adding a Serial1.begin(9600); in the setup() function.

    Pete

  3. #3
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    10,602
    Paul has noted that Serial RAM buffers are always allocated. As was seen for Serial3. Perhaps double check that you edited the Serial1.c file in the correct location and saved the edit. Each Serial# file appears to have a local copy of the #define xx_BUFFER_SIZE's.

  4. #4
    Junior Member
    Join Date
    Oct 2016
    Posts
    4
    Hi Pete,

    In my original sketch I had references to Serial1 and that made no difference. I also tried your suggestion and again there is no difference to the size of the sketch when editing Serial1.c.

    Thanks.

  5. #5
    Junior Member
    Join Date
    Oct 2016
    Posts
    4
    Hi defragster,

    Serial1.c and Serial3.c are both located in the following folder on my PC: C:\Program Files (x86)\Arduino\hardware\teensy\avr\cores\teensy3

    I've just tried editing Serial1.c again as follows (I've used a high value to see if it would fail to compile):

    #define TX_BUFFER_SIZE 64 // number of outgoing bytes to buffer
    #define RX_BUFFER_SIZE 6400000 // number of incoming bytes to buffer
    #define RTS_HIGH_WATERMARK 40 // RTS requests sender to pause
    #define RTS_LOW_WATERMARK 26 // RTS allows sender to resume
    #define IRQ_PRIORITY 64 // 0 = highest priority, 255 = lowest


    But this made no difference and still compiles.

    Thanks.

  6. #6
    Senior Member
    Join Date
    Jan 2013
    Posts
    843
    Changing TX_BUFFER_SIZE / RX_BUFFER_SIZE works for me. If I use your 6400000 buffer value, I get a link error: 'region `RAM' overflowed by 6143880 bytes'.

    There is no 'Serial1.c', there is 'serial1.c'.

    Enable verbose compiler output and make sure that the file you edited actually gets compiled.

  7. #7
    Junior Member
    Join Date
    Oct 2016
    Posts
    4
    Hi tni,

    Thanks for the reply. I've just reinstalled the IDE/Teensy software (which I should have tried at the start) and all is fine now.

    Thanks all for the replies/suggestions.

  8. #8
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,332
    Quote Originally Posted by BobNoHope View Post
    #define RX_BUFFER_SIZE 6400000 // number of incoming bytes to buffer
    Even though Teensy 3.6 has 256K of RAM, due to the use of 16 bit index variables in the code, this buffer can not be larger than 64K.

  9. #9
    Member educa's Avatar
    Join Date
    Jan 2017
    Location
    Belgium
    Posts
    21
    Just to be sure I understand correctly. That serial buffer talked about above is a ram buffer which is filled by serial interrupts, but is there also some kind of HARDWARE serial buffer built in in the main CPU on the teensy3.6 ?

  10. #10
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,332
    Quote Originally Posted by educa View Post
    but is there also some kind of HARDWARE serial buffer built in in the main CPU on the teensy3.6 ?
    Yes, there is also an 8 byte FIFOs (hardware buffer) on Serial1 and Serial2, which allows more interrupt latency and fewer interrupts for CPU overhead during sustained data flow.

    Serial3, Serial4, Serial5 and Serial6 do not have the FIFOs.

  11. #11
    Member educa's Avatar
    Join Date
    Jan 2017
    Location
    Belgium
    Posts
    21
    Note to self. (and whoever makes the same wrong guess like I did ). Serial communication using the NATIVE usb port on the teensy is something completely different with native usb at 12MBps speed and a buffer for 2 usb packets of each 64 bytes

    https://www.pjrc.com/teensy/td_serial.html
    Last edited by educa; 01-22-2017 at 10:56 PM.

  12. #12
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    21,332
    Yes, indeed USB serial is a completely different protocol.

    Some of that info was written in the days before Teensy 3.x. It's still mostly accurate, except the new boards are able to buffer much more than 2 packets.

  13. #13
    Senior Member
    Join Date
    Jun 2015
    Posts
    132
    Is it possible to increase the native serial(usb) rx buffer size from 64 to say 256? (ie Serial. )

    Regards
    Russell

  14. #14
    I am really suffering here, spend last 3 hours trying to figure out where are the files that can be edited. I want to activate 9bit for serial for teensy 3.6. Editing HardwareSerial.h does not work. What should I edit and where is it located in Mac?

    Edit:

    Finally I found it. On Mac the files that need to be edited are not to be found with the find functionality, they are located under the Arduino icon, right click and select 'Show package content'

    The path is strange I think: Contents/Java/Hardware/Teensy/Avr/Cores/Teensy3/HardwareSerial.h .

    It only took me 4 hours to figure this out, Hopefully it helps someone.
    Last edited by Garug; 08-20-2017 at 08:33 PM.

Posting Permissions

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