Pages: [1]   Go Down
Author Topic: Lady Ada's "save some memory" Serial hack  (Read 409 times)
0 Members and 1 Guest are viewing this topic.
Connecticut, US
Offline Offline
Edison Member
*
Karma: 2
Posts: 1036
Whatduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


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:
#define RX_BUFFER_SIZE 128

to a lower positive number:

Code:
#define RX_BUFFER_SIZE [glow]16[/glow]

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

Code:
[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:
#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?
Logged

Raleigh, NC
Offline Offline
Jr. Member
**
Karma: 0
Posts: 75
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Agreed!
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 134
Posts: 6762
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

SF Bay Area (USA)
Offline Offline
Tesla Member
***
Karma: 134
Posts: 6762
Strongly opinionated, but not official!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Pages: [1]   Go Up
Jump to: