diff --git a/.cargo/config b/.cargo/config index 5d4b78a7cab49ca9c8bbe8d076af420fee86624f..9fbb6a5c92c04e1a177e9707faebe74d4468fd27 100644 --- a/.cargo/config +++ b/.cargo/config @@ -6,9 +6,9 @@ # uncomment ONE of these three option to make `cargo run` start a GDB session # which option to pick depends on your system # runner = "arm-none-eabi-gdb -q -x openocd.gdb" -# runner = "gdb-multiarch -q -x openocd.gdb" +runner = "gdb-multiarch -q -x openocd.gdb" # runner = "gdb -q -x openocd.gdb" -runner = "probe-run --chip STM32F411RETx" +# runner = "probe-run --chip STM32F411RETx" rustflags = [ # This is needed if your flash or ram addresses are not aligned to 0x10000 in memory.x diff --git a/examples/rtt_timing.rs b/examples/rtt_timing.rs index 4a376ae7e81df5aab46270fe2d1b9a66ec7775a5..13796fab64639cc6fcd5d322ec29e8f7bade7dd3 100644 --- a/examples/rtt_timing.rs +++ b/examples/rtt_timing.rs @@ -102,7 +102,7 @@ fn timed_loop() -> (u32, u32) { // Why do you think it differs that much? // // [Your answer here] -// I think that the optimizer removed the for loop: +// I think that the optimizer removes the for loop: // for _ in 0..10000 { // asm::nop(); // } @@ -234,11 +234,45 @@ fn timed_loop() -> (u32, u32) { // https://developer.arm.com/documentation/ddi0439/b/Data-Watchpoint-and-Trace-Unit/DWT-Programmers-Model // // [Your answer here] +// No, there is no function call. The two following line loads in the loaction of the cycle count, +// which is always updated. Thus r1 holds the location of the cycle counter. +// 0x08000232 <+0>: movw r1, #4100 ; 0x1004 +// 0x0800023a <+8>: movt r1, #57344 ; 0xe000 +// Then the two following lines loads in the current cycle value for start(r0) and end(r1). +// 0x0800023e <+12>: ldr r0, [r1, #0] +// 0x08000246 <+20>: ldr r1, [r1, #0] +// // // Now check your answer by dumping the registers // (gdb) info registers // // [Register dump here] +// (gdb) info registers +// r0 0x80000000 -2147483648 +// r1 0xe0001004 -536866812 +// r2 0x2710 10000 +// r3 0xa 10 +// r4 0x20000000 536870912 +// r5 0x20000430 536871984 +// r6 0x0 0 +// r7 0x2000ffe8 536936424 +// r8 0x0 0 +// r9 0x0 0 +// r10 0x0 0 +// r11 0x0 0 +// r12 0x1 1 +// sp 0x2000ff98 0x2000ff98 +// lr 0x8000373 134218611 +// pc 0x800023e 0x800023e <rtt_timing::timed_loop+12> +// xPSR 0x81000000 -2130706432 +// fpscr 0x0 0 +// msp 0x2000ff98 0x2000ff98 +// psp 0x0 0x0 +// primask 0x1 1 +// basepri 0x0 0 +// faultmask 0x0 0 +// control 0x0 0 +// // // We can now set a breakpoint exactly at the `nop`. // @@ -248,7 +282,7 @@ fn timed_loop() -> (u32, u32) { // (gdb) continue // // (gdb) disassemble -// 0x08000232 <+0>: movw r1, #4100 ; 0x1004 +// 0x08000232 <+0>: movw r1, #4100 ; 0x1004 // 0x08000236 <+4>: movw r2, #10000 ; 0x2710 // 0x0800023a <+8>: movt r1, #57344 ; 0xe000 // 0x0800023e <+12>: ldr r0, [r1, #0] @@ -264,6 +298,7 @@ fn timed_loop() -> (u32, u32) { // (gdb) x 0xe0001004 // // [Your answer here] +// 0x31de3cd8 // // Now, let's execute one iteration: // (gdb) continue @@ -271,10 +306,12 @@ fn timed_loop() -> (u32, u32) { // What is now the current value of the cycle counter? // // [Your answer here] +// 0x31de3cdc // // By how much does the cycle counter increase for each iteration? // // [Your answer here] +// 4 // // ------------------------------------------------------------------------ // F) Reseting the cycle counter