From c2e88a26421efcf325b60e2aa51b300fc230aa29 Mon Sep 17 00:00:00 2001
From: Per <Per Lindgren>
Date: Mon, 13 Jan 2020 22:43:25 +0100
Subject: [PATCH] runner refactoring

---
 examples/f401_break.rs  |  32 --------------
 runner/Cargo.toml       |   3 ++
 runner/src/main.rs      |  91 ++++++++++++++++++++++------------------
 runner/test000001.ktest | Bin 140 -> 0 bytes
 4 files changed, 54 insertions(+), 72 deletions(-)
 delete mode 100644 examples/f401_break.rs
 delete mode 100644 runner/test000001.ktest

diff --git a/examples/f401_break.rs b/examples/f401_break.rs
deleted file mode 100644
index 90e5416..0000000
--- a/examples/f401_break.rs
+++ /dev/null
@@ -1,32 +0,0 @@
-// minimal example for the stm32-f401 (and the f4 series)
-//! Prints "Hello, world!" on the host console using semihosting
-
-#![no_main]
-#![no_std]
-
-extern crate panic_halt;
-
-use stm32f4::stm32f401 as stm32;
-
-use cortex_m::asm;
-use cortex_m_rt::entry;
-
-#[entry]
-fn main() -> ! {
-    asm::bkpt();
-
-    loop {}
-}
-
-// See RM0368 Reference Manual for details
-// https://www.st.com/content/ccc/resource/technical/document/reference_manual/5d/b1/ef/b2/a1/66/40/80/DM00096844.pdf/files/DM00096844.pdf/jcr:content/translations/en.DM00096844.pdf
-//
-// Memory map is given in `memory.x`, in particular we define:
-// 96k RAM starting at 0x2000_0000, and
-// 256k Flash starting at 0x0800_0000
-//
-// Run in separate terminal:
-// openocd -f openocd.cfg
-//
-// cargo run --example f401_minimal --features f4 --target thumbv7em-none-eabihf
-// This is the way!
diff --git a/runner/Cargo.toml b/runner/Cargo.toml
index b256a54..683ad6b 100644
--- a/runner/Cargo.toml
+++ b/runner/Cargo.toml
@@ -10,3 +10,6 @@ edition = "2018"
 probe-rs = { path = "../../probe-rs/probe-rs", version = "0.3.0" }
 ktest = { path = "../ktest", version = "0.1.0" }
 failure = "0.1.6"
+
+[lib]
+name = "runner"
\ No newline at end of file
diff --git a/runner/src/main.rs b/runner/src/main.rs
index 10c2815..5fcc857 100644
--- a/runner/src/main.rs
+++ b/runner/src/main.rs
@@ -13,6 +13,8 @@ use probe_rs::{
     target::info::{self, ChipInfo},
 };
 
+// don't look at this, its just testing some stuff...
+
 // le byte order
 fn main() {
     println!("read ktest file");
@@ -52,26 +54,25 @@ fn main() {
 
     // println!("... done");
 
-    let cpu_info = session
-        .target
-        .core
-        .reset_and_halt(&mut session.probe)
-        .unwrap();
-    println!("Core stopped at address 0x{:08x}", cpu_info.pc);
+    // let data = session.probe.read32(0x0000_0000).unwrap();
+    // println!("stack 0x{:08x}", data);
 
-    let data = session.probe.read32(0x0000_0000).unwrap();
-    println!("stack 0x{:08x}", data);
+    // let data = session.probe.read32(0x0000_0004).unwrap();
+    // println!("reset 0x{:08x}", data);
 
-    let data = session.probe.read32(0x0000_0004).unwrap();
-    println!("reset 0x{:08x}", data);
+    // run_to_halt(&mut session);
 
-    run_to_halt(&mut session);
-    cycnt_enable(&mut session);
-    cycnt_reset(&mut session);
-    run_to_halt(&mut session);
-    let cyccnt = cycnt_read(&mut session);
-    println!("cyccnt {}", cyccnt);
-    run_to_halt(&mut session);
+    // cycnt_enable(&mut session);
+    // cycnt_reset(&mut session);
+
+    // let cyccnt = cycnt_read(&mut session);
+    // println!("cyccnt {}", cyccnt);
+
+    // run_to_halt(&mut session);
+    // let cyccnt = cycnt_read(&mut session);
+    // println!("cyccnt {}", cyccnt);
+
+    // run_to_halt(&mut session);
 
     // session
     //     .target
@@ -94,23 +95,15 @@ fn main() {
     // let cpu_info = session.target.core.step(&mut session.probe).unwrap();
     // println!("Core stopped at address 0x{:08x}", cpu_info.pc);
 
-    // for (name, data) in ktest.objects {
-    //     println!("run {}", name);
-    //     session.target.core.run(&mut session.probe).unwrap();
-
-    //     session
-    //         .target
-    //         .core
-    //         .wait_for_core_halted(&mut session.probe)
-    //         .unwrap();
-
-    //     let cpu_info = session.target.core.halt(&mut session.probe).unwrap();
-    //     println!("Core stopped at address 0x{:08x}", cpu_info.pc);
+    reset_and_halt(&mut session);
+    run_to_halt(&mut session);
 
-    //     set_symbolic(&mut session, &data);
-    // }
+    for (name, data) in ktest.objects {
+        set_symbolic(&mut session, &data);
+        run_to_halt(&mut session);
+    }
 
-    // println!("done and run");
+    println!("done");
     // session.target.core.run(&mut session.probe).unwrap();
 
     // session
@@ -122,6 +115,20 @@ fn main() {
     // println!("breapoint reached");
 }
 
+// resets the target and run
+fn reset_and_run(session: &mut Session) {
+    session.target.core.reset(&mut session.probe).unwrap();
+}
+
+// resets the target and halts
+fn reset_and_halt(session: &mut Session) {
+    session
+        .target
+        .core
+        .reset_and_halt(&mut session.probe)
+        .unwrap();
+}
+
 fn read_bkpt(session: &mut Session) -> Option<u8> {
     // try to read the program counter
     let pc_value = session
@@ -170,14 +177,18 @@ fn run_to_halt(session: &mut Session) {
     }
     session.target.core.run(&mut session.probe).unwrap();
     println!("running");
-    session
-        .target
-        .core
-        .wait_for_core_halted(&mut session.probe)
-        .unwrap();
+    match session.target.core.wait_for_core_halted(&mut session.probe) {
+        Ok(_) => {
+            print!("Hit breakpoint :",);
+        }
+        Err(DebugProbeError::Timeout) => {
+            print!("Timeout :");
+        }
+        Err(err) => panic!("internal error:{:?}", err),
+    }
 
     let cpu_info = session.target.core.halt(&mut session.probe).unwrap();
-    println!("Run: Core stopped at address 0x{:08x}", cpu_info.pc);
+    println!("Core stopped at address 0x{:08x}", cpu_info.pc);
 }
 // index is the oject number
 fn set_symbolic(session: &mut Session, data: &[u8]) {
@@ -189,8 +200,8 @@ fn set_symbolic(session: &mut Session, data: &[u8]) {
 
     println!("r0 0x{:08x}", r0);
     println!("object {:?}", data);
-    session.target.core.step(&mut session.probe).unwrap();
-    // let r0 = session.probe.write_block8(r0, data).unwrap();
+    // session.target.core.step(&mut session.probe).unwrap();
+    let r0 = session.probe.write_block8(r0, data).unwrap();
 }
 
 fn open_probe() -> MasterProbe {
diff --git a/runner/test000001.ktest b/runner/test000001.ktest
deleted file mode 100644
index e0675e4eaf2e957beb5b60306e08631bf34cad67..0000000000000000000000000000000000000000
GIT binary patch
literal 0
HcmV?d00001

literal 140
zcmeYcaSaY(U|?WoU|?WmU|@*T&&bbB)i21&(=RG5F3~Rmk(nj>**U4Hx~Ub3xdl0?
z#rh?QMd_&}`bDWZsfop@`f%~0)bz~alGLL3lGNf7-P9Dbl+>hDLz6_q<P-}F3%#5i
S1_S`v##)w~3KnDmi30%2T_-gF

-- 
GitLab