From 1e2daa2c81ff29acb82fc9db139f9bfc7db562e5 Mon Sep 17 00:00:00 2001 From: Per Lindgren <per.lindgren@ltu.se> Date: Tue, 18 Feb 2020 00:11:41 +0100 Subject: [PATCH] bare0/1 polish --- examples/bare0.rs | 14 +++++-------- examples/bare1.rs | 50 +++++++++++++++++++++++++++++++++++++---------- 2 files changed, 45 insertions(+), 19 deletions(-) diff --git a/examples/bare0.rs b/examples/bare0.rs index fbd8cea..29ff386 100644 --- a/examples/bare0.rs +++ b/examples/bare0.rs @@ -15,19 +15,15 @@ // no standard main, we declare main using [entry] #![no_main] -// Minimal runtime / startup for Cortex-M microcontrollers -//extern crate cortex_m_rt as rt; // Panic handler, for textual output using semihosting -extern crate panic_semihosting; -// Panic handler, infinite loop on panic -// extern crate panic_halt; +use panic_semihosting as _; // import entry point use cortex_m_rt::entry; // a constant (cannot be changed at run-time) const X_INIT: u32 = 10; -//const X_INIT: u32 = core::u32::MAX; +// const X_INIT: u32 = core::u32::MAX; // global mutable variables (changed using unsafe code) static mut X: u32 = X_INIT; @@ -50,10 +46,10 @@ fn main() -> ! { // Here we assume you are using `vscode` with `cortex-debug`. // -// 0. Compile/build the example in debug (dev) mode. +// 0. Compile/build and run the example in debug (dev) mode. // -// > cargo build --example bare0 -// (or use the vscode build task) +// > cargo run --example bare0 +// (or use vscode) // // 1. Run the program in the debugger, let the program run for a while and // then press pause. diff --git a/examples/bare1.rs b/examples/bare1.rs index acd55f5..3c76d7c 100644 --- a/examples/bare1.rs +++ b/examples/bare1.rs @@ -10,7 +10,7 @@ #![no_main] #![no_std] -extern crate panic_itm; +use panic_itm as _; use cortex_m_rt::entry; @@ -49,14 +49,14 @@ fn main() -> ! { // // 1. Build and run the application // -// > cargo build --example bare1 -// (or use the vscode build task) +// > cargo run --example bare1 +// (or use the `itm fifo (debug)` or the `itm internal (debug)` launch configuration.) // -// Make sure you have followed the instructions for fifo `ITM` tracing. -// Debug using the `itm fifo (debug)` launch configuration. +// Make sure you have followed the instructions for fifo `ITM` tracing accordingly. // // When debugging the application it should hit the `bkpt` instruction. // What happens when you continue (second iteration of the loop)? +// (passing 3 breakpoints) // // ** your answer here ** // @@ -91,7 +91,7 @@ fn main() -> ! { // Rebuild `bare1.rs` in release (optimized mode). // // > cargo build --example bare1 --release -// (or using the vscode build task) +// (or using the vscode) // // Compare the generated assembly for the loop // between the dev (un-optimized) and release (optimized) build. @@ -109,6 +109,11 @@ fn main() -> ! { // // ** your answer here ** // +// Is there now any reference to the panic handler? +// If not, why is that the case? +// +// ** your answer here ** +// // commit your answers (bare1_3) // // Discussion: @@ -131,7 +136,32 @@ fn main() -> ! { // Later we will demonstrate how we can get guarantees of panic free execution. // This is very important to improve reliability. // -// 4. *Optional +// 4. Now comment out the `read_volatile`. +// +// > cargo build --example bare1 --release +// (or using the vscode) +// +// Compare the generated assembly for the loop +// between the dev (un-optimized) and release (optimized) build. +// +// What is the output of: +// > disassemble +// +// ** your answer here ** +// +// How many instructions are in between the two `bkpt` instructions. +// +// ** your answer here ** +// +// Where is the local variable stored? +// What happened, and why is Rust + LLVM allowed to do that? +// +// ** your answer here ** +// +// commit your answers (bare1_4) +// +// +// 5. *Optional // You can pass additional flags to the Rust `rustc` compiler. // // `-Z force-overflow-checks=off` @@ -144,11 +174,11 @@ fn main() -> ! { // // ** your answer here ** // -// commit your answers (bare1_4) +// commit your answers (bare1_5) // // Now restore the `.cargo/config` to its original state. // -// 5. *Optional +// 6. *Optional // There is another way to conveniently use wrapping arithmetics // without passing flags to the compiler. // @@ -164,7 +194,7 @@ fn main() -> ! { // // ** your answer here ** // -// commit your answers (bare1_5) +// commit your answers (bare1_6) // // Final discussion: // -- GitLab