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

Commit

Permalink
Merge pull request #69 from knurling-rs/blocking-rtt
Browse files Browse the repository at this point in the history
toggle RTT mode after RAM initialization
  • Loading branch information
Jonas Schievink committed Sep 22, 2020
2 parents dcacbbc + 7f7f0d3 commit df90d57
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ fn notmain() -> Result<i32, anyhow::Error> {
})
.collect::<HashSet<_>>();

let (rtt_addr, uses_heap) = rtt_and_heap_info_from(&elf)?;
let (rtt_addr, uses_heap, main) = get_rtt_heap_main_from(&elf)?;

let vector_table = vector_table.ok_or_else(|| anyhow!("`.vector_table` section is missing"))?;
log::debug!("vector table: {:x?}", vector_table);
Expand Down Expand Up @@ -333,10 +333,23 @@ fn notmain() -> Result<i32, anyhow::Error> {

log::debug!("starting device");
if core.get_available_breakpoint_units()? == 0 {
log::warn!("device doesn't support HW breakpoints; HardFault will NOT make `probe-run` exit with an error code");
} else {
core.set_hw_breakpoint(vector_table.hard_fault & !THUMB_BIT)?;
if rtt_addr.is_some() {
bail!("RTT not supported on device without HW breakpoints");
} else {
log::warn!("device doesn't support HW breakpoints; HardFault will NOT make `probe-run` exit with an error code");
}
}

if let Some(rtt) = rtt_addr {
core.set_hw_breakpoint(main)?;
core.run()?;
const OFFSET: u32 = 44;
const FLAG: u32 = 2; // BLOCK_IF_FULL
core.write_word_32(rtt + OFFSET, FLAG)?;
core.clear_hw_breakpoint(main)?;
}

core.set_hw_breakpoint(vector_table.hard_fault & !THUMB_BIT)?;
core.run()?;
}

Expand Down Expand Up @@ -920,11 +933,12 @@ impl Stacked {
}
}

fn rtt_and_heap_info_from(
fn get_rtt_heap_main_from(
elf: &ElfFile,
) -> Result<(Option<u32>, bool /* uses heap */), anyhow::Error> {
) -> Result<(Option<u32>, bool /* uses heap */, u32), anyhow::Error> {
let mut rtt = None;
let mut uses_heap = false;
let mut main = None;

for (_, symbol) in elf.symbols() {
let name = match symbol.name() {
Expand All @@ -933,6 +947,7 @@ fn rtt_and_heap_info_from(
};

match name {
"main" => main = Some(symbol.address() as u32 & !THUMB_BIT),
"_SEGGER_RTT" => rtt = Some(symbol.address() as u32),
"__rust_alloc" | "__rg_alloc" | "__rdl_alloc" | "malloc" if !uses_heap => {
log::debug!("symbol `{}` indicates heap is in use", name);
Expand All @@ -942,7 +957,11 @@ fn rtt_and_heap_info_from(
}
}

Ok((rtt, uses_heap))
Ok((
rtt,
uses_heap,
main.ok_or_else(|| anyhow!("`main` symbol not found"))?,
))
}

const LR: CoreRegisterAddress = CoreRegisterAddress(14);
Expand Down

0 comments on commit df90d57

Please sign in to comment.