Skip to content

Migrate SPI controller operations to async - #3161

Draft
floitsch wants to merge 2 commits into
floitsch/spi.20-buffer-targetfrom
floitsch/spi.30-async-controller
Draft

Migrate SPI controller operations to async#3161
floitsch wants to merge 2 commits into
floitsch/spi.20-buffer-targetfrom
floitsch/spi.30-async-controller

Conversation

@floitsch

@floitsch floitsch commented Aug 6, 2026

Copy link
Copy Markdown
Member

Stacked on #3160.

Requires toitware/esp-idf#126, which adds a narrow public nonblocking SPI bus-acquire operation on top of the existing bus lock. That ESP-IDF PR is stacked on toitware/esp-idf#125.

This migrates ESP32 SPI controller transfers and explicit bus reservation away from blocking primitives.

Highlights:

  • controller transfers are split into start and finish primitives; start queues with zero timeout and finish polls for the completed descriptor
  • an allocation-free post-transaction callback wakes the waiting Toit task through the resource event queue
  • native DMA buffers are allocated and populated before dispatch, and every synchronous error or retryable OOM path cleans up fully
  • the operation remains protected across yields, including deadline handling, so dispatched transactions are always finalized
  • explicit bus reservation uses try-acquire plus a Toit yield loop; a failed try rolls back only its own pending lock request
  • short transmit-only transfers use persistent inline transaction storage, and zero-length transfers avoid null pointer arithmetic
  • two-board tests verify scheduler progress during a deliberately slow transfer and repeatedly exercise reservation contention
  • full SPI target and buffer-target suites pass on classic ESP32 and ESP32-S3, covering modes, bit order, speeds, DMA and non-DMA lengths, partial classic DMA words, overflow, re-arm, and maximum-size transfers

A recent upstream ESP-IDF checkout was checked as well. It still has no public finite-time or nonblocking SPI bus acquisition, so #126 remains necessary and intentionally follows the existing ESP-IDF lock API.

This is a complete-transaction API. Half-buffer streaming and watermark callbacks are deliberately not included.

@floitsch
floitsch force-pushed the floitsch/spi.30-async-controller branch from 8c5ba0f to ff823a4 Compare August 10, 2026 12:47
@floitsch
floitsch force-pushed the floitsch/spi.30-async-controller branch 2 times, most recently from f84c4ae to 36a90c4 Compare August 10, 2026 14:29
@floitsch
floitsch force-pushed the floitsch/spi.30-async-controller branch from 36a90c4 to 0dc5c19 Compare August 10, 2026 16:11
@floitsch
floitsch force-pushed the floitsch/spi.30-async-controller branch 2 times, most recently from 6e9364e to 5ab5adf Compare August 10, 2026 20:13
@floitsch
floitsch force-pushed the floitsch/spi.30-async-controller branch from 5ab5adf to e9039a2 Compare August 10, 2026 21:40
@floitsch
floitsch force-pushed the floitsch/spi.30-async-controller branch from e9039a2 to c4fddc6 Compare August 10, 2026 21:51
@floitsch
floitsch force-pushed the floitsch/spi.30-async-controller branch from c4fddc6 to 81ce542 Compare August 10, 2026 22:58
@floitsch
floitsch force-pushed the floitsch/spi.30-async-controller branch from 81ce542 to 63cc407 Compare August 11, 2026 01:18
@floitsch

Copy link
Copy Markdown
Member Author

@CodeRabbit review

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@floitsch, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 58 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 81d5d507-3728-46ef-a2d9-bb6e43ee0002

📥 Commits

Reviewing files that changed from the base of the PR and between 2bbefb0 and 63cc407.

📒 Files selected for processing (7)
  • lib/spi.toit
  • src/compiler/propagation/type_primitive_spi.cc
  • src/primitive.h
  • src/resources/spi_esp32.cc
  • src/resources/spi_esp32.h
  • tests/hw/esp32/spi-buffer-target-shared.toit
  • third_party/esp-idf

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@floitsch
floitsch force-pushed the floitsch/spi.30-async-controller branch from 63cc407 to b813676 Compare August 11, 2026 23:56
@floitsch
floitsch force-pushed the floitsch/spi.30-async-controller branch from b813676 to a3cd396 Compare August 12, 2026 21:18
@floitsch
floitsch force-pushed the floitsch/spi.30-async-controller branch from a3cd396 to 59a5ab5 Compare August 12, 2026 21:46
@floitsch
floitsch force-pushed the floitsch/spi.30-async-controller branch from 59a5ab5 to 43aa673 Compare August 12, 2026 21:51
@floitsch
floitsch force-pushed the floitsch/spi.30-async-controller branch from 43aa673 to 89201c8 Compare August 12, 2026 22:20
@floitsch
floitsch force-pushed the floitsch/spi.30-async-controller branch from 89201c8 to cfb906b Compare August 12, 2026 22:32
@floitsch
floitsch force-pushed the floitsch/spi.30-async-controller branch 2 times, most recently from f1479ae to f31d001 Compare August 16, 2026 17:11
@floitsch
floitsch force-pushed the floitsch/spi.30-async-controller branch from f31d001 to 8c5c5dc Compare August 16, 2026 18:56
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