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

Commit 6b9d66e

Browse files
DirbaioYatekii
authored andcommitted
Use 32bit accesses for RTT pointers to fix torn reads/writes.
1 parent f6fbf9e commit 6b9d66e

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

probe-rs-rtt/src/channel.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ impl Channel {
9494
}
9595

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

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

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

229229
Ok(total)
@@ -329,7 +329,7 @@ impl DownChannel {
329329

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

334334
Ok(total)
335335
}

0 commit comments

Comments
 (0)