Skip to content

Commit b377bcd

Browse files
committed
chore(deps): upgrade probe-rs and probe-rs-rtt to ^0.12.0
<https://github.com/probe-rs/probe-rs/blob/master/CHANGELOG.md#0120>: > ## Changed > > [...] > > - Breaking API: Modify `probe-rs-rtt` interfaces to use `probe_rs:: > Core` rather than `Arc<Mutex<probe_rs::Session>>`.
1 parent c7f2f32 commit b377bcd

File tree

3 files changed

+63
-60
lines changed

3 files changed

+63
-60
lines changed

Cargo.lock

Lines changed: 23 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/r3_test_runner/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ r3_test_suite = { path = "../r3_test_suite", default-features = false }
1111
arg_enum_proc_macro = { version = "0.3.0" }
1212
aho-corasick = { version = "0.7.13" }
1313
futures-core = { version = "0.3.5" }
14-
probe-rs-rtt = { version = "0.11.0" }
14+
probe-rs-rtt = { version = "0.12.0" }
1515
tokio-serial = { version = "5.4.1" }
1616
lazy_static = { version = "1.4.0" }
1717
env_logger = { version = "0.8.4" }
@@ -20,7 +20,7 @@ serialport = { version = "4.0.0" }
2020
itertools = { version = "0.10.0" }
2121
pin-utils = { version = "0.1.0" }
2222
thiserror = { version = "1.0.20" }
23-
probe-rs = { version = "0.11.0" }
23+
probe-rs = { version = "0.12.0" }
2424
tempdir = { version = "0.3.7" }
2525
anyhow = { version = "1.0.32" }
2626
serde = { version = "1.0.114" }

src/r3_test_runner/src/targets/probe_rs.rs

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -190,17 +190,24 @@ pub async fn attach_rtt(
190190
let rtt_scan_region = rtt_scan_region.clone();
191191

192192
let result = spawn_blocking(move || {
193-
let _halt_guard = if halt_on_access {
194-
Some(CoreHaltGuard::new(session.clone()).map_err(AttachRttError::HaltCore)?)
193+
let mut session = session.lock().unwrap();
194+
let memory_map = session.target().memory_map.clone();
195+
let mut core = session.core(0).map_err(AttachRttError::HaltCore)?;
196+
let halt_guard;
197+
let core = if halt_on_access {
198+
halt_guard = CoreHaltGuard::new(&mut core).map_err(AttachRttError::HaltCore)?;
199+
&mut *halt_guard.core
195200
} else {
196-
None
201+
&mut core
197202
};
198203

199-
match probe_rs_rtt::Rtt::attach_region(session, &rtt_scan_region) {
200-
Ok(rtt) => Ok(Some(rtt)),
201-
Err(probe_rs_rtt::Error::ControlBlockNotFound) => Ok(None),
202-
Err(e) => Err(AttachRttError::AttachRtt(e)),
203-
}
204+
let result = match probe_rs_rtt::Rtt::attach_region(core, &memory_map, &rtt_scan_region)
205+
{
206+
Ok(rtt) => Some(rtt),
207+
Err(probe_rs_rtt::Error::ControlBlockNotFound) => None,
208+
Err(e) => return Err(AttachRttError::AttachRtt(e)),
209+
};
210+
Ok(result)
204211
})
205212
.await
206213
.unwrap()?;
@@ -244,34 +251,20 @@ fn find_rtt_symbol(elf_bytes: &[u8]) -> Option<u64> {
244251
}
245252

246253
/// Halts the first core while this RAII guard is held.
247-
struct CoreHaltGuard(Arc<Mutex<probe_rs::Session>>);
248-
249-
impl CoreHaltGuard {
250-
fn new(session: Arc<Mutex<probe_rs::Session>>) -> Result<Self, probe_rs::Error> {
251-
{
252-
let mut session = session.lock().unwrap();
253-
let mut core = session.core(0)?;
254-
core.halt(std::time::Duration::from_millis(100))?;
255-
}
254+
struct CoreHaltGuard<'a, 'probe> {
255+
core: &'a mut probe_rs::Core<'probe>,
256+
}
256257

257-
Ok(Self(session))
258+
impl<'a, 'probe> CoreHaltGuard<'a, 'probe> {
259+
fn new(core: &'a mut probe_rs::Core<'probe>) -> Result<Self, probe_rs::Error> {
260+
core.halt(std::time::Duration::from_millis(100))?;
261+
Ok(Self { core })
258262
}
259263
}
260264

261-
impl Drop for CoreHaltGuard {
265+
impl Drop for CoreHaltGuard<'_, '_> {
262266
fn drop(&mut self) {
263-
let mut session = self.0.lock().unwrap();
264-
let mut core = match session.core(0) {
265-
Ok(x) => x,
266-
Err(e) => {
267-
log::warn!(
268-
"Failed to get the core object while restarting the core (ignored): {:?}",
269-
e
270-
);
271-
return;
272-
}
273-
};
274-
if let Err(e) = core.run() {
267+
if let Err(e) = self.core.run() {
275268
log::warn!("Failed to restart the core (ignored): {:?}", e);
276269
}
277270
}
@@ -448,20 +441,27 @@ impl ReadRtt {
448441
buf: &mut [u8],
449442
halt_on_access: bool,
450443
) -> tokio::io::Result<usize> {
451-
let _halt_guard = if halt_on_access {
452-
Some(
453-
CoreHaltGuard::new(session)
454-
.map_err(|e| tokio::io::Error::new(tokio::io::ErrorKind::Other, e))?,
455-
)
444+
// FIXME: Hold the lock in `ReadRtt`; it's pointless to be able to have
445+
// two instances of `ReadRtt` pointing to the same `Session` and
446+
// performing interleaved reads
447+
let mut session = session.lock().unwrap();
448+
let mut core = session
449+
.core(0)
450+
.map_err(|e| tokio::io::Error::new(tokio::io::ErrorKind::Other, e))?;
451+
let halt_guard;
452+
let core = if halt_on_access {
453+
halt_guard = CoreHaltGuard::new(&mut core)
454+
.map_err(|e| tokio::io::Error::new(tokio::io::ErrorKind::Other, e))?;
455+
&mut *halt_guard.core
456456
} else {
457-
None
457+
&mut core
458458
};
459459

460460
let mut num_read_bytes = 0;
461461

462462
for (i, channel) in rtt.up_channels().iter().enumerate() {
463463
let num_ch_read_bytes = channel
464-
.read(buf)
464+
.read(core, buf)
465465
.map_err(|e| tokio::io::Error::new(tokio::io::ErrorKind::Other, e))?;
466466

467467
if num_ch_read_bytes != 0 {

0 commit comments

Comments
 (0)