Skip to content

SPI: allow forcing CPU-driven blocking transfers#5350

Open
bugadani wants to merge 1 commit intoesp-rs:mainfrom
bugadani:spi-force-blocking-config
Open

SPI: allow forcing CPU-driven blocking transfers#5350
bugadani wants to merge 1 commit intoesp-rs:mainfrom
bugadani:spi-force-blocking-config

Conversation

@bugadani
Copy link
Copy Markdown
Contributor

Transferring only a few times may be faster than setting up the DMA or rescheduling an async task. This PR adds a configuration that lets users force CPU-driven blocking mode below a certain transfer length, to avoid these setup/reschedule times.

@bugadani bugadani force-pushed the spi-force-blocking-config branch 3 times, most recently from 70f6776 to 9f22983 Compare April 13, 2026 11:14
@bugadani bugadani force-pushed the spi-force-blocking-config branch from 9f22983 to 7454c8e Compare April 13, 2026 11:25
@bugadani
Copy link
Copy Markdown
Contributor Author

/hil full

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 13, 2026

Triggered full HIL run for #5350.

Run: https://github.com/esp-rs/esp-hal/actions/runs/24341117212

Status update: ❌ HIL (full) run failed (conclusion: failure).

@bugadani
Copy link
Copy Markdown
Contributor Author

/test-size embassy_spi esp32s3

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 13, 2026

Binary Size Report

esp32s3

Diff (PR vs. Base)
VM SIZE    
-------------- 
+1.0%    +680    .text
+0.5%    +296    .bss
+0.1%      +8    .data
+0.6%    +984    TOTAL
Filtering enabled (source_filter); omitted  341Ki of entries

@github-actions github-actions Bot added the merge-conflict Merge conflict detected. Automatically added/removed by CI. label Apr 13, 2026
@github-actions
Copy link
Copy Markdown

New commits in main has made this PR unmergable. Please resolve the conflicts.

@bugadani bugadani force-pushed the spi-force-blocking-config branch from 7454c8e to a10fea5 Compare April 13, 2026 15:27
@bugadani bugadani force-pushed the spi-force-blocking-config branch from a10fea5 to 57d0584 Compare May 6, 2026 11:05
@github-actions github-actions Bot removed the merge-conflict Merge conflict detected. Automatically added/removed by CI. label May 6, 2026
@bugadani bugadani force-pushed the spi-force-blocking-config branch from 57d0584 to 036e67e Compare May 6, 2026 11:14
@bugadani bugadani marked this pull request as ready for review May 6, 2026 11:14
Copilot AI review requested due to automatic review settings May 6, 2026 11:14
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new SPI master configuration knob to optionally bypass async/DMA overhead for small transfers by forcing CPU-driven (blocking) transfers under a configurable length threshold.

Changes:

  • Introduces Config::min_async_transfer_size (unstable setter) and stores it in per-peripheral State.
  • Uses the threshold in Spi<Async> and SpiBusAsync implementations to fall back to blocking transfers for small buffers.
  • Extends the same threshold behavior to SpiDma (blocking + async), disabling DMA and executing CPU-driven transfers when below the threshold.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
esp-hal/src/spi/master/mod.rs Adds config/state for the threshold and applies it in async SPI paths.
esp-hal/src/spi/master/dma.rs Applies the same threshold to DMA driver paths, with a CPU fallback.
esp-hal/CHANGELOG.md Documents the new SPI master config option.

Comment thread esp-hal/src/spi/master/mod.rs
Comment on lines +475 to +487
/// Minimum transfer size in bytes below which CPU-driven (blocking) I/O
/// is used instead of async or DMA transfers.
///
/// This can reduce overhead for small transfers where DMA setup or
/// async context-switch cost exceeds the benefit. For
/// [`SpiDma`][crate::spi::master::dma::SpiDma], the threshold applies in
/// both blocking and async DMA modes: when met, DMA is disabled and the
/// transfer is performed by the CPU.
///
/// A value of `0` (the default) disables the threshold — all transfers use
/// the driver's default method.
#[builder_lite(unstable)]
min_async_transfer_size: usize,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can have a mile-long field name, or just accept this...

@bugadani bugadani force-pushed the spi-force-blocking-config branch from 036e67e to 943d031 Compare May 6, 2026 11:24
Copilot AI review requested due to automatic review settings May 6, 2026 11:35
@bugadani bugadani force-pushed the spi-force-blocking-config branch from 943d031 to f3b2d37 Compare May 6, 2026 11:35
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment thread esp-hal/src/spi/master/dma.rs
Comment thread esp-hal/CHANGELOG.md
@bugadani bugadani force-pushed the spi-force-blocking-config branch from f3b2d37 to e833770 Compare May 6, 2026 12:18
@bugadani
Copy link
Copy Markdown
Contributor Author

bugadani commented May 6, 2026

/hil full --test spi_full_duplex

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 6, 2026

Triggered full HIL run for #5350.

Run: https://github.com/esp-rs/esp-hal/actions/runs/25435607324

Status update: ❌ HIL (full) run failed (conclusion: failure).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants