You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AVR: Arduino Serial (HardwareSerial / TinySoftwareSerial) always linked, ~175 B RAM + ~1 KB flash on Uno #4725
An Uno or ATtiny85 sketch that never touches Serial links Arduino's HardwareSerial (TinySoftwareSerial on ATtiny) anyway. Measured on master 7ac9a83c6e against 3.10.3 (both built with today's fbuild):
board / example
3.10.3 flash / RAM
master flash / RAM
RAM from Serial
uno / Apa102
3178 / 187
4510 / 501
Serial 157 B + vtable 18 B, plus about 1 KB of HardwareSerial::* code and the USART ISRs __vector_18/__vector_19
attiny85 / Blink
3338 / 131
3132 / 233
Serial 18 B + rx_buffer 36 B + vtable 16 B
On a 2 KB (Uno) or 512 B (ATtiny85) part, that is a real cost.
Cause
In 3.10.3, src/platforms/avr/io_avr.h wrote the UART registers directly. Since 9c8d5b1830 ("refactor io, platforms namespace, unity build"), platforms/avr/io_avr.cpp.hpp includes platforms/arduino/io_arduino.hpp, whose fl::platforms::print/println/available/read/... reference Serial. All of it sits in the platforms+ unity object, which every sketch links. The linker map shows:
libframework.a(HardwareSerial0.cpp.o)
platforms+_069c.cpp.o (symbol from plugin) (Serial)
The archive member gets pulled before LTO/gc runs. Once it is in, its USART ISRs keep Serial alive. No FastLED code calls it at runtime: the only references in the final image come from the core's serialEventRun and the ISRs.
Why this isn't a one-line fix
A weak extern HardwareSerial Serial would drop the object, but then fl::print would print nothing in any sketch that calls fl::begin() without touching Serial itself. That changes behaviour.
Possible ways forward: (a) bring back the 3.10.3 direct-register UART path for AVR, (b) move the Arduino Serial shims into their own non-unity object so they only link when called, (c) route through a function pointer that fl::begin() installs.
Activity
fix(avr): link Arduino Serial only when a sketch uses it (#4725) (#4730)