Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpiDevice cancel safety: always set CS pin to high on drop #3844

Merged
merged 2 commits into from
Feb 7, 2025

Conversation

showier-drastic
Copy link
Contributor

@showier-drastic showier-drastic commented Feb 4, 2025

Currently, if a transfer is dropped, the CS will stay in a low state, which seems to be undesired. This uses OnDrop to guarantee that CS will be high regardless what happens.

Note that it is currently still unsafe, at least for STM32, to drop an on-going SPI transfer. More investigation on this is TBD. Some suggestions on this would be nice, e.g., whether it's desired to implement cancel safety for SPI transfers.

If a transfer is dropped, the CS will stay in a low state, which
seems to be unsafe.
@@ -97,11 +102,10 @@ where

// On failure, it's important to still flush and deassert CS.
let flush_res = bus.flush().await;
let cs_res = self.cs.set_high();
drop(cs_drop);
Copy link
Member

Choose a reason for hiding this comment

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

this will silently swallow the error.

I'd suggest doing cs_drop.defuse() and then do set_high as before so the error can be handled.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed as you advised. Could you please take a look again?

Copy link
Member

@Dirbaio Dirbaio left a comment

Choose a reason for hiding this comment

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

thanks!

@Dirbaio Dirbaio added this pull request to the merge queue Feb 7, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 7, 2025
@Dirbaio Dirbaio added this pull request to the merge queue Feb 7, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Feb 7, 2025
@Dirbaio Dirbaio merged commit f2a6014 into embassy-rs:main Feb 7, 2025
7 checks passed
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