Repository navigation
Description
Context
Native child of #5024, following ESP8266 PR #5021. Discovery baseline: 94dab9c6b. Two investigation rounds completed: (1) inventory and dispatch/consumer tracing; (2) register semantics, variants, interrupt contracts, timing units and focused duplicate search. This is a verified software-path optimization opportunity, not a measured performance result.
Implementation evidence: src/platforms/arm/sam/fastpin_arm_sam.h:27-104; src/platforms/arm/sam/fastspi_arm_sam.h:145-156.
Due _DUEPIN uses full 32-bit ODSR via fastset and SODR/CODR atomic masks, with separate PIOA-D. FastPinBB points to individual bit-band aliases whose masks are1 and must be excluded from whole-port eligibility. SAM3X ODSR writes are controlled by PIO output-write-enable state (OWER/OWSR): do not assume readable ODSR implies arbitrary full-port writes are enabled. The native hardware SPI writeBit method separately branches then pulses GPIO.
Production/API reachability: Default SPIOutput remains SAMHardwareSPIOutput; its writeBit is a public GPIO software-bit API, while bulk bytes/writeBits9 use peripheral and are excluded. Explicit SoftwareSPIOutput<DATA,CLOCK,divider> in fastspi.h:107 reaches generic. No claim that ordinary APA102 bulk transfer currently bit-bangs on Due.
The existing shared implementation is src/platforms/shared/spi_bitbang/generic_software_spi.h: kCanStreamSamePort (53-55) requires explicit pin opt-in; useAtomicWrites (60-69) chooses atomic writes for independent ports or FAST_SPI_INTERRUPTS_WRITE_PINS; writeStreamingBit (234-242) combines the previous falling edge with the next data write; finishByteStream (264-268) restores final clock-low. Existing same-port fallback (305-324) emits three stores per bit. Stream callers are writeBytesValueRaw (354-397), writeBytes (403-456), and writePixels (472-557). Absence of opt-in alone was not used as evidence.
Proposal
Use SODR/CODR branchless data policy on actual GPIO entrypoints. Allow generic two-write same-ODSR stream only once required OWSR bits/configuration are proved without broadening unrelated output-write permissions.
Use the existing ESP8266 policy pattern where semantics match; no global default-true trait. Atomic writes and exclusive full-port streaming have different ownership contracts. Whole-port snapshots must never be selected for interrupt/shared-port mode, and a two-core platform must treat the second core as a concurrent writer.
Acceptance criteria
- Establish RED before implementation with a focused fixture compiling the actual production pin implementation and selected SPI entrypoint, instrumenting vendor-register writes or tracing actual generated stores. Capture byte/pixel/start-bit waveforms and count GPIO writes. A fake unrelated pin class or a test checking only trait constants does not establish coverage.
- GREEN must show the targeted improvement: eligible exclusive same-port generic stream emits two stores per payload bit plus one final clock-low per nonempty block; atomic data emits one correct-width data store without a data-dependent GPIO branch or stale whole-port snapshots. If only an independent GPIO bit path applies, assert its direct production register/address/value sequence and absence of OUT RMW. Preserve bit order, exact edge count, final clock-low, modifiers, RGB order, brightness/dithering, start bits, empty blocks and transaction ordering.
- Mutation-sensitive gate: restore the old production writer/policy (or disable the new platform opt-in while leaving the test intact) and demonstrate the same focused gate fails. A waveform-only test that passes both old and new paths is insufficient for the optimization claim. Keep correctness and optimization assertions separate.
- Cover 0x00, 0xff, 0x55, 0xaa, every one-hot byte and transitions across adjacent bytes, pixels and frame boundaries. Inject unrelated-pin updates between writes; atomic/shared mode must preserve them and must never enter full-port streaming. Exercise same-port/different-port cases only where hardware exposes them.
- Audit units before reusing delay code: for these ARM families
fastspi.h:85-90encodesDATA_RATE_MHZ/KHZas CPU-cycles-per-bit, not Hz. Cover slow rates, divider <=10, odd dividers and the 35ns minimum (bitbangPhaseDelay); prove no unsigned underflow and preserve requested high/low timing. Do not transplant ESP8266 minimum-write-cycle assumptions to another bus/CPU. - Compile the real board/configuration matrix below using repository wrappers and supported fbuild toolchains; preserve native peripheral, forced-software-pin and interrupt-safe configurations. A host fixture does not establish vendor-header or real-core compilation.
- Removing redundant GPIO stores while preserving all existing conservative padding requires production-connected traces, real target compilation and generated-code/store-count evidence. Changing target timing assumptions (crediting GPIO latency or skipping existing padding) additionally requires physical logic-analyzer/loopback evidence at the connector/LED input for requested rates, high/low widths and setup/hold under declared interrupt/core conditions. Any claim of physical speed or phase accuracy requires measurements with board/core/compiler/rate/payload recorded. Missing hardware is explicitly unmeasured and cannot establish electrical validation; hardware-dependent timing changes remain open until measured.
Board/configuration matrix
Arduino Due SAM3X8E, supported Digix variant. Same PIO pins0/1, different PIO pins0/2. Compile normal FastPin and explicit SoftwareSPIOutput API; keep FastPinBB negative for streaming. Verify actual BSP PIO_Configure/OWER state on device.
Decisions
- Scope is the implementation above; shared variants belong to this one child with the explicit matrix rather than duplicate issues per board.
- Priority P2: reduce unnecessary GPIO work without weakening electrical or concurrency correctness.
- Hardware peripheral transfers, DMA/PIO engines and clockless protocol encoding are excluded even when filenames mention SPI.
- Preserve existing fallback eligibility until vendor width/address/mux/polarity and timing gates pass; no blanket opt-in based on architectural similarity.
- No source changes, builds, hardware measurements or claimed speedup were made during discovery.
Next steps
Shared prerequisite gates: #5031 owns the production-connected tracing/inventory/mutation infrastructure; #5032 owns shared default-delay call overhead. This child owns the distinct platform register/polarity/width/dispatch contract and should reuse those gates.
- Confirm real vendor headers/register contracts and annotate eligible variants/pins.
- Add the production-connected RED gate and record its failure.
- Implement the smallest platform policy/writer change; run GREEN and old-path mutation.
- Run board matrix and hardware timing checks, then review before opt-in.
Open questions
The board/device availability, exact GPIO bus write latency and supported compiler code generation require implementation-time evidence. Any implementation-specific blockers called out above remain required work. This discovery does not certify hardware timing.
Duplicate search used issue metadata for all-state "software SPI", "bitbang", and "two-write"; no existing platform-specific optimization child was found. Broader platform bring-up and hardware-SPI issues do not replace this focused work.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity