Skip to content

Commit

Permalink
Merge pull request #2 from VitalBio/SPI-Robustness
Browse files Browse the repository at this point in the history
SPI Robustness
  • Loading branch information
sakian authored Apr 11, 2024
2 parents a917571 + db7e69b commit 488a248
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
7 changes: 7 additions & 0 deletions hal/src/sercom/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1267,6 +1267,13 @@ where
self.config.as_mut().regs.disable();
self.config
}

/// Disable and then re-enable the SPI peripheral
#[inline]
pub fn reset(&mut self) {
self.config.as_mut().regs.disable();
self.config.as_mut().regs.enable();
}
}

#[cfg(feature = "min-samd51g")]
Expand Down
7 changes: 4 additions & 3 deletions hal/src/sercom/spi/impl_ehal_thumbv7em.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,15 +291,16 @@ macro_rules! impl_blocking_spi_transfer {
let mut to_send = cells.iter();
let mut to_recv = cells.iter();
while to_recv.len() > 0 {
let flags = self.read_flags_errors()?;
if to_send.len() > 0 && flags.contains(Flags::DRE) {
if to_send.len() > 0 {
while !self.read_flags_errors()?.contains(Flags::DRE) {}
let word = match to_send.next() {
Some(cell) => cell.get(),
None => unreachable!(),
};
self.config.as_mut().regs.write_data(word as u32);
}
if to_recv.len() > to_send.len() && flags.contains(Flags::RXC) {
if to_recv.len() > to_send.len() {
while !self.read_flags_errors()?.contains(Flags::RXC) {}
let word = self.config.as_mut().regs.read_data() as Word<$Length>;
match to_recv.next() {
Some(cell) => cell.set(word),
Expand Down

0 comments on commit 488a248

Please sign in to comment.