stm32f1xx-hal
stm32f1xx-hal copied to clipboard
Better Circular DMA support
This is my initial draft on PR on issue #242.
The example serial-dma-circ-len.rs
shows how to use it in more detail, but the most important changes are demonstrate in the following snippet:
let mut circ_buffer = rx.circ_read(buf);
// wait until we have 5 bytes
while circ_buffer.len() < 5 {}
let mut dat = [0 as u8; 4];
assert!(circ_buffer.read(&mut dat[..]) == 4);
One thing I have noticed is that currently a lot of the responsibility in setting up DMA is coded in the using module (e.g. in the serial
module. I've introduced a setup
function, so that it happens within the DMA module, and the setup within the serial module looks like:
fn circ_read(self, buffer: &'static mut B) -> CircBuffer<u8, Self>{
let buffer = buffer.as_mut_slice();
let paddr = unsafe { &(*$USARTX::ptr()).dr as *const _ as u32 };
let mut buf = CircBuffer::new(buffer, self);
unsafe { buf.setup(paddr, Priority::MEDIUM) };
buf
}
I have renamed the old CircBuffer
behaviour renamed into e.g. CircDoubleBuffer
.
I have only implemented this for the serial module so far.