{
  "id": "embedded/spi-cs-glitch-on-gpio",
  "signature": "SPI: chip select glitch detected on GPIO line, causing false slave selection",
  "signature_zh": "SPI：GPIO线路上检测到片选信号毛刺，导致从设备被误选中",
  "regex": "SPI: chip select glitch detected on GPIO line",
  "domain": "embedded",
  "category": "hardware_error",
  "subcategory": null,
  "root_cause": "The chip select (CS) GPIO line is driven by software or has insufficient drive strength, causing a brief low pulse (glitch) during GPIO toggling, which falsely selects or deselects the SPI slave.",
  "root_cause_type": "generic",
  "root_cause_zh": "片选GPIO线由软件驱动或驱动强度不足，在GPIO切换时产生短暂低电平脉冲（毛刺），导致SPI从设备被误选中或取消选中。",
  "versions": [],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "",
      "why_fails": "Adding a delay before toggling CS does not eliminate the glitch; the glitch occurs during the transition itself.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "",
      "why_fails": "Changing the GPIO output speed to high increases the glitch amplitude due to faster slew rate, making the problem worse.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Enable the SPI peripheral's hardware NSS (automatic chip select) if available. Example on STM32: hspi.Init.NSS = SPI_NSS_HARD_OUTPUT; then configure the CS pin as SPI_NSS alternate function.",
      "success_rate": 0.95,
      "how": "Enable the SPI peripheral's hardware NSS (automatic chip select) if available. Example on STM32: hspi.Init.NSS = SPI_NSS_HARD_OUTPUT; then configure the CS pin as SPI_NSS alternate function.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Add a 10kΩ pull-up resistor on the CS line to hold it high during GPIO transitions, and set the GPIO output to open-drain with a weak drive.",
      "success_rate": 0.85,
      "how": "Add a 10kΩ pull-up resistor on the CS line to hold it high during GPIO transitions, and set the GPIO output to open-drain with a weak drive.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Enable the SPI peripheral's hardware NSS (automatic chip select) if available. Example on STM32: hspi.Init.NSS = SPI_NSS_HARD_OUTPUT; then configure the CS pin as SPI_NSS alternate function.",
    "Add a 10kΩ pull-up resistor on the CS line to hold it high during GPIO transitions, and set the GPIO output to open-drain with a weak drive."
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://www.st.com/resource/en/application_note/an4031-stm32-spi-protocol.pdf",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.86,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2024-06-01",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}