Teensy 3.6 Serial Buffer

Status
Not open for further replies.

BobNoHope

New member
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.
 
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
 
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.
 
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.
 
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.
 
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.
 
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.
 
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 ?
 
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.
 
Note to self. (and whoever makes the same wrong guess like I did :p ). 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:
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.
 
Is it possible to increase the native serial(usb) rx buffer size from 64 to say 256? (ie Serial. )

Regards
Russell
 
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:
Status
Not open for further replies.
Back
Top