# SPI: DMA transfer incomplete, expected 256 bytes but only 128 bytes received on channel 1

- **ID:** `embedded/spi-dma-transfer-incomplete`
- **Domain:** embedded
- **Category:** data_error
- **Error Code:** `SPI_DMA_INCOMPLETE`
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

The SPI DMA transfer was prematurely terminated due to a timeout, FIFO overflow, or slave device deasserting chip select mid-transfer.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| STM32Cube_FW_F7 v1.17.0 | active | — | — |
| STM32Cube_FW_G4 v1.6.0 | active | — | — |
| DMA HAL Driver v2.3.0 | active | — | — |

## Workarounds

1. **Add a DMA transfer complete callback (HAL_SPI_TxRxCpltCallback) to verify the received byte count and re-initiate the transfer if incomplete.** (85% success)
   ```
   Add a DMA transfer complete callback (HAL_SPI_TxRxCpltCallback) to verify the received byte count and re-initiate the transfer if incomplete.
   ```
2. **Enable SPI CRC checking to detect data corruption and retry the transfer on CRC mismatch.** (70% success)
   ```
   Enable SPI CRC checking to detect data corruption and retry the transfer on CRC mismatch.
   ```

## Dead Ends

- **Increase the SPI clock speed to transfer data faster** — Higher clock speed can exacerbate timing issues and cause more FIFO overflows, worsening the problem. (80% fail)
- **Disable DMA and use polling SPI transfer instead** — Polling transfers can block the CPU for long periods, causing real-time task failures and still not resolving the root cause of incomplete transfers. (75% fail)
