Repository navigation
Description
Summary
SAMD builds now pull in the Arduino SPI library unconditionally, via an #if 0 LDF hint in platforms/arm/samd/ldf_headers.h. That is a deliberate stopgap landed with #4011 to get the four SAMD boards compiling. It should not be the end state.
How we got here
platforms/arm/sam/fastspi_arm_sam.h does:
#if defined(FL_IS_SAMD21) || defined(FL_IS_SAMD51)
#include <SPI.h>
#include <wiring_private.h>
Neither macro ever evaluated true before #4011, because is_samd.h required ARDUINO_ARCH_SAMD — which the board manifests do not define. So the entire SAMD SPI stack has never been compiled, on any board, ever. Fixing detection switched it on and the build immediately failed:
fastspi_arm_sam.h:17:10: fatal error: SPI.h: No such file or directory
The LDF hint is the repo's existing mechanism for this, and it keeps the fix inside src/ so library consumers benefit rather than only this repo's CI matrix (the alternative, lib_deps in ci/boards.py, would have fixed CI and left every downstream user broken).
Why this is a stopgap
1. The dependency is unconditional and the cost is real. The LDF scanner does not evaluate conditionals, so the hint cannot be narrowed to "only when a SPI chipset is used". platforms/esp/32/ldf_headers.h documents exactly this failure mode for larger libraries:
PlatformIO's LDF scans
#includedirectives even inside#if 0blocks, which causes the entire library (and its global constructors) to be linked. Global C++ objects like the ArduinoWiFiinstance end up in.init_array, creating GC roots that prevent--gc-sectionsfrom removing ~326 KB.
SPIClass is the same shape of problem at much smaller scale: a global instance, hence a GC root, on a part with 32 KB of RAM (SAMD21). ESP32 avoids this entirely by defaulting to the ESP-IDF spi_master driver and treating the Arduino SPIClass backend as an opt-in escape hatch. SAMD has no such escape hatch today.
2. Nobody knows whether the SAMD SPI code is correct. It has no compile history. Compiling is not working — it has never been exercised on hardware in this configuration, and it lives under platforms/arm/sam/ (the SAM3X/Due directory) despite being SAMD21/SAMD51 code, which is its own source of confusion.
3. The empty-hint comment was actively misleading. platforms/arm/samd/ldf_headers.h read "no additional LDF hints needed currently" — true only while the stack was unreachable. Worth checking whether the same is true of platforms/arm/stm32/ldf_headers.h, which is also empty while fastspi_arm_stm32.h also includes <SPI.h>.
Proposed work
- Measure the flash/RAM cost of the unconditional
SPIlink onsamd21(32 KB RAM) viabash bloat samd21, and confirm whetherSPIClass's global survives--gc-sections. - Decide the target shape: a native SAMD SERCOM backend needing no Arduino library, or an
FL_SAMD_SPI_ARDUINO=1opt-in mirroring the ESP32 arrangement. - Exercise the SAMD SPI path on hardware (APA102 or similar) — it has never run.
- Move the SAMD SPI sources out of
platforms/arm/sam/intoplatforms/arm/samd/, or state plainly in the SAM README why SAMD code lives there. - Audit
platforms/arm/stm32/ldf_headers.hfor the same latent gap.
Not urgent
SAMD CI is green with the stopgap and the dependency is correct, just broader than it needs to be. This is a size and hygiene issue, not a correctness one.
Follows #4011.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
fix(samd): hint SPI via LDF instead of per-board lib_deps (#4011)
fix(samd): declare SPI in lib_deps as well; fbuild ignores the LDF hint
fix(samd): route SAMD to bit-bang SPI instead of the Arduino backend
fix(samd): detect SAMD from part macros, not ARDUINO_ARCH_SAMD (#4015)
fix(samd): use native SERCOM for hardware SPI (FastLED#4100)