Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions probe-plotter-tools/src/bin/custom-viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ use std::{env, io::Read, sync::mpsc, thread, time::Duration};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let help = "Usage: \nprobe-plotter /path/to/elf [chip] [update_rate_ms=10] [channel_mode=no change]";
let help =
"Usage: \nprobe-plotter /path/to/elf [chip] [update_rate_ms=10] [channel_mode=no change]";

let elf_path = env::args().nth(1).expect(help);

Expand Down Expand Up @@ -39,7 +40,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
.read_to_end(&mut elf_bytes)
.unwrap();

let (metrics, settings) = parse(&elf_bytes);
let (metrics, settings, scan_region) = parse(&elf_bytes);

let main_thread_token = rerun::MainThreadToken::i_promise_i_am_on_the_main_thread();

Expand Down Expand Up @@ -78,6 +79,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
&elf_bytes,
settings,
metrics,
scan_region,
settings_update_receiver,
initial_settings_sender,
)
Expand Down
2 changes: 1 addition & 1 deletion probe-plotter-tools/src/bin/minimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn main() {
let mut session = probe_rs::Session::auto_attach(target, Default::default()).unwrap();
let mut core = session.core(0).unwrap();

let (mut metrics, _settings) = parse_elf_file(&elf_path);
let (mut metrics, _settings, _) = parse_elf_file(&elf_path);
for m in &metrics {
println!("{}: {}", m.name, m.address);
}
Expand Down
22 changes: 14 additions & 8 deletions probe-plotter-tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use defmt_parser::Level;
use object::{Object, ObjectSymbol};
use probe_rs::{
Core, MemoryInterface,
rtt::{ChannelMode, Rtt},
rtt::{self, ChannelMode, Rtt},
};
use rerun::TextLogLevel;
use serde::Deserialize;
Expand Down Expand Up @@ -47,17 +47,24 @@ pub enum Type {
}

// Most of this is taken from https://github.com/knurling-rs/defmt/blob/8e517f8d7224237893e39337a61de8ef98b341f2/decoder/src/elf2table/mod.rs and modified
pub fn parse(elf_bytes: &[u8]) -> (Vec<Metric>, Vec<Setting>) {
pub fn parse(elf_bytes: &[u8]) -> (Vec<Metric>, Vec<Setting>, rtt::ScanRegion) {
let elf = object::File::parse(elf_bytes).unwrap();

let mut metrics = Vec::new();
let mut settings = Vec::new();

let mut scan_region = rtt::ScanRegion::Ram;

for entry in elf.symbols() {
let Ok(name) = entry.name() else {
continue;
};

if name == "_SEGGER_RTT" {
scan_region = rtt::ScanRegion::Exact(entry.address());
continue;
}

let Ok(sym) = Symbol::demangle(name) else {
continue;
};
Expand Down Expand Up @@ -98,20 +105,18 @@ pub fn parse(elf_bytes: &[u8]) -> (Vec<Metric>, Vec<Setting>) {
}
}

(metrics, settings)
(metrics, settings, scan_region)
}

/// Parse elf file into a set of Metrics and Settings
pub fn parse_elf_file(elf_path: &str) -> (Vec<Metric>, Vec<Setting>) {
pub fn parse_elf_file(elf_path: &str) -> (Vec<Metric>, Vec<Setting>, rtt::ScanRegion) {
let mut buffer = Vec::new();
std::fs::File::open(elf_path)
.unwrap()
.read_to_end(&mut buffer)
.unwrap();

let (metrics, settings) = parse(&buffer);

(metrics, settings)
parse(&buffer)
}

/// A background task which communicates with the probe
Expand All @@ -129,12 +134,13 @@ pub fn probe_background_thread(
elf_bytes: &[u8],
mut settings: Vec<Setting>,
mut metrics: Vec<Metric>,
scan_region: rtt::ScanRegion,
settings_update_receiver: mpsc::Receiver<Setting>,
initial_settings_sender: mpsc::Sender<Vec<Setting>>,
) {
let mut session = probe_rs::Session::auto_attach(target, Default::default()).unwrap();
let mut core = session.core(0).unwrap();
let mut rtt = Rtt::attach(&mut core).unwrap();
let mut rtt = Rtt::attach_region(&mut core, &scan_region).unwrap();
let table = defmt_decoder::Table::parse(elf_bytes).unwrap().unwrap();

// TODO: Get this to work
Expand Down
Loading