-
Notifications
You must be signed in to change notification settings - Fork 214
adds dma support for spi #319
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
Conversation
57a4319 to
bf03f2a
Compare
| pub struct Tx<SPI> { | ||
| spi: PhantomData<SPI>, | ||
| dr: u32, | ||
| } | ||
|
|
||
| pub struct Rx<SPI> { | ||
| spi: PhantomData<SPI>, | ||
| dr: u32, | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you bound this SPI to an Instance trait (or other name) with a fn dr() -> u32 method, you could remove this dr field and save some ram. You could then implement this Instance trait for SPI1 (and others) with something like:
unsafe { &(&*SP1::ptr().dr) as *const _ as u32 }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good.
172a168 to
8242235
Compare
|
I've made the change suggested by Thales. I'm having trouble getting the example to work with two transfers. It only transfers once. I have it working in my project using rtic, so my guess is that there is some concurrency going on that is whooshing above my head. Any got any ideas what I'm missing? |
examples/spi_dma.rs
Outdated
| cortex_m::interrupt::free(|cs| *G_TRANSFER.borrow(cs).borrow_mut() = Some(transfer)); | ||
| // Enable interrupt | ||
| unsafe { | ||
| cortex_m::peripheral::NVIC::unmask(stm32::Interrupt::DMA1_STREAM5); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| cortex_m::peripheral::NVIC::unmask(stm32::Interrupt::DMA1_STREAM5); | |
| cortex_m::peripheral::NVIC::unmask(stm32::Interrupt::DMA2_STREAM4); |
src/spi.rs
Outdated
| } | ||
|
|
||
| fn new_tx(&self) -> Tx<SPI> { | ||
| self.spi.cr2.write(|w| w.txdmaen().enabled()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| self.spi.cr2.write(|w| w.txdmaen().enabled()); | |
| self.spi.cr2.modify(|_, w| w.txdmaen().enabled()); |
src/spi.rs
Outdated
| } | ||
|
|
||
| fn new_rx(self) -> Rx<SPI> { | ||
| self.spi.cr2.write(|w| w.rxdmaen().enabled()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| self.spi.cr2.write(|w| w.rxdmaen().enabled()); | |
| self.spi.cr2.modify(|_, w| w.rxdmaen().enabled()); |
... or else txrx() doesn't work because txdmaen is reset
|
cc @peauters |
|
Apologies for leaving this open for so long. I got diverted off onto another project. I'll look to get this in to shape in the next week or so. |
|
Are there any showstoppers left for merging this one? |
|
@kalkyl Can you test this? |
|
bors r+ |
This is a first draft of what DMA support for SPI would look like.
I don't have a great opinion on how some of the error flags can/should be used in conjunction with DMA transfers and would love some advice.
Once #318 has been merged, I'll update the example to look at the extra error flags to show multiple transfers.