Current state of embedded DMA?

What is the current state / best practice / recommended crates for using DMA in embedded rust, ideally with RTFM 0.4.x, or with cortex-m-rt in general? I'm struggling to find much info or working code. I recall there used to be dma examples in those crates, but no longer.

I last looked in detail about the same time last year, and it was all in a very loose shape - but there was going to be a big push on embedded work in 2018, so I wasn't concerned. I left it alone for a bit, but have come back a year later and .. I can't see that much has changed. (I know a lot of work has gone into other areas, like working on stable rust, which is great - but not my current concern).

I don't even see it on the wg 2019 wishlist. It seems (at least to me) a rather fundamental ability!

I'm aware of the embedonimicon DMA chapter (and the blog post that was its earlier form back then). It's a good discussion of the issues and a sketch of where the solution should go, and very informative overall. But it ends without a clear usable solution, and some caveats about what's left as an exercise.

Have I missed something, or should I just put this aside again for a while longer?

It should be possible. Here's an example for the stm32l4 series (stm32l4xx-hal/serial_dma_us2.rs at master · stm32-rs/stm32l4xx-hal · GitHub). I'm certain other repos have similar examples as well.

Good to know - the ones in the stm32f1xx-hal crate (which I'm using) are explicitly disabled, and there doesn't seem to be any hal::dma module at all.

PS: It's my intention to add it, pending whatever result comes from this thread.

Hey! Embedded-WG member here. I think the current issues are generally:

  • The implementation of DMA on different chips have a number of different behaviors, which makes it hard to elegantly abstract over all platforms.
  • It can be difficult to (correctly) make a safe abstraction over DMA in Rust, for all the reasons mentioned in the embedonomicon.

Feel free to open up an issue, but we also plan to be making two lists in the near future:

  • Patterns we think are good when writing driver libraries
  • Patterns we don't have great examples for yet (including DMA)

The idea would be to enumerate issues like this in the 2nd list, and once someone (like yourself) comes up with a great way of doing things, we can add it to the first list, with a bit of explanation, and links to projects that are doing things this way.

I'll also go ahead and ping our IRC channel (#rust-embedded at irc.mozilla.org) where most developers are active, and point them to this thread to weigh in!

3 Likes

That would be great! Given that the ideal goals are still some way off (and potentially never fully possible), what are people using today - even if model-specific - and what common elements and patterns (perhaps a generic transfer state representation) is just what I'm looking for at the moment.