Go Down

Topic: Lady Ada's "save some memory" Serial hack (Read 431 times) previous topic - next topic

halley


On Lady Ada's site, there is a recommendation for her Wave Shield and GPS Shield libraries to hack your individual copy of a standard Serial library file (I think it's wiring_serial.c), to edit the size of the serial receive buffer.

The recommendation is, if you need RAM and use little PC->AVR traffic, to reduce the buffer from:

Code: [Select]

#define RX_BUFFER_SIZE 128


to a lower positive number:

Code: [Select]

#define RX_BUFFER_SIZE [glow]16[/glow]


I would recommend the standard header offer this choice without having to edit the header directly.

Code: [Select]

[glow]#ifndef RX_BUFFER_SIZE[/glow]
#define RX_BUFFER_SIZE 128
[glow]#endif[/glow]


Then a user could override the default big buffer in their sketch:

Code: [Select]

#define RX_BUFFER_SIZE 16
#include <Serial.h>


This would let you build different sketches with different serial buffer sizes easily, since the Arduino IDE is compiling the "library" multiple times anyway.

The only problem with this scheme is that the Arduino sketch IDE kind of hides this by not actually requiring an #include for the standard stuff like the Serial class.

Comments?


westfw

Quote
The only problem with this scheme is that the Arduino sketch IDE kind of hides this by not actually requiring an #include for the standard stuff like the Serial class.

It's worse than that.  The serial code (and buffer) is part of the wiring library, so #defines in a sketch (which are local to a source-level .c file) wouldn't have any effect on them.

How about allowing a "wiring-options.h" as part of a sketch (In the sketch directory).  If it existed, it would be forced-inlcuded in the builds of the wiring code...  I think that would be pretty easy to implement.

westfw

I have submitted a patch that implements the "wiring_options.h" idea to the developers mailing list.

Go Up