Repository navigation
fix(teensy4): send pending writeBit bits at transaction boundaries - #5147
Conversation
…5064) Bits ahead of a byte still ride in one 9-15 bit LPSPI frame. A 1-7 bit remainder, which no LPSPI frame can carry, goes out by GPIO with the pads saved and restored. release, waitFully, finalizeTransmission and writeBytesValueRaw flush first, so pending bits never reach the next transaction. The legacy mxrt1062 copy becomes a shim.
|
Caution Review failedThe pull request is closed. Walkthrough
Merge Risk:
|
Memory usage (this PR vs. its merge base)Change in
|
Part of #5064 (does not close it; see "Not met"). Part of #5024.
On Teensy 4,
Teensy4HardwareSPIOutput::writeBitonly transmitted on every eighth call, andwaitFully,finalizeTransmissionandreleasenever finished a partial group. Soselect(); writeBit<0>(1); endTransaction();sent nothing, and the bit leaked into the next transaction's first byte.writeBytesValueRawalso skipped bits still pending.Fix
fl::delayNanosecondssteps, then restores both pads' mux and pad-control values. Every LPSPI write here blocks until it is done, so the shifter is idle at the handoff.release,waitFully,finalizeTransmissionandwriteBytesValueRawsend pending bits first. Pending bits can no longer reach a later transaction or be overtaken by raw bytes, and chip select is released only after they are out.port().namespace fland the warning push/pop now sit inside theFL_IS_TEENSY_4Xblock they open in.src/platforms/arm/mxrt1062/fastspi_arm_mxrt1062.hshared the live header's include guard, so whichever was included first silently replaced the other. It is now a one-line shim, like its siblings in that directory.Evidence
tests/platforms/arm/teensy/teensy4_common/fastspi_arm_mxrt1062.cppruns the real class, its realLpspiBusand the realSM16716Controlleron three simulated LPSPI peripherals. The simulator records frame lengths (frames under 8 bits count as errors), chip select, pad ownership, the receive FIFO, and GPIO latches on pins 11/13.BIT0-7 with all 256 values;waitFully,finalizeTransmission,endTransactionandrelease;port().RDR;read is an unused-value error on the simulated register. With only that line made an explicit read, it fails at its first check:endTransactionsent 0 bits, not 1.release;waitFullyorfinalizeTransmissionas no-ops;bash compile teensy41|teensy40 --examples Apa102pass, with the sketch temporarily given calls through both header paths:Teensy4HardwareSPIOutputon indices 0, 1 and 2, and every changed method. The sketch was restored and not committed.bash test fastspi_arm_mxrt1062 --debugpasses with sanitizers.bash test --cpppasses: 359/359 unit tests, but only 1/1 example was re-run, the rest being cached.bash lintexits 0.Not met from #5064
SPIOutputresolves toSPIDeviceProxy, which has nowriteBit, so SM16716 cannot reach this class through the normal dispatch. The test routes the real controller onto this class directly. This PR fixes the public class; it does not add a producer.fl::delayNanosecondscalls.Limits
FastPin::setOutput, which calls Teensy'spinModeand writes the pads. Both values are saved and restored. The GPIO direction bits stay as outputs; the mux decides what reaches the pad.sendFramestill spins on RX-not-empty, as before. It assumes RX capture is on, whichbeginTransactionsets.Summary by CodeRabbit