-
Notifications
You must be signed in to change notification settings - Fork 48
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
Access DMA buffered data from RTIC task #171
Comments
Thank you for the report! :) Yeah the DMA story is currently less than perfect... This is issue is proof of that. I have opened #170 to try and find solutions to make working with DMA more nice. I believe this is a good example of something that should be easier to do. As for your code snippet above. Mutable references are supposed to be unique. [...]
let mut adc_dma = unsafe {// First mutable borrow ------v
stream.into_circ_peripheral_to_memory_transfer(adc_dma_enabled, &mut ADC_BUFFER, config)
};
// Start DMA transfer and ADC conversion
adc_dma.start(|adc| adc.start_conversion());
(
Local {
adc_dma: adc_dma,// v------ Second mutable borrow - UB💥
adc_buffer: unsafe { &mut ADC_BUFFER },
},
init::Monotonics(mono),
)
[...] The second mutable borrow causes UB. So this should really be avoided. This why the warning tries to prevent you from borrowing the From a quick look I do not see anything preventing implementing something like |
I encountered this exact same roadblock last week while working on something. I believe the original designers intended for transfers to be constructed and then ...very difficult to embed in any kind of abstracted code due to move semantics. But yes this is a good use-case example we outlined in #170 for interface improvements. As a side note, it's usually good practice to minimize the size of interrupt functions, unless immediate response time is necessary. If it's not, you can |
Hi I'm new to rust and stm32s so please bare with me.
Main issue: I cannot find a way to access buffered data from a RTIC task triggered by a DMA transfer complete interrupt.
Preferred functionality from a stm32f4xx_hal example - https://github.com/stm32-rs/stm32f4xx-hal/blob/master/examples/rtic-adc-dma.rs
This example configures DMA to trigger an interrupt when its buffer is full (in this case a quantity of 2).
transfer
is set as a shared variable, and given a&'static mut [u16; 2]
buffer to fill.In the
dma
interrupt task (triggered when the first buffer is full), the task locks shared.transfer, and (from what I understand) passes ownership of the filled buffer from the transfer to the interrupt task, replacing it with a second buffer.I have attempted to do something similar with stm32g4xx_hal without success. There is no
next_trasfer()
available.I am not necessarily requiring a double buffer strategy, but simply a way to access the full buffer's data from the interrupt task utilizing the tools provided from this hal, avoiding unsafe blocks.
Side note:
I have developed a somewhat usable way using unsafe blocks to access
static mut
array. This is not my preferred method.In fact, rustc gives me this warning
warning: creating a mutable reference to mutable static is discouraged
.Is there already a supported way to access the dma buffer data? Or is this functionality lacking.
Thanks for the help!
The text was updated successfully, but these errors were encountered: