increase RX buffer for hardware Serial

hi,

I need to increase the RX buffer for my Mega2560 application from 64 to 256. In …\arduino-1.6.5-r5\hardware\arduino\avr\cores\arduino\HardwareSerial.h I found the definition

#if (RAMEND < 1000)
#define SERIAL_RX_BUFFER_SIZE 16
#else
#define SERIAL_RX_BUFFER_SIZE 64
#endif

Editing 64 to 256 is easy. But as far as I understand the code this definition is valid for all hardware UARTs. I need to increase the RX buffer only for one of the four UARTs on the Mega256 and want to avoid increasing it also when I run a sketch on an UNO which only has 2k RAM.

How can I get an increased RX buffer only for one UART on the Mega2560?

SupArdu

Okay, counter question (because of the classic XY problem here)

Why do you think you need that? Can't you just read it more often? 64 bytes is already quite lengthy for a Mega to handle!

well,

my application is using a GSM module to answer phone calls, to read/write SMS and to send data as a Webclient to a server.

The GSM module sometimes needs waiting times to wait for a response. During this waiting times phone calls and SMSs may come in which generate long strings on the serial RX, longer than 64 bytes.

I see as possible solutions: 1) slow down baud rate to 1200 or less --> everything will be slow and the question remains how slow shall be the baud rate for a reliable application, not to loose any SMS or phone call 2) write the GSM control software as a state machine avoiding waiting times with delay(..) --> it will be a very complicated software (I know that the GSM library for Arduino is a state machine. But it uses SoftwareSerial which is not suitable in my application. I tried it and had severe problems. I need an UART. In the forum you can find a lot of questions when the GSM library will be available for hardware serial. The response is: because the software is a state machine the change takes months of rework...) 3) Use an UART instead of SoftwareSerial. It seems to me the easiest way. And that is the reason for my question.

Meantimes I got an idea: If my application contains

define SERIAL_RX_BUFFER_SIZE 256

at the very beginning then this might overwrite the #define in HardwareSerial.h, and the change is valid only in the specific application, not generally.

Simply don't wait for the GSM module to transmit all the bytes. Just read it as you go. Even at 115200 baud the Arduino is able to read the Serial a couple of times per byte receive.

In other words, you don't have a problem ;) You're just making one up.

And as 3, of course you use hardware serial (uart) when you have one left. Using softwareSerial when you have free hardware serial ports is just dump...