Teensy LC serial buffer resize

Status
Not open for further replies.

lampbus

New member
Hi,
I am building a chain of 11 TeensyLC units connected by hardwareserial.

I would like to blast packets of 270 bytes of data from one to the next, and this would be a bit easier to make work if the buffers were at least that size, so I can let the hardware transfer out & in the packets, then process them in the code (that is also doing other things).

I have found several people describing how to change the Arduino core code to achieve larger buffers, but I am a bit lost with the TeensyLC, as it dosen't directly have a HardwareSerial.cpp in the cores.teensy3 dir, and the hardwareserial1.cpp (etc) only contains :
Code:
#include "HardwareSerial.h"

HardwareSerial Serial1;

void serialEvent1() __attribute__((weak));
void serialEvent1() {}

Which actual hardwareserial.cpp code is actually used ?

The one in cores.teensy can be modified up to buffer size 256, due to the uint8_t indexing.
The one in the arduino 1.6.3 I have installed seems to allow buffers larger than 256 bytes as it has 16 bit var alternative defines in the .h :

Code:
#if (SERIAL_TX_BUFFER_SIZE>256)
typedef uint16_t tx_buffer_index_t;
#else
typedef uint8_t tx_buffer_index_t;
#endif
#

(ps, all the teensy lc (and 3.1) stuff is also in a subdir 'avr' which is slightly non-intuitive as they are Arm)

Thanks if you can help...I am new to all this having come from PIC and MeLabs PBP compiler.
 
Lots of people have made this buffer size mod on Teensy 3.1, which uses the same code.

So far, there haven't been many confirmed cases of doing it on Teensy-LC, so I hope you'll post a followup with your results.
 
I had a question I looked up - this change would need to be made in (hardware\teensy\avr\cores\teensy3\)serial[1,2,3].c as fitting the use case - looks like the right answer.

I assume these buffers are taken byte for byte from RAM - per active serial port? And the port #2&#3 has '#define TX_BUFFER_SIZE 40' not 64 like the other buffers for #1&2&3

I find this line #85 in the Serial#.c files that suggest only one 8 byte fifo UART - I suppose that is a holdover from T_3.0 unit?
// UART0 has 8 byte fifo, UART1 and UART2 have 1 byte buffer

Looking at http://www.pjrc.com/teensy/teensy31.html says the T_3.1 has two FIFOs - Are there no FIFOs on the LC as this shows?
http://www.pjrc.com/teensy/teensyLC.html

And semi unrelated - USB (serial) - transmits up to 64 bytes per packet - I saw as I looked this was noted on PJRC.com - so lots of small prints make more waste in packet overhead.
 
Yes, that comment in the code is old info when Teensy 3.0 was the only targeted hardware.

On the USB side, yes the USB uses 64 byte packets. The code combines small writes to fill up the packets. Doing lots of small writes does use more CPU time to combine the data into the packets, but the code is very good at efficiently packing data to maximize USB bandwidth. There is a timeout and a send_now() function to force sending a partial packet. But other than those cases, you don't need to worry about poor bandwidth usage of packets... at least on the Teensy side.

However, Windows and Linux are very poor at this. Only Macintosh combines small writes to efficiently use USB bandwidth. So on the PC side, large writes are essential if you want to efficiently send data to a Teensy. Here's some benchmarking I did a couple years ago. Scroll down to "Operating System Differences".

http://www.pjrc.com/teensy/benchmark_usb_serial_receive.html
 
looking AT : Serial1.availableForWrite()
I wonder if that changed to: serial_write_buffer_free

This name was chosen by the Arduino Team after a very long and exhausting public debate. It had many other names at various times. I tried on-and-off for 2+ years to get them to accept this seemingly very simple feature as an official part of Arduino, and every time it got bogged down in endless debate, usually over the name. Finally, "availableForWrite" was accepted as an official and permanent part of Arduino's official API.

Internally, much of Teensyduino's code is pure C, with thin C++ wrappers. The idea is to (hopefully) help people who wish to use only C. But that seems to be less and less important as time goes on....
 
Got it - I find HardwareSerial.h does the mapping for serial and serial2,serial3:
virtual int availableForWrite(void) { return serial_write_buffer_free(); }
 
:(
Internally, much of Teensyduino's code is pure C, with thin C++ wrappers. The idea is to (hopefully) help people who wish to use only C. But that seems to be less and less important as time goes on....

Well, I ONLY use pure C-code, so most of Paul's libraries are useful for me
 
Status
Not open for further replies.
Back
Top