Where to modify the RX buffer size of Serial1

I test the MKR Zero by the function Serial1.availbleForWrite() and Serial1.available(), and found that the rx and tx buffer size are all equal to 256.

According to some idea that the parameter to modify the buffer size is:
SERIAL_TX_BUFFER_SIZE
SERIAL_RX_BUFFER_SIZE

I used two way to modify the parameters:

  1. Define them in my sketch at the most beginning. I used the following to define:
    #define SERIAL_RX_BUFFER_SIZE 64
    or
    #define SERIAL1_RX_BUFFER_SIZE 64
    But they did not change

2.Search the filename HardwareSerial.h to see if such SERIAL_RX_BUFFER_SIZE is defined to 256, but they are all 64 since the memory is greater than 1023.
the directory is:
...\ArduinoData\packages\arduino\hardware\avr\1.8.5\cores\arduino
...\ArduinoData\packages\arduino\hardware\samd\1.8.12\cores\arduino\api\deprecated
...\ArduinoData\packages\arduino\hardware\samd\1.8.12\cores\arduino\api
\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino
...\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.8.3\cores\arduino

but they are all defined to 64.

So, anybody help me to change the MKR ZERO's rx and tx buffer size of Serial1

The first option should work I think. See lines 42 and 49 below.

SERIAL1_RX_BUFFER_SIZE does not seem to appear anywhere in the core code.

I don't know the answer to your question... but why do you need to increase the buffer size? I've always found it better to process the buffer a byte at a time as soon as they arrive, so that it never fills up.

if I understood OP right, he try to decrease the buffer.... from 256 to 64 ... but why? - it is a question.

Ah yes... I think you are correct. Maybe trying to save memory?

just testing. I want to change RX buffer to 2048, for other op takes lots of time and I found something is missing.

After defined SERIAL_TX_BUFFER_SIZE, the return of Serial1.availbleForWrite() did not changed.

Just found the topic

Maybe it answer my question. I will try next week.

My goal is to receive one line, send it to ethernet and write to SD.
Sometimes it takes a long time to do something, and the buffer is full.
So I tried to enlarge the RX buffer to see if it works.

Somehow, I doubt that "send it to ethernet" and/or "write to SD" take too long(unless your serial source is way too "talkative", in which case I'd lower it's baud rate or in some other way change how often it talks at you); the problem likely lies in how you are doing those things, and other things, that results in the buffer filling. Rather than consume more memory with longer buffers, I'd suggest analyzing your code to find efficiencies/remove bottlenecks there.
C

The serial source is actually talkative, and it runs under baudrate=38400.
sometimes write to SD or the op of connect to Ethernet takes a long time, and all of these op are standander functions, I don't want to modify them. So the way to solve this problem is to enlarge the RX buffer size to avoid missing the input char.

It is possible to use a buffer ring or queue, in which you can store your data and process later.

It should be in ...packages/arduino/hardware/samd/1.8.12/cores/arduino/Uart.h

great! Thanks

I read the doc just now, found that is a very useful lib RingBuffer. It can not solve my problem, but I would use it in other sketch.

You can use that or make your own, then you don't need to modify the serial buffer.

Yes, it is. and I found that the buffer is using SafeRingBufferN, where rx and tx buffer are using the same size SERIAL_BUFFER_SIZE,
finally I set the rx buffer to 1024 and tx buffer to 128.
Thanks a lot!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.