Repository navigation
Description
Context
The independent public blocking parallel SPI classes compute 1u << pin from arbitrary u8 pin arguments without validating the index. All six SpiBlock1/2/4/8/16/32::setPinMapping implementations do this for clock and data. ISR 1/2/4 pin-index APIs use the same unchecked operation, including data indices in their mask variants.
On targets with 32-bit unsigned int, pin 32 or greater produces undefined shifts; on 16-bit unsigned-int targets the limit is smaller. Duplicate data pins and data/clock overlap can also make contradictory masks rather than reject the configuration. A purported 32-independent-data-plus-clock mapping cannot fit one 32-bit GPIO bank; it needs explicit rejection or a real bank model, not aliased bits.
Sources at the fixed audit baseline:
| void setPinMapping(u8 data, u8 clk) FL_NO_EXCEPT { |
spi_block_2.h, spi_block_4.h, spi_block_8.h, spi_block_16.h, spi_block_32.h, spi_isr_1.h, spi_isr_2.h and spi_isr_4.h. The six blocking bodies must not be collapsed to forwarding aliases.
These documented public classes are directly callable. ParallelDevice::begin() currently rejects both modes, so no active producer is claimed through it. ISR 8/16/32 expose raw 32-bit masks; they are not mislabeled as the same index-shift implementation, but their accepted mask contract must be assessed explicitly.
Proposal
Validate pin and mask contracts before shifting, indexing, updating configuration or writing GPIO. Represent the actual target/bank capability; fail explicitly on unsupported indices, collisions or mappings rather than wrapping/truncating them. Preserve previously valid state when reconfiguration fails.
Acceptance criteria
- RED -> GREEN tests call each actual production blocking implementation and each ISR 1/2/4 pin-index entrypoint, including mask variants. Cover valid boundary indices, unsigned-int-width boundaries, 31/32/255, duplicate pins, data-clock overlap and failed reconfiguration followed by a valid transfer.
- No undefined shift, incorrect-bank access or GPIO output may occur for rejected inputs. Preserve all valid mapped data bits, unrelated pins, exact clock/data edges and empty/repeated transfer behavior.
- Assess ISR 8/16/32 raw-mask contracts separately: clock mask shape, overlap, representable bank and caller rejection where applicable. Do not falsely claim those use the same pin-index API.
- Real supported vendor builds establish bank/operation width; host sanitizers/trace tests establish production logic only. Unsupported 32-data-plus-independent-clock configurations must not silently alias.
- Restore the old unchecked shifts/mapping independently and require focused regressions to fail, followed by exact restoration and GREEN. Bind all independent source/configuration inputs into test: gate software SPI changes on exhaustive production-path and mutation evidence #5031.
Decisions
Group the shared invalid-mapping cause while preserving independent method coverage. This is separate from the shared hardcoded MMIO selection defect and #5050's unrelated runtime channel loop. No copied test writer or absent in-tree producer can certify these public methods.
Part of #5024.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
zackees commentedon Nov 7, 2026
#5146 covers part of this issue. It validates every SpiBlock1-32 and SpiIsr1/2/4 pin-index entry point, and ParallelDevice::begin(), before any shift. Rejected calls return false and keep the last good mapping, and unmapped blocking drivers write no GPIO.
Still open here:
fix(spi): reject pin mappings parallel soft-SPI cannot shift into its…
fix(spi): reject aliased lanes and bad raw masks in parallel soft-SPI (…