Skip to content

sdfat(teensy4): route SdFat's SPI transport onto LpspiBus #3971

Closed

Description

@zackees

Sub-issue of #3970. Scope: Teensy 4.0 / 4.1 (MXRT1062) only.

Investigation result: the live surface is smaller than the issue implies

Two branches in SdSpiTeensy3.cpp.hpp are dead, which removes most of the apparent work:

  • SDFAT_SDCARD_SPI / SDFAT_SDCARD_SS_PIN are never defined anywhere in the tree, so the setMISO/setMOSI/setSCK branch is unreachable. Those three methods are not needed.
  • USE_TRANSFER_TX_RX is always defined for Teensy, so the in-place transfer(buf, count) branch is unreachable. Only the 3-argument full-duplex form is needed.

The live surface SpiPort_t must provide is therefore exactly:

member LpspiBus today
begin() / end() present
beginTransaction(settings) / endTransaction() present
transfer(u8) -> u8 present (writes TDR, spins FSR, returns RDR)
setTransferWriteFill(u8) missing
transfer(const void* tx, void* rx, size count) missing

Plus a settings type — LpspiSettings(clock, bit_order, data_mode) already has the identical signature to SPISettings(maxSck, MSBFIRST, SPI_MODE0) — and a default instance, for which LpspiBus::get(index) already exists behind fl::Singleton<LpspiBusStorage> (elision-safe).

Tasks

  • Add setTransferWriteFill(fl::u8) to LpspiBus (stores the fill byte used when tx == nullptr)
  • Add transfer(const void* tx, void* rx, fl::size count) to LpspiBus. A loop over the existing transfer(u8) is acceptable for a first cut; tx == nullptr sends the fill byte, rx == nullptr discards. Do not add DMA or async.
  • Make SpiPort_t resolve to LpspiBus on Teensy 4 instead of SPIClass, through the existing SdSpiDriver.h typedef seam, and drop the #include "SPI.h" on that path
  • Point SdSpiArduinoDriver::begin()'s fallback at LpspiBus::get(0) instead of the global SPI
  • Keep the Arduino path reachable behind a define as an escape hatch

Constraints

Acceptance

  • bash compile teensy41 --examples Fx/FxSdCard links, no SPIClass/SPI undefined symbols
  • bash compile teensy40 --examples Fx/FxSdCard links
  • bash test --cpp passes — 283/283 unit and 83/83 examples on host. This is the check that caught the previous attempt (fix(examples): declare the SPI dependency in FxSdCard — takes teensy to 8/8 green (#3838) #3969), so run it, not just bash lint
  • bash lint clean
  • teensy35/36 behaviour unchanged (still on the Arduino path, still red — expected)
  • A sketch that never calls beginSd() still emits no SdFat/SPI storage (singleton elision preserved)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions