Fault Injection & Debugging

SPI bus fault testing and chip-select verification

SPI has no hardware ACK bit—when a slave drops off the bus, MISO silently reads 0x00 or 0xFF. Test your detection paths automatically in CI.

Because SPI has no acknowledgement phase, a disconnected sensor, bad CPOL/CPHA mode or dropped CS line simply returns 0xFF or shifted garbage. Firmware without chip-ID checks, CRC validation or range sanity checks happily feeds 0xFFFF into a PID loop.

CircuitTwin lets you run real SPI drivers against twins like Bosch BMI088, MAX31855, SX1276 and SX1280 while injecting bus disconnects, busy-pin holds and frozen register values.

SPI failure modes to gate in CI

Failure modeWhat MISO returnsHow to catch it in firmware
Slave disconnected / unpoweredAll 0xFF or 0x00Check WHO_AM_I / CHIP_ID + reject all-0xFF frames
Wrong CPHA or dummy byteBit-shifted ID (e.g. 0x3C vs 0x1E)Assert exact reset CHIP_ID against twin
CS raised while TX FIFO drainingTruncated write / ignored commandPoll SPI_SR.BSY == 0 before raising CS
Radio BUSY pin ignored (SX1280)Dropped SetTx / config commandPoll BUSY low before every SPI opcode (verified by AC-6)

Local CLI workflow

Shell — run SPI fault suite
ct test run --json --junit results/spi.xml tests/spi-faults.suite.yaml

Suite & fault configuration

tests/spi-faults.suite.yaml
version: 1
board: nucleo-f767zi
firmware: build/spi_imu.elf
tests:
  - name: bmi088-bus-disconnect-recovery
    faults:
      - at_ms: 80
        part: bmi088
        kind: bus_disconnect
        duration_ms: 30
    expect:
      console_contains: "SPI_REINIT_OK"
      exit_code: 0
  - name: max31855-open-thermocouple
    faults:
      - at_ms: 50
        part: max31855
        kind: fault_bit
        bit: OC
    expect:
      console_contains: "TC_OPEN_FAULT"

CI pipeline integration

.github/workflows/spi-faults.yml
name: SPI Fault CI
on: [push, pull_request]
jobs:
  spi-test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: cmake --build build
      - uses: circuittwin/action@v1
        with:
          suite: tests/spi-faults.suite.yaml

SPI chip-select glitch and bus-disconnect testing

Catch wrong SPI CPOL/CPHA modes, missing CS de-assertion and frozen MISO readings before flashing a PCB.

Shared SPI buses fail silently when one driver leaves CS low or forgets to restore CPOL/CPHA after talking to a Mode 3 IMU and a Mode 0 flash chip.

CircuitTwin models full-duplex SPI transactions, CS framing and per-device fault injection so CI fails immediately when an unexpected chip ID or 0xFF/0x00 bus read goes unchecked.

SPI faults caught in CI

FaultWire symptomExpected firmware check
bus_disconnectMISO reads 0xFF or 0x00Driver rejects invalid JEDEC/WHO_AM_I instead of trusting zeros
Mode mismatchShifted bit values on MISOInit fails fast with SPI_MODE_ERROR
CS held across transfersCommand framing misalignedTwin logs framing fault and driver recovers cleanly
Shell - run SPI disconnect fault suite
ct test run --json --junit results/spi-faults.xml tests/spi-glitch.suite.yaml
tests/spi-glitch.suite.yaml
version: 1
board: nucleo-h743zi2
firmware: build/app.elf
tests:
  - name: spi-imu-disconnect-and-reinit
    timeout_ms: 2000
    faults:
      - at_ms: 80
        part: icm-42688-p
        kind: bus_disconnect
        duration_ms: 40
    expect:
      console_contains: "SPI_SENSOR_RECOVERED"
      exit_code: 0

Troubleshooting checklist

SymptomFix
BMI088 accelerometer ID reads 0x00 on first byteBMI088 accelerometer requires 1 dummy byte after the address byte in SPI mode; gyroscope does not.
Slave misses last write byte at high SCLKWait for RXNE and BSY==0 before releasing CS; check prescaler in the SPI Clock Divider Calculator.
SX1280 ignores SetTx command intermittentlyPoll the BUSY GPIO until low before asserting NSS (checked by radio acceptance criterion AC-6).
Shared SPI bus corrupts flash during IMU DMAGuard bus access with a mutex and verify CS polarity/idle states for every device on the bus.
CS rises before last SPI byte finishes shiftingWait for SPI_SR_BSY == 0 (not just TXE == 1) before pulling NSS high.
SPI read lags by one byteFlush the RX FIFO or read SPI_DR after every dummy write to clear OVR.

Frequently asked questions

QuestionAnswer
Why does pulling SPI CS high on TXE corrupt the last byte?TXE fires when the transmit buffer is empty, while the shift register is still clocking the final byte onto MOSI. Always poll BSY=0 before raising CS.

Related boards & component twins

More in Fault Injection & Debugging