Skip to content

Harden I2C and SPI hardware edge cases - #3205

Merged
floitsch merged 10 commits into
floitsch/spi.30-async-controllerfrom
floitsch/i2c-spi-hw-tests
Sep 13, 2026
Merged

floitsch merged 10 commits into
floitsch/spi.30-async-controllerfrom
floitsch/i2c-spi-hw-tests

Conversation

@floitsch

@floitsch floitsch commented Sep 3, 2026 •

Copy link
Copy Markdown
Member

Stacked on #3161. The required ESP-IDF patch head is already on master.

This follow-up closes the remaining review and hardware-test gaps for the asynchronous I2C/SPI stack:

  • Adds deterministic retryable-OOM cleanup tests for target and controller allocation paths.
  • Tests I2C clock stretching, a bus held low before START, FIFO boundaries, exact overflow accounting, abort, and reuse.
  • Adds the i2c.Target --default-response option: a bounded fallback response used whenever no ordinary transmit data is ready. Ordinary write data takes over at a read-transaction boundary, and the default is restored automatically after that stream drains.
  • Covers the full request protocol on paired boards: repeated not-ready reads, controller request, queued ready response, and automatic return to not-ready.
  • Expands SPI target and buffer-target coverage across modes 0-3, single/full-duplex direction changes, bit order, DMA/non-DMA, queue overflow, abort/close, and non-byte-aligned CS termination.
  • Measures every supported CS setup/hold value with independent RMT probes and verifies the clock count.
  • Adds CONFIG_TOIT_ENABLE_I2C_TARGET and CONFIG_TOIT_ENABLE_SPI_TARGET; disabling either compiles its implementation and dependencies out, while both remain enabled in the default envelope.
  • Keeps CONFIG_SPI_MASTER_ISR_IN_IRAM=y on classic ESP32 while retaining both targets.
  • Hardens staged construction, cancellation, cleanup, teardown ordering, queue allocation, and target response arbitration.
  • Marks one-data-line controller buses as half-duplex and rejects the unrepresentable classic-ESP32 hold value 16.
  • Adds a tracking document with the coverage inventory and hardware evidence.

The original ESP32 ACKs an empty target read but returns undefined FIFO contents; an observed eight-byte read was b5 ff ff ff ff ff ff ff. The configured default makes this case deterministic without clock stretching.

Hardware verification using paired boards:

  • ESP32: complete I2C/SPI selection 15/15 after setup and 12/12 immediately without setup.
  • ESP32-S3: complete I2C/SPI selection 15/15 after setup and 12/12 immediately without setup.
  • Focused default-response I2C tests pass on both variants, including short dynamic responses and transitions back to the fallback response.
  • Changed Toit sources pass analysis with warnings treated as errors; host, target-disabled, ESP32, and ESP32-S3 builds pass.
  • Native ESP-IDF I2C/SPI builds pass with the relevant IRAM-safe options enabled.

@floitsch
floitsch force-pushed the floitsch/i2c-spi-hw-tests branch from 297bd38 to 310264a Compare September 3, 2026 15:48
@floitsch
floitsch force-pushed the floitsch/i2c-spi-hw-tests branch from 310264a to 2046e8d Compare September 3, 2026 15:57
@floitsch
floitsch force-pushed the floitsch/i2c-spi-hw-tests branch from 2046e8d to e08a157 Compare September 3, 2026 16:08
@floitsch
floitsch force-pushed the floitsch/i2c-spi-hw-tests branch 2 times, most recently from 7e35b5f to b8cf906 Compare September 4, 2026 16:45
@floitsch
floitsch force-pushed the floitsch/i2c-spi-hw-tests branch from b8cf906 to 9e2f216 Compare September 4, 2026 22:51
@floitsch
floitsch force-pushed the floitsch/i2c-spi-hw-tests branch from 9e2f216 to 675283e Compare September 7, 2026 23:27
@floitsch
floitsch force-pushed the floitsch/i2c-spi-hw-tests branch from 675283e to 370466c Compare September 7, 2026 23:42
@floitsch
floitsch force-pushed the floitsch/i2c-spi-hw-tests branch from 370466c to 69795e0 Compare September 8, 2026 16:03
@floitsch
floitsch force-pushed the floitsch/i2c-spi-hw-tests branch 2 times, most recently from 1b5a0ff to fc78399 Compare September 9, 2026 10:34
@floitsch
floitsch force-pushed the floitsch/i2c-spi-hw-tests branch from fc78399 to bc4d8e1 Compare September 9, 2026 15:12
@floitsch
floitsch removed this pull request from stack #3213 September 9, 2026 15:16
@floitsch
floitsch added this pull request to stack #3217 September 9, 2026 15:16
@floitsch
floitsch force-pushed the floitsch/i2c-spi-hw-tests branch from 77576ba to fde9bbd Compare September 10, 2026 21:30
@floitsch
floitsch force-pushed the floitsch/i2c-spi-hw-tests branch from cadcbed to 6fd74c9 Compare September 12, 2026 23:16
@floitsch
floitsch merged commit 0ef6232 into master Sep 13, 2026
37 checks passed
@floitsch
floitsch deleted the floitsch/i2c-spi-hw-tests branch September 13, 2026 01:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant