Skip to content
This repository has been archived by the owner on Jan 30, 2024. It is now read-only.

Commit

Permalink
Update probe-rs, probe-rs-rtt to 0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
korken89 committed Nov 25, 2021
1 parent a826c79 commit c3d4b65
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 40 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p

## [Unreleased]

- [#]
- [#285]: Update `probe-rs` and `probe-rs-rtt` to `0.12`

[#285]: https://github.com/knurling-rs/probe-run/pull/285

## [v0.3.0] - 2021-11-09

Expand Down
64 changes: 43 additions & 21 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ gimli = { version = "0.24", default-features = false }
git-version = "0.3"
log = "0.4"
object = { version = "0.24", default-features = false }
probe-rs = "0.11"
probe-rs-rtt = "0.11"
probe-rs = "0.12"
probe-rs-rtt = "0.12"
signal-hook = "0.3"
structopt = "0.3"

Expand Down
30 changes: 14 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ use std::{
path::Path,
process,
sync::atomic::{AtomicBool, Ordering},
sync::{Arc, Mutex},
sync::Arc,
time::Duration,
};

use anyhow::{anyhow, bail};
use colored::Colorize as _;
use defmt_decoder::{DecodeError, Frame, Locations, StreamDecoder};
use probe_rs::{
config::MemoryRegion,
flashing::{self, Format},
Core,
DebugProbeError::ProbeSpecific,
Expand Down Expand Up @@ -130,15 +131,15 @@ fn run_target_program(elf_path: &Path, chip_name: &str, opts: &cli::Opts) -> any
}
start_program(&mut sess, elf)?;

let sess = Arc::new(Mutex::new(sess));
let current_dir = &env::current_dir()?;

let halted_due_to_signal = extract_and_print_logs(elf, &sess, opts, current_dir)?;
let memory_map = sess.target().memory_map.clone();
let mut core = sess.core(0)?;

print_separator();
let halted_due_to_signal =
extract_and_print_logs(elf, &mut core, &memory_map, opts, current_dir)?;

let mut sess = sess.lock().unwrap();
let mut core = sess.core(0)?;
print_separator();

let canary_touched = canary
.map(|canary| canary.touched(&mut core, elf))
Expand Down Expand Up @@ -231,15 +232,16 @@ fn set_rtt_to_blocking(

fn extract_and_print_logs(
elf: &Elf,
sess: &Arc<Mutex<Session>>,
core: &mut probe_rs::Core,
memory_map: &[MemoryRegion],
opts: &cli::Opts,
current_dir: &Path,
) -> anyhow::Result<bool> {
let exit = Arc::new(AtomicBool::new(false));
let sig_id = signal_hook::flag::register(signal::SIGINT, exit.clone())?;

let mut logging_channel = if let Some(address) = elf.rtt_buffer_address() {
Some(setup_logging_channel(address, sess.clone())?)
Some(setup_logging_channel(address, core, memory_map)?)
} else {
eprintln!("RTT logs not available; blocking until the device halts..");
None
Expand Down Expand Up @@ -273,7 +275,7 @@ fn extract_and_print_logs(
let mut was_halted = false;
while !exit.load(Ordering::Relaxed) {
if let Some(logging_channel) = &mut logging_channel {
let num_bytes_read = match logging_channel.read(&mut read_buf) {
let num_bytes_read = match logging_channel.read(core, &mut read_buf) {
Ok(n) => n,
Err(e) => {
eprintln!("RTT error: {}", e);
Expand Down Expand Up @@ -303,8 +305,6 @@ fn extract_and_print_logs(
}
}

let mut sess = sess.lock().unwrap();
let mut core = sess.core(0)?;
let is_halted = core.core_halted()?;

if is_halted && was_halted {
Expand All @@ -321,9 +321,6 @@ fn extract_and_print_logs(
// TODO refactor: a printing fucntion shouldn't stop the MC as a side effect
// Ctrl-C was pressed; stop the microcontroller.
if exit.load(Ordering::Relaxed) {
let mut sess = sess.lock().unwrap();
let mut core = sess.core(0)?;

core.halt(TIMEOUT)?;
}

Expand Down Expand Up @@ -394,13 +391,14 @@ fn location_info(

fn setup_logging_channel(
rtt_buffer_address: u32,
sess: Arc<Mutex<Session>>,
core: &mut probe_rs::Core,
memory_map: &[MemoryRegion],
) -> anyhow::Result<UpChannel> {
const NUM_RETRIES: usize = 10; // picked at random, increase if necessary

let scan_region = ScanRegion::Exact(rtt_buffer_address);
for _ in 0..NUM_RETRIES {
match Rtt::attach_region(sess.clone(), &scan_region) {
match Rtt::attach_region(core, memory_map, &scan_region) {
Ok(mut rtt) => {
log::debug!("Successfully attached RTT");

Expand Down

0 comments on commit c3d4b65

Please sign in to comment.