Skip to content
Snippets Groups Projects
Commit 1e2daa2c authored by Per Lindgren's avatar Per Lindgren
Browse files

bare0/1 polish

parent c45dc28a
Branches
No related tags found
No related merge requests found
...@@ -15,19 +15,15 @@ ...@@ -15,19 +15,15 @@
// no standard main, we declare main using [entry] // no standard main, we declare main using [entry]
#![no_main] #![no_main]
// Minimal runtime / startup for Cortex-M microcontrollers
//extern crate cortex_m_rt as rt;
// Panic handler, for textual output using semihosting // Panic handler, for textual output using semihosting
extern crate panic_semihosting; use panic_semihosting as _;
// Panic handler, infinite loop on panic
// extern crate panic_halt;
// import entry point // import entry point
use cortex_m_rt::entry; use cortex_m_rt::entry;
// a constant (cannot be changed at run-time) // a constant (cannot be changed at run-time)
const X_INIT: u32 = 10; 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) // global mutable variables (changed using unsafe code)
static mut X: u32 = X_INIT; static mut X: u32 = X_INIT;
...@@ -50,10 +46,10 @@ fn main() -> ! { ...@@ -50,10 +46,10 @@ fn main() -> ! {
// Here we assume you are using `vscode` with `cortex-debug`. // 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 // > cargo run --example bare0
// (or use the vscode build task) // (or use vscode)
// //
// 1. Run the program in the debugger, let the program run for a while and // 1. Run the program in the debugger, let the program run for a while and
// then press pause. // then press pause.
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
#![no_main] #![no_main]
#![no_std] #![no_std]
extern crate panic_itm; use panic_itm as _;
use cortex_m_rt::entry; use cortex_m_rt::entry;
...@@ -49,14 +49,14 @@ fn main() -> ! { ...@@ -49,14 +49,14 @@ fn main() -> ! {
// //
// 1. Build and run the application // 1. Build and run the application
// //
// > cargo build --example bare1 // > cargo run --example bare1
// (or use the vscode build task) // (or use the `itm fifo (debug)` or the `itm internal (debug)` launch configuration.)
// //
// Make sure you have followed the instructions for fifo `ITM` tracing. // Make sure you have followed the instructions for fifo `ITM` tracing accordingly.
// Debug using the `itm fifo (debug)` launch configuration.
// //
// When debugging the application it should hit the `bkpt` instruction. // When debugging the application it should hit the `bkpt` instruction.
// What happens when you continue (second iteration of the loop)? // What happens when you continue (second iteration of the loop)?
// (passing 3 breakpoints)
// //
// ** your answer here ** // ** your answer here **
// //
...@@ -91,7 +91,7 @@ fn main() -> ! { ...@@ -91,7 +91,7 @@ fn main() -> ! {
// Rebuild `bare1.rs` in release (optimized mode). // Rebuild `bare1.rs` in release (optimized mode).
// //
// > cargo build --example bare1 --release // > cargo build --example bare1 --release
// (or using the vscode build task) // (or using the vscode)
// //
// Compare the generated assembly for the loop // Compare the generated assembly for the loop
// between the dev (un-optimized) and release (optimized) build. // between the dev (un-optimized) and release (optimized) build.
...@@ -109,6 +109,11 @@ fn main() -> ! { ...@@ -109,6 +109,11 @@ fn main() -> ! {
// //
// ** your answer here ** // ** 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) // commit your answers (bare1_3)
// //
// Discussion: // Discussion:
...@@ -131,7 +136,32 @@ fn main() -> ! { ...@@ -131,7 +136,32 @@ fn main() -> ! {
// Later we will demonstrate how we can get guarantees of panic free execution. // Later we will demonstrate how we can get guarantees of panic free execution.
// This is very important to improve reliability. // 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. // You can pass additional flags to the Rust `rustc` compiler.
// //
// `-Z force-overflow-checks=off` // `-Z force-overflow-checks=off`
...@@ -144,11 +174,11 @@ fn main() -> ! { ...@@ -144,11 +174,11 @@ fn main() -> ! {
// //
// ** your answer here ** // ** your answer here **
// //
// commit your answers (bare1_4) // commit your answers (bare1_5)
// //
// Now restore the `.cargo/config` to its original state. // Now restore the `.cargo/config` to its original state.
// //
// 5. *Optional // 6. *Optional
// There is another way to conveniently use wrapping arithmetics // There is another way to conveniently use wrapping arithmetics
// without passing flags to the compiler. // without passing flags to the compiler.
// //
...@@ -164,7 +194,7 @@ fn main() -> ! { ...@@ -164,7 +194,7 @@ fn main() -> ! {
// //
// ** your answer here ** // ** your answer here **
// //
// commit your answers (bare1_5) // commit your answers (bare1_6)
// //
// Final discussion: // Final discussion:
// //
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment