Repository navigation
fix(avr): link Arduino Serial only when a sketch uses it (Fixes #4725) - #4730
Conversation
FastLED's Arduino I/O shims sit in the always-linked platforms+ unity object. Their strong references to Serial (and, on ATTinyCore, to TinySoftwareSerial methods defined next to it) pulled the core's Serial object, ring buffers and USART ISRs into every AVR sketch. On AVR the shims now reference Serial weakly and call it through an opaque Stream&, so no devirtualized direct references remain. fl::serial_begin() and fl::SerialPort::begin() are header-inline on AVR, so their strong reference lands in the caller's object: sketches that begin a port (Arduino Serial or fl::serial_begin) still print. Tighten uno max_size_apa102 9300 -> 8500 (Apa102 4510 -> 3682 B). Co-Authored-By: Claude <[email protected]>
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configuration
📒 Files selected for processing (4)
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (8)
💤 Files with no reviewable changes (1)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review. 📝 WalkthroughWalkthroughAVR Arduino serial setup and access now use conditional inline definitions and a weakly linked stream. The Uno Apa102 size threshold changes from 9300 to 8500, and the threshold checker and size history reflect that change. ChangesAVR serial setup and stream access
Uno Apa102 size threshold
Priority: ➖ Normal Estimated code review effort: 3 (Moderate) | ~20 minutes Change: Bug fix · Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to No actionable issue remains from this review. The change is ready to merge after normal checks. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Full details: Docstring CoverageExplanation Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 5 files. (2 skipped: 2 unsupported.)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Fixes #4725 (part of #4728).
Root cause
platforms/avr/io_avr.cpp.hppincludesplatforms/arduino/io_arduino.hpp, so FastLED'sprint/available/read/... shims live in theplatforms+unity object that every sketch links. Their strong references toSerialpulledHardwareSerial0.cpp.o(uno) orTinySoftwareSerial.cpp.o(ATtiny) out of the core archive before LTO ran. That brought in the Serial object, its ring buffers, and the USART ISRs that keep them alive. On ATTinyCore, GCC also devirtualizedSerial.available()etc. into direct calls toTinySoftwareSerial::*, which live in the same archive member.Fix
#pragma weak Serialinio_arduino.hpp. Each shim checks&Serial != 0and calls through an opaqueStream&(an empty asm hides the dynamic type, so the calls stay virtual).fl::serial_begin()(AVR+Arduino) andfl::SerialPort::begin()are now header-inline. Their strongSerialreference lands in the caller's object, so a sketch that callsfl::serial_begin()still links Serial and prints. A sketch that callsSerial.begin()does too.max_size_apa102goes from 9300 to 8500 (claimed savings), and the frozen list andSIZE_THRESHOLD_HISTORY.mdare updated to match.Before / after (flash / RAM bytes)
Uno Blink RAM delta, 3.10.3 to master (symbol diff, bloat report)
str1.1+187: Blink's banner literals in.data(example, by design)Serial+157 andvtable for HardwareSerial+18: Blink callsSerial.begin(example, by design; library-side zero-cost now)addLeds<NEOPIXEL>controller 24 → 89 (+65) and guard ±0gControllersData16 → 32 (+16)timer_millis+4,sWaitSpinBudgetUs+4,FastLED+2, small renames ±0Evidence that printing still works
fl::serial_begin(115200); fl::println("probe-4725");linksHardwareSerial0, and the string is in the ELF (6786 / 657).Serial.begin(9600); fl::println(...)linksTinySoftwareSerial,Print::write, and the string.bash test --cpp: 317/317 unit and 95/95 examples pass.bash lintis clean.Summary by CodeRabbit