Skip to content
Snippets Groups Projects
Commit c2e88a26 authored by Per's avatar Per
Browse files

runner refactoring

parent 4de57d13
No related branches found
No related tags found
No related merge requests found
// 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!
...@@ -10,3 +10,6 @@ edition = "2018" ...@@ -10,3 +10,6 @@ edition = "2018"
probe-rs = { path = "../../probe-rs/probe-rs", version = "0.3.0" } probe-rs = { path = "../../probe-rs/probe-rs", version = "0.3.0" }
ktest = { path = "../ktest", version = "0.1.0" } ktest = { path = "../ktest", version = "0.1.0" }
failure = "0.1.6" failure = "0.1.6"
[lib]
name = "runner"
\ No newline at end of file
...@@ -13,6 +13,8 @@ use probe_rs::{ ...@@ -13,6 +13,8 @@ use probe_rs::{
target::info::{self, ChipInfo}, target::info::{self, ChipInfo},
}; };
// don't look at this, its just testing some stuff...
// le byte order // le byte order
fn main() { fn main() {
println!("read ktest file"); println!("read ktest file");
...@@ -52,26 +54,25 @@ fn main() { ...@@ -52,26 +54,25 @@ fn main() {
// println!("... done"); // println!("... done");
let cpu_info = session // let data = session.probe.read32(0x0000_0000).unwrap();
.target // println!("stack 0x{:08x}", data);
.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(); // let data = session.probe.read32(0x0000_0004).unwrap();
println!("stack 0x{:08x}", data); // println!("reset 0x{:08x}", data);
let data = session.probe.read32(0x0000_0004).unwrap(); // run_to_halt(&mut session);
println!("reset 0x{:08x}", data);
run_to_halt(&mut session); // cycnt_enable(&mut session);
cycnt_enable(&mut session); // cycnt_reset(&mut session);
cycnt_reset(&mut session);
run_to_halt(&mut session); // let cyccnt = cycnt_read(&mut session);
let cyccnt = cycnt_read(&mut session); // println!("cyccnt {}", cyccnt);
println!("cyccnt {}", cyccnt);
run_to_halt(&mut session); // run_to_halt(&mut session);
// let cyccnt = cycnt_read(&mut session);
// println!("cyccnt {}", cyccnt);
// run_to_halt(&mut session);
// session // session
// .target // .target
...@@ -94,23 +95,15 @@ fn main() { ...@@ -94,23 +95,15 @@ fn main() {
// let cpu_info = session.target.core.step(&mut session.probe).unwrap(); // let cpu_info = session.target.core.step(&mut session.probe).unwrap();
// println!("Core stopped at address 0x{:08x}", cpu_info.pc); // println!("Core stopped at address 0x{:08x}", cpu_info.pc);
// for (name, data) in ktest.objects { reset_and_halt(&mut session);
// println!("run {}", name); run_to_halt(&mut session);
// 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);
// 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.target.core.run(&mut session.probe).unwrap();
// session // session
...@@ -122,6 +115,20 @@ fn main() { ...@@ -122,6 +115,20 @@ fn main() {
// println!("breapoint reached"); // 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> { fn read_bkpt(session: &mut Session) -> Option<u8> {
// try to read the program counter // try to read the program counter
let pc_value = session let pc_value = session
...@@ -170,14 +177,18 @@ fn run_to_halt(session: &mut Session) { ...@@ -170,14 +177,18 @@ fn run_to_halt(session: &mut Session) {
} }
session.target.core.run(&mut session.probe).unwrap(); session.target.core.run(&mut session.probe).unwrap();
println!("running"); println!("running");
session match session.target.core.wait_for_core_halted(&mut session.probe) {
.target Ok(_) => {
.core print!("Hit breakpoint :",);
.wait_for_core_halted(&mut session.probe) }
.unwrap(); Err(DebugProbeError::Timeout) => {
print!("Timeout :");
}
Err(err) => panic!("internal error:{:?}", err),
}
let cpu_info = session.target.core.halt(&mut session.probe).unwrap(); 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 // index is the oject number
fn set_symbolic(session: &mut Session, data: &[u8]) { fn set_symbolic(session: &mut Session, data: &[u8]) {
...@@ -189,8 +200,8 @@ 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!("r0 0x{:08x}", r0);
println!("object {:?}", data); println!("object {:?}", data);
session.target.core.step(&mut session.probe).unwrap(); // session.target.core.step(&mut session.probe).unwrap();
// let r0 = session.probe.write_block8(r0, data).unwrap(); let r0 = session.probe.write_block8(r0, data).unwrap();
} }
fn open_probe() -> MasterProbe { fn open_probe() -> MasterProbe {
......
File deleted
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment