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

Async SPI #385

Merged
merged 11 commits into from
Feb 8, 2023
Merged

Async SPI #385

merged 11 commits into from
Feb 8, 2023

Conversation

MabezDev
Copy link
Member

@MabezDev MabezDev commented Feb 6, 2023

This PR implements a Future based abstraction around the current DMA implementations and uses said abstraction to implement the Async SPI traits from e-h on SpiDma.

FYI the diff looks kinda weird because of the fmt commit, perhaps compare the commits before that fmt commit for easier viewing.

Breaking changes

dma::private, gdma::private, and pdma::private no longer exist. All the DMA types/traits are now public. The ideal solution would be to erase these types see #381.

Future work

  • The error handling for the DMA needs some work at the moment DMA errors are unchecked.
  • We could implement the e-h-a SPI traits on the normal Spi struct using the peripheral FIFO + interrupts, but this is less efficient and unnecessary for this initial implementation.

@bjoernQ
Copy link
Contributor

bjoernQ commented Feb 7, 2023

Looks good and works fine

Only thing is discovered: we broke the I2S sound example (circular DMA) by 5f933aa

So technically this PR isn't the problem but I think the mentioned commit is the ground work for this

Reverting that one line makes it work again, apparently but breaks this

@bjoernQ
Copy link
Contributor

bjoernQ commented Feb 7, 2023

Maybe an obvious fix would be to change

dw0.set_suc_eof(last);

to

dw0.set_suc_eof(circular || last);

Interestingly the example also works with the original true on ESP32

@MabezDev
Copy link
Member Author

MabezDev commented Feb 7, 2023

Thanks for the review!

Maybe an obvious fix would be to change

Sounds good, but perhaps we should do that change in another PR, and maybe take a closer look and make sure that's the real fix?

@bjoernQ
Copy link
Contributor

bjoernQ commented Feb 7, 2023

Thanks for the review!

Maybe an obvious fix would be to change

Sounds good, but perhaps we should do that change in another PR, and maybe take a closer look and make sure that's the real fix?

You are right it's not really related to this PR - I will create an issue for that (since I2S is already broken)
So I guess this is fine for me then

Copy link
Contributor

@JurajSadel JurajSadel left a comment

Choose a reason for hiding this comment

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

LGTM!

self: core::pin::Pin<&mut Self>,
cx: &mut core::task::Context<'_>,
) -> Poll<Self::Output> {
TX::waker().register(cx.waker());
Copy link
Contributor

@bugadani bugadani May 14, 2023

Choose a reason for hiding this comment

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

@MabezDev Shouldn't the waker only be registered when the poll returns Pending? I know this is a common pattern in embassy but I wonder if it's necessary to execute code unconditionally.

At first I suspected this might be the reason for a bug I'm expeciencing, but that came from me not correctly understanding what's happening here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Perhaps? Did you try moving the waker registration? I can't really see it causing an issue, but if it fixes your issue its something to look into.

Copy link
Contributor

Choose a reason for hiding this comment

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

No I'm working on another issue. I don't expect this to cause problems, just worse than ideal perf, so nothing terribly important.

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.

4 participants