Skip to content
This repository has been archived by the owner on Aug 27, 2021. It is now read-only.

Commit

Permalink
Use 32bit accesses for RTT pointers to fix torn reads/writes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dirbaio authored and Yatekii committed Nov 25, 2020
1 parent f6fbf9e commit 6b9d66e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions probe-rs-rtt/src/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ impl Channel {
}

fn read_pointers(&self, dir: &'static str) -> Result<(u32, u32), Error> {
let mut block = [0u8; 8];
let mut block = [0u32; 2];
self.session
.lock()
.unwrap()
.core(0)?
.read_8(self.ptr + Self::O_WRITE as u32, block.as_mut())?;
.read_32(self.ptr + Self::O_WRITE as u32, block.as_mut())?;

let write: u32 = block.pread_with(0, LE).unwrap();
let read: u32 = block.pread_with(4, LE).unwrap();
let write: u32 = block[0];
let read: u32 = block[1];

let validate = |which, value| {
if value >= self.size {
Expand Down Expand Up @@ -223,7 +223,7 @@ impl UpChannel {
// Write read pointer back to target if something was read
let mut lock = self.0.session.lock().unwrap();
let mut core = lock.core(0)?;
core.write_8(self.0.ptr + Channel::O_READ as u32, &read.to_le_bytes())?;
core.write_word_32(self.0.ptr + Channel::O_READ as u32, read)?;
}

Ok(total)
Expand Down Expand Up @@ -329,7 +329,7 @@ impl DownChannel {

let mut lock = self.0.session.lock().unwrap();
let mut core = lock.core(0)?;
core.write_8(self.0.ptr + Channel::O_WRITE as u32, &write.to_le_bytes())?;
core.write_word_32(self.0.ptr + Channel::O_WRITE as u32, write)?;

Ok(total)
}
Expand Down

0 comments on commit 6b9d66e

Please sign in to comment.