From 1b747d6c99f287da24d534823e01ecfb9a9fcc00 Mon Sep 17 00:00:00 2001
From: Blinningjr <nicke.l@telia.com>
Date: Wed, 2 Dec 2020 14:01:18 +0100
Subject: [PATCH] Finished exercises in main

---
 src/main.rs | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 90 insertions(+), 5 deletions(-)

diff --git a/src/main.rs b/src/main.rs
index 6598720..3364935 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -6,7 +6,7 @@
 #![no_std]
 
 use panic_halt as _;
-// use panic_rtt_target as _;
+//use panic_rtt_target as _;
 use rtt_target::{rprintln, rtt_init_print};
 use stm32f4;
 
@@ -21,10 +21,10 @@ const APP: () = {
     #[idle]
     fn idle(_cx: idle::Context) -> ! {
         rprintln!("idle");
-        // panic!("panic");
-        loop {
-            continue;
-        }
+        panic!("panic");
+//        loop {
+//            continue;
+//        }
     }
 };
 
@@ -51,6 +51,7 @@ const APP: () = {
 //         at /home/pln/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-rt-0.6.13/src/lib.rs:526
 //
 // Make sure you got the expected output
+// Awnser: Yes, got the expected output.
 //
 // C) Panic tracing
 // Rust is designed for reliability, with the aim to deliver memory safety
@@ -64,6 +65,30 @@ const APP: () = {
 // What is the output?
 //
 // [Your answer here]
+// Compiling app v0.1.0 (/home/niklas/Desktop/D7020E/rtic_f4xx_nucleo)
+// error: unreachable expression
+//   --> src/main.rs:25:9
+//    |
+// 24 |           panic!("panic");
+//    |           ---------------- any code following this expression is unreachable
+// 25 | /         loop {
+// 26 | |             continue;
+// 27 | |         }
+//    | |_________^ unreachable expression
+//    |
+// note: the lint level is defined here
+//   --> src/main.rs:4:9
+//    |
+// 4  | #![deny(warnings)]
+//    |         ^^^^^^^^
+//    = note: `#[deny(unreachable_code)]` implied by `#[deny(warnings)]`
+// 
+// error: aborting due to previous error
+// 
+// error: could not compile `app`
+// 
+// To learn more, run the command again with --verbose.
+// 
 //
 // D) Panic halt
 // Tracing is nice during development, but requires a debugger attached
@@ -77,12 +102,37 @@ const APP: () = {
 // What is the output?
 //
 // [Your answer here]
+//  Compiling app v0.1.0 (/home/niklas/Desktop/D7020E/rtic_f4xx_nucleo)
+//    Finished dev [unoptimized + debuginfo] target(s) in 0.68s
+//     Running `probe-run --chip STM32F411RETx target/thumbv7em-none-eabi/debug/app`
+//  (HOST) INFO  flashing program (10.53 KiB)
+//  (HOST) INFO  success!
+//────────────────────────────────────────────────────────────────────────────────
+//init
+//idle
+//
 //
 // Now press Ctrl-C
 //
 // What is the output?
 //
 // [Your answer here]
+//^Cstack backtrace:
+//   0: core::sync::atomic::compiler_fence
+//        at /home/niklas/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/sync/atomic.rs:2644
+//   1: rust_begin_unwind
+//        at /home/niklas/.cargo/registry/src/github.com-1ecc6299db9ec823/panic-halt-0.2.0/src/lib.rs:33
+//   2: core::panicking::panic_fmt
+//        at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/panicking.rs:85
+//   3: core::panicking::panic
+//        at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/panicking.rs:50
+//   4: app::idle
+//        at src/main.rs:24
+//   5: main
+//        at src/main.rs:13
+//   6: Reset
+//        at /home/niklas/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-rt-0.6.13/src/lib.rs:526
+//
 //
 // E) Find the source
 // Figure out how to find the source of `panic_halt`, and look at the implementation.
@@ -92,3 +142,38 @@ const APP: () = {
 //
 // Paste the implementation here
 // [Your answer here]
+////! Set the panicking behavior to halt
+////!
+////! This crate contains an implementation of `panic_fmt` that simply halt in an infinite loop.
+////!
+////! # Usage
+////!
+////! ``` ignore
+////! #![no_std]
+////!
+////! extern crate panic_halt;
+////!
+////! fn main() {
+////!     panic!("argument is ignored");
+////! }
+////! ```
+////!
+////! # Breakable symbols
+////!
+////! With the panic handler being `#[inline(never)]` the symbol `rust_begin_unwind` will be
+////! available to place a breakpoint on to halt when a panic is happening.
+//
+//#![deny(missing_docs)]
+//#![deny(warnings)]
+//#![no_std]
+//
+//use core::panic::PanicInfo;
+//use core::sync::atomic::{self, Ordering};
+//
+//#[inline(never)]
+//#[panic_handler]
+//fn panic(_info: &PanicInfo) -> ! {
+//    loop {
+//        atomic::compiler_fence(Ordering::SeqCst);
+//    }
+//}
-- 
GitLab