Skip to content

RX and TX Buffers for HardwareSerial are hard coded in size and equal length #1929

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jantje opened this issue Mar 12, 2014 · 9 comments
Closed

Comments

@jantje
Copy link

jantje commented Mar 12, 2014

Hi
I have many arduino sketches that send out lots of data and hardly receives any data.
I really would like to increase the TX buffer but not the RX buffer. Therefore I would like to modify the HardwareSerial class where it states:

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

to

#if !(defined(SERIAL_TX_BUFFER_SIZE)&&defined(SERIAL_RX_BUFFER_SIZE))
#if (RAMEND < 1000)
#define SERIAL_TX_BUFFER_SIZE 16 
#define SERIAL_RX_BUFFER_SIZE 16 
#else
#if ARDUINO_AVR_MEGA2560
#define SERIAL_TX_BUFFER_SIZE 64 
#define SERIAL_RX_BUFFER_SIZE 64 
#else
#define SERIAL_TX_BUFFER_SIZE 64 
#define SERIAL_RX_BUFFER_SIZE 64 
#endif
#endif

this allows to change the size by using a define and allows for different sizes for RX and TX buffer.
and make all subsequent changes.
Would a change like this be accepted?
jantje

@jantje
Copy link
Author

jantje commented Mar 13, 2014

due to #1870 and #1856 sizes bigger than 255 have no use.
I remember having seen a issue about the memory usage of the serial buffers when not used (I know they take memory when not used due to the extern declaration) if that issue is fixed maybe it is smarter to change the buffersize on the mega to a default of bigger than 64?

@jantje
Copy link
Author

jantje commented Apr 15, 2014

as fixed in #1955

@jantje jantje closed this as completed Apr 15, 2014
@mrts
Copy link

mrts commented Mar 22, 2015

@jantje But how do you actually use it with Arduino IDE? Would

#define SERIAL_TX_BUFFER_SIZE 32
#include <Arduino.h>

at the top of a .ino file work (I doubt as AFAIK Arduino.h is implicitly included)?

@matthijskooijman
Copy link
Collaborator

@mrts, that won't work, since those defines will not be in effect when HardwareSerial0.cpp, which defines the actual buffers, is compiled. I think the way to do this right now, is to modify HardwareSerial.h.

@mrts
Copy link

mrts commented Mar 22, 2015

@jantje, right, that's what I expected. Thanks for clarifying!

@jantje
Copy link
Author

jantje commented Mar 22, 2015

you can also modify platform.txt or boards.txt
It may be a good idea to make a "big buffer" board.

@mrts
Copy link

mrts commented Mar 27, 2015

Thanks for the tip!

@PaulStoffregen
Copy link
Contributor

You can also create a menu using boards.txt, with each option in the menu passing different -Dxyz flags to the compiler.

@YsHoang
Copy link

YsHoang commented Dec 14, 2015

How i can change buffer of arduino due?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants