Skip to content

Commit

Permalink
Always stop after reading.
Browse files Browse the repository at this point in the history
For some reason suspending causes subsequent reads to overrun.
  • Loading branch information
qwandor committed Apr 15, 2024
1 parent ba891a7 commit 1bbcccf
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions nrf-hal-common/src/twim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,17 +426,11 @@ where
compiler_fence(SeqCst);
unsafe { self.set_rx_buffer(buffer)? };

// Set appropriate lastrx shortcut.
if next_operation_write.is_none() {
self.0.shorts.write(|w| w.lastrx_stop().enabled());
} else {
#[cfg(not(any(
feature = "5340-app",
feature = "5340-net",
feature = "52832"
)))]
self.0.shorts.write(|w| w.lastrx_suspend().enabled());
}
// TODO: We should suspend rather than stopping if there are more operations to
// follow, but for some reason that results in an overrun error and reading bad
// data in the next read.
rtt_target::rprintln!("Stopping after read.");
self.0.shorts.write(|w| w.lastrx_stop().enabled());

// Start read.
self.0.tasks_startrx.write(|w| unsafe { w.bits(1) });
Expand Down Expand Up @@ -514,8 +508,10 @@ impl<T: Instance> I2c for Twim<T> {
// Copy the resulting data back to the various buffers.
for j in (0..=i).rev() {
if let Operation::Read(buffer) = &mut operations[j] {
buffer.copy_from_slice(&rx_copy[pending_rx_bytes-buffer.len()..pending_rx_bytes]);
pending_rx_bytes-= buffer.len();
buffer.copy_from_slice(
&rx_copy[pending_rx_bytes - buffer.len()..pending_rx_bytes],
);
pending_rx_bytes -= buffer.len();
} else {
break;
}
Expand Down

0 comments on commit 1bbcccf

Please sign in to comment.