stm32/spi: fix blocking transfer hanging after async.
This commit is contained in:
parent
49ef19c0b2
commit
1dc618f0e4
@ -575,6 +575,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
||||
}
|
||||
|
||||
pub fn blocking_write<W: Word>(&mut self, words: &[W]) -> Result<(), Error> {
|
||||
unsafe { T::REGS.cr1().modify(|w| w.set_spe(true)) }
|
||||
flush_rx_fifo(T::REGS);
|
||||
self.set_word_size(W::WORDSIZE);
|
||||
for word in words.iter() {
|
||||
@ -584,6 +585,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
||||
}
|
||||
|
||||
pub fn blocking_read<W: Word>(&mut self, words: &mut [W]) -> Result<(), Error> {
|
||||
unsafe { T::REGS.cr1().modify(|w| w.set_spe(true)) }
|
||||
flush_rx_fifo(T::REGS);
|
||||
self.set_word_size(W::WORDSIZE);
|
||||
for word in words.iter_mut() {
|
||||
@ -593,6 +595,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
||||
}
|
||||
|
||||
pub fn blocking_transfer_in_place<W: Word>(&mut self, words: &mut [W]) -> Result<(), Error> {
|
||||
unsafe { T::REGS.cr1().modify(|w| w.set_spe(true)) }
|
||||
flush_rx_fifo(T::REGS);
|
||||
self.set_word_size(W::WORDSIZE);
|
||||
for word in words.iter_mut() {
|
||||
@ -602,6 +605,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
||||
}
|
||||
|
||||
pub fn blocking_transfer<W: Word>(&mut self, read: &mut [W], write: &[W]) -> Result<(), Error> {
|
||||
unsafe { T::REGS.cr1().modify(|w| w.set_spe(true)) }
|
||||
flush_rx_fifo(T::REGS);
|
||||
self.set_word_size(W::WORDSIZE);
|
||||
let len = read.len().max(write.len());
|
||||
|
@ -68,6 +68,22 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
spi.read::<u8>(&mut []).await.unwrap();
|
||||
spi.write::<u8>(&[]).await.unwrap();
|
||||
|
||||
// === Check mixing blocking with async.
|
||||
spi.blocking_transfer(&mut buf, &data).unwrap();
|
||||
assert_eq!(buf, data);
|
||||
spi.transfer(&mut buf, &data).await.unwrap();
|
||||
assert_eq!(buf, data);
|
||||
spi.blocking_write(&buf).unwrap();
|
||||
spi.transfer(&mut buf, &data).await.unwrap();
|
||||
assert_eq!(buf, data);
|
||||
spi.blocking_read(&mut buf).unwrap();
|
||||
spi.blocking_write(&buf).unwrap();
|
||||
spi.write(&buf).await.unwrap();
|
||||
spi.read(&mut buf).await.unwrap();
|
||||
spi.blocking_write(&buf).unwrap();
|
||||
spi.blocking_read(&mut buf).unwrap();
|
||||
spi.write(&buf).await.unwrap();
|
||||
|
||||
info!("Test OK");
|
||||
cortex_m::asm::bkpt();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user