{
  "id": "embedded/spi-dma-fifo-overrun",
  "signature": "SPI: DMA FIFO overrun, data lost on channel 2",
  "signature_zh": "SPI：DMA FIFO溢出，通道2数据丢失",
  "regex": "SPI:\\s*DMA\\s+FIFO\\s+overrun,\\s*data\\s+lost\\s+on\\s+channel\\s+\\d+",
  "domain": "embedded",
  "category": "runtime_error",
  "subcategory": null,
  "root_cause": "SPI DMA transfer rate exceeds FIFO drain speed, causing data loss in the RX FIFO.",
  "root_cause_type": "generic",
  "root_cause_zh": "SPI DMA传输速率超过FIFO排空速度，导致接收FIFO中数据丢失。",
  "versions": [
    {
      "version": "STM32Cube_FW_H7_V1.11.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "FreeRTOSv202212.01",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "ARM GCC 12.2.1",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Increasing SPI clock speed to match DMA rate",
      "why_fails": "Higher clock speed worsens the FIFO overflow issue as data arrives faster.",
      "fail_rate": 0.9,
      "condition": "",
      "sources": []
    },
    {
      "action": "Disabling DMA and using polling mode",
      "why_fails": "Polling mode reduces throughput and may cause CPU starvation in real-time systems.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Adding software delay loops in the DMA ISR",
      "why_fails": "Delays in ISR increase latency and can cause other interrupts to be missed.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Reduce SPI baud rate prescaler (e.g., from 2 to 4) in MX_SPI1_Init(): hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4; then regenerate code.",
      "success_rate": 0.85,
      "how": "Reduce SPI baud rate prescaler (e.g., from 2 to 4) in MX_SPI1_Init(): hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4; then regenerate code.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Enable SPI RX FIFO threshold interrupt and use DMA with circular mode: set hspi1.Init.FifoThreshold = SPI_FIFO_THRESHOLD_08DATA; and configure DMA in circular mode.",
      "success_rate": 0.9,
      "how": "Enable SPI RX FIFO threshold interrupt and use DMA with circular mode: set hspi1.Init.FifoThreshold = SPI_FIFO_THRESHOLD_08DATA; and configure DMA in circular mode.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use DMA flow controller with burst transfers: configure DMA2_Stream0 with DMA_SxCR_PBURST and DMA_SxCR_MBURST enabled.",
      "success_rate": 0.75,
      "how": "Use DMA flow controller with burst transfers: configure DMA2_Stream0 with DMA_SxCR_PBURST and DMA_SxCR_MBURST enabled.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Reduce SPI baud rate prescaler (e.g., from 2 to 4) in MX_SPI1_Init(): hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4; then regenerate code.",
    "Enable SPI RX FIFO threshold interrupt and use DMA with circular mode: set hspi1.Init.FifoThreshold = SPI_FIFO_THRESHOLD_08DATA; and configure DMA in circular mode.",
    "Use DMA flow controller with burst transfers: configure DMA2_Stream0 with DMA_SxCR_PBURST and DMA_SxCR_MBURST enabled."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://www.st.com/resource/en/application_note/dm00204416-spi-dma-communication-on-stm32-microcontrollers-stmicroelectronics.pdf",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.85,
  "fix_success_rate": 0.78,
  "resolvable": "true",
  "first_seen": "2024-03-15",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}