diff --git a/beginner/apps/Cargo.toml b/beginner/apps/Cargo.toml index a5483c0..6c75a25 100644 --- a/beginner/apps/Cargo.toml +++ b/beginner/apps/Cargo.toml @@ -18,7 +18,7 @@ debug = 1 debug-assertions = true # ! incremental = false lto = "fat" -opt-level = 'z' # ! +opt-level = 0 overflow-checks = false [profile.release] diff --git a/tools/Cargo.lock b/tools/Cargo.lock index 9d6fbe9..c2b3b84 100644 --- a/tools/Cargo.lock +++ b/tools/Cargo.lock @@ -169,6 +169,7 @@ dependencies = [ "probe-rs", "probe-rs-rtt", "rustc-demangle", + "thiserror", "xmas-elf", ] diff --git a/tools/dk-run/Cargo.toml b/tools/dk-run/Cargo.toml index fdac90b..1dbdd3d 100644 --- a/tools/dk-run/Cargo.toml +++ b/tools/dk-run/Cargo.toml @@ -15,3 +15,4 @@ probe-rs = "0.6.2" probe-rs-rtt = "0.1.0" rustc-demangle = "0.1.16" xmas-elf = "0.7.0" +thiserror = "1.0.11" diff --git a/tools/dk-run/src/main.rs b/tools/dk-run/src/main.rs index 43b7504..2ac912c 100644 --- a/tools/dk-run/src/main.rs +++ b/tools/dk-run/src/main.rs @@ -13,6 +13,7 @@ use std::{ process, rc::Rc, }; +use core::fmt::Error; use anyhow::{anyhow, bail}; use arrayref::array_ref; @@ -192,17 +193,42 @@ fn notmain() -> Result { // run let core = Rc::new(core); - let mut rtt = Rtt::attach_region( - core.clone(), - &sess, - &ScanRegion::Exact(rtt_addr.ok_or_else(|| anyhow!("RTT control block not available"))?), - )?; + let mut num_retries = 5; + + let mut rtt: Result; + + loop { + // TODO how do i best to this without allocating two rtts + rtt = Rtt::attach_region( + core.clone(), + &sess, + &ScanRegion::Exact(rtt_addr.ok_or_else(|| anyhow!("RTT control block not available"))?), // todo only do this once? + ); + + // todo clean up control flow + if rtt.is_ok() { + log::info!("successfully attached rtt"); + break; + } + + num_retries -= 1; + if num_retries == 0 { + // todo return last err instead + break; + } + log::info!("Rtt::attach_region failed. retrying."); + } + + log::info!("go rtt"); let channel = rtt + .unwrap() .up_channels() .take(0) .ok_or_else(|| anyhow!("RTT up channel 0 not found"))?; + log::info!("chan"); + static CONTINUE: AtomicBool = AtomicBool::new(true); ctrlc::set_handler(|| {