-
Notifications
You must be signed in to change notification settings - Fork 184
Closed
Labels
Description
ATmega324PB has two i2c and SPI ports. I've made it so that Wire1.h and SPI1.h is automatically included when Wire.h or SPI.h is included (because it's convenient). A downside of this is the memory usage.
Unlike the (included) HardwareSerial library, Wire and SPI occupies memory even though their begin() routines isn't even called. I think the large memory usage is because all buffers and variables is included by the compiler.
Does anybody know how we can prevent the SPI and Wire libraries to be included by the compiler when their begin methods isn't called? At least this is how HardwareSerial.h works.
The outcome of this issue will also affect how these libraries work with ATmega328PB as well.
#include <Wire.h>
void setup() { }
void loop() { }
Target (LTO disabled) | Blank sketch | Blank sketch with Wire.h included |
---|---|---|
ATmega324P | Flash: 470 bytes / RAM: 9 bytes | Flash: 1540 bytes / RAM: 216 bytes |
ATmega324PB | Flash: 602 bytes / RAM: 9 bytes | Flash: 2686 bytes / RAM: 423 bytes |