-
Notifications
You must be signed in to change notification settings - Fork 249
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
How to manage lifetimes with DMA #905
Comments
I'm really not an expert on DMA, so I waited a while to give others a chance to answer first. However, as nobody did yet, let me try. As far as I know there's no great answer to your question. It's a hard problem if you want to be strict about rust's safety guarantees:
Depending on your use case, the simplest solution may be to use an allocator, eg. https://crates.io/crates/embedded-alloc, and be careful to avoid OOM situations. Of course, if you are not writing a library that should be safe even if users of that library call the API in unexpected ways, but instead you are the only user of your DMA buffer, you can also "just be careful" not to forget an object, and make sure you always stop the DMA transfer. Then you can do something like this:
Sorry, this is not a complete solution, and I'm not even sure that everything I wrote is correct. |
Hia,
This is probably a misunderstanding; but I'm really not sure how to correctly handle the buffers used for DMA given their
'static
requirement that I seem to run into.For example, given a struct that contains the buffer to be used with DMA
The only way to get this to really work is to make
self
'static
which isn't really viable with re-use.This is because I run into
rp2040_hal::dma::single_buffer::Config::new
requiring a'static
lifetime on the ReadTarget.Am I missing something that will allow any other lifetime around this? Trying to encapsulate the ownership nicely? Given that the transfer.wait() call returns the buffer, my original plan was to persist the transfer item into the object to retrieve it but can't get that far.
I assume I'm missing something obvious, but also can't seem to find any online examples that deal with this (i.e. dont just use the dma in the main entry function; but actually have the buffer stored elsewhere).
The text was updated successfully, but these errors were encountered: