-
Notifications
You must be signed in to change notification settings - Fork 216
fix(spi): allow using both tx+rx DMA even if capability is not Duplex #883
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
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.
Hey @ritikmishra, thanks for bringing this up. You're right that this is a gap, which seems to be only present in the async+DMA implementation. In fact, we got it right in the blocking+DMA impl:
impl<C, D> Spi<C, D>
where
C: ValidConfig,
D: Receive,
C::OpMode: MasterMode,
{
/// Attach RX and TX DMA channels to this [`Spi`]. Its
/// [`SpiBus`](crate::ehal::spi::SpiBus) implementation will use DMA to
/// carry out its transactions. In Master mode, since even read SPI
/// transaction necessarily involve a write, [`Rx`]-only must take two
/// DMA channels, just the same as if it were [`Duplex`].
#[cfg(feature = "dma")]
pub fn with_dma_channels<R, T>(self, rx: R, tx: T) -> Spi<C, D, R, T>
where
R: crate::dmac::AnyChannel<Status = crate::dmac::Ready>,
T: crate::dmac::AnyChannel<Status = crate::dmac::Ready>,
{
Spi {
capability: self.capability,
config: self.config,
_rx_channel: rx,
_tx_channel: tx,
}
}
}
To sum up:
- In master mode:
- RX: requires 2 channels
- TX: requires 1 channel
- In slave mode:
- RX: requires 1 channel
- TX: requires 1 channel
8dfe86a
to
23a5b1c
Compare
I've made the required changes in this PR. Please let me know if you have questions or comments, otherwise please just merge it and I'll merge #883! |
@jbeaurivage i merged your pr on my fork! |
* atsamd-hal release v0.22.0 * Add missing commits to HAL changelog * Update wio_terminal changelog to include #874 * Update HAL changelog to include #881 * Update HAL changelog to include #883 * Updade pygamer and HAL changelogs following #814 * Update HAL changelog to include #880 * Update HAL changelog to include #878 * Update HAL changelog to include #875 * Update HAL changelog to include #845 * Bump atsamd-hal-macros (#875) * Changelog formatting
Summary
Previously, the SPI API would only allow using both TX and RX DMA channels if both the DI and DO pads were connected. However, even if there is no DO pad present, it is still useful to use a TX DMA in order to write bytes into the data register + drive SCK (in order to receive data from a SPI slave).
We are using at ATSAME54N19A to read voltages from an ADS7043 ADC. The ADS7043 ADC will automatically send the measurement over MISO once clock pulses are detected on SCK, meaning that using MOSI is not necessary.
Checklist
#[allow]
certain lints where reasonable, but ideally justify those with a short comment.If Adding a new Board
crates.json
If Adding a new cargo
feature
to the HALcrates.json
Note
The crate changelogs should no longer be manually updated! Changelogs are now automatically generated. Instead: