Skip to content

SPI.h and Wire.h occupy twice as much RAM on 324PB than on other AVRs #133

@MCUdude

Description

@MCUdude

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions