Merge pull request #371 from bobmcwhirter/spi_v3_fix

Fix blocking-write for SPI.
This commit is contained in:
Bob McWhirter 2021-08-24 15:48:20 -04:00 committed by GitHub
commit 354ec75b74
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -171,6 +171,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
w.set_dsize(word_size.dsize()); w.set_dsize(word_size.dsize());
}); });
T::regs().cr1().modify(|w| { T::regs().cr1().modify(|w| {
w.set_csusp(false);
w.set_spe(true); w.set_spe(true);
}); });
} }
@ -375,8 +376,19 @@ impl<'d, T: Instance> embedded_hal::blocking::spi::Write<u8> for Spi<'d, T, NoDm
} }
if !sr.txp() { if !sr.txp() {
// loop waiting for TXE // loop waiting for TXE
continue;
} }
break;
} }
unsafe {
let rxdr = regs.rxdr().ptr() as *const u8;
// discard read to prevent pverrun.
let _ = ptr::read_volatile(rxdr);
}
}
while unsafe { !regs.sr().read().txc() } {
// spin
} }
Ok(()) Ok(())
@ -469,8 +481,20 @@ impl<'d, T: Instance> embedded_hal::blocking::spi::Write<u16> for Spi<'d, T, NoD
} }
if !sr.txp() { if !sr.txp() {
// loop waiting for TXE // loop waiting for TXE
continue;
} }
break;
} }
unsafe {
let rxdr = regs.rxdr().ptr() as *const u8;
// discard read to prevent pverrun.
let _ = ptr::read_volatile(rxdr);
}
}
while unsafe { !regs.sr().read().txc() } {
// spin
} }
Ok(()) Ok(())