{
  "id": "embedded/spi-dma-crc-error-stm32",
  "signature": "SPI: DMA CRC error, received CRC mismatch on slave, expected 0x1A2B got 0x3C4D",
  "signature_zh": "SPI：DMA CRC错误，从设备接收到的CRC不匹配，期望0x1A2B实际为0x3C4D",
  "regex": "SPI: DMA CRC error, received CRC mismatch on slave, expected 0x[0-9A-F]+ got 0x[0-9A-F]+",
  "domain": "embedded",
  "category": "protocol_error",
  "subcategory": null,
  "root_cause": "CRC calculation mismatch between master and slave due to different polynomial settings or DMA transfer length misalignment in STM32 SPI hardware CRC mode.",
  "root_cause_type": "generic",
  "root_cause_zh": "主从设备间CRC计算不匹配，原因是多项式设置不同或STM32 SPI硬件CRC模式下DMA传输长度未对齐。",
  "versions": [
    {
      "version": "STM32Cube_FW_H7 v1.10.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "ARM GCC v12.2.1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "SPI HAL driver v2.4.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Disable SPI CRC hardware and implement software CRC",
      "why_fails": "Software CRC adds latency and may conflict with DMA timing; hardware CRC mismatch root cause remains unaddressed.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "Swap master and slave roles",
      "why_fails": "Role swap does not fix polynomial or length mismatch; error may move but persists.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Set identical CRC polynomial on both master and slave: SPI_InitTypeDef.CRCPolynomial = 7; and ensure SPI_CRCPR register matches. For DMA, set SPI_CR2.TXDMAEN/RXDMAEN after configuring CRC length.",
      "success_rate": 0.95,
      "how": "Set identical CRC polynomial on both master and slave: SPI_InitTypeDef.CRCPolynomial = 7; and ensure SPI_CRCPR register matches. For DMA, set SPI_CR2.TXDMAEN/RXDMAEN after configuring CRC length.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Align DMA transfer size to CRC length: if CRC is 16-bit, ensure total transfer length is multiple of 2 bytes. Use HAL_SPI_TransmitReceive_DMA() with buffer sizes that include CRC bytes.",
      "success_rate": 0.9,
      "how": "Align DMA transfer size to CRC length: if CRC is 16-bit, ensure total transfer length is multiple of 2 bytes. Use HAL_SPI_TransmitReceive_DMA() with buffer sizes that include CRC bytes.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "在主从设备上设置相同的CRC多项式：SPI_InitTypeDef.CRCPolynomial = 7；并确保SPI_CRCPR寄存器匹配。对于DMA，在配置CRC长度后设置SPI_CR2.TXDMAEN/RXDMAEN。",
    "将DMA传输大小与CRC长度对齐：如果CRC是16位，确保总传输长度是2字节的倍数。使用包含CRC字节的缓冲区大小的HAL_SPI_TransmitReceive_DMA()。"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://www.st.com/resource/en/reference_manual/rm0399-stm32h745755-and-stm32h747757-advanced-armbased-32bit-mcus-stmicroelectronics.pdf",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.88,
  "fix_success_rate": 0.92,
  "resolvable": "true",
  "first_seen": "2023-11-20",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}