From 31723faee9a643b0405741f35aeb096a8a4dbb6d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carl=20=C3=96sterberg?= <carl.vilhelms.osterberg@gmail.com>
Date: Fri, 5 Mar 2021 16:30:51 +0100
Subject: [PATCH] tasks done

---
 examples/rtic_bare4.rs | 10 +++++++---
 examples/rtic_bare5.rs | 13 +++++++------
 2 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/examples/rtic_bare4.rs b/examples/rtic_bare4.rs
index f6e3e29..8f01d93 100644
--- a/examples/rtic_bare4.rs
+++ b/examples/rtic_bare4.rs
@@ -57,10 +57,12 @@ const APP: () = {
     #[init]
     fn init(_cx: init::Context) {
         // power on GPIOA
+        //6.3.11
         let r = read_u32(RCC_AHB1ENR); // read
         write_u32(RCC_AHB1ENR, r | 1); // set enable
 
         // configure PA5 as output
+        //8.4.1
         let r = read_u32(GPIOA_MODER) & !(0b11 << (5 * 2)); // read and mask
         write_u32(GPIOA_MODER, r | 0b01 << (5 * 2)); // set output mode
 
@@ -100,7 +102,7 @@ const APP: () = {
 //
 //    What was the error message and explain why.
 //
-//    error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
+//    error[E0133]: call to unsafe function is unsafe and requires unsafe function or block.
 //    A volatile read to register clashes with rusts memory safety, therefor we must tell the compiler
 //    that we know what we are doing and just go with it.
 //
@@ -127,9 +129,11 @@ const APP: () = {
 //
 //    If we try to access GPIOA_MODER before its powered we wont be able to write to it.
 //
-//    Without the non-reordering property of `write_volatile/read_volatile` could that happen in theory
+//    With the reordering property of `write_volatile/read_volatile` could that happen in theory
 //    (argue from the point of data dependencies).
 //
-//    ** your answer here **
+//    Maybe some read operation which is a load from memory gets optimizied into 
+//    being moved around because in pipelineing mode a load takes an extra
+//    clock cycle.
 //
 //    Commit your answers (bare4_3)
diff --git a/examples/rtic_bare5.rs b/examples/rtic_bare5.rs
index b62fad2..4defae4 100644
--- a/examples/rtic_bare5.rs
+++ b/examples/rtic_bare5.rs
@@ -64,8 +64,9 @@ mod stm32f40x {
             mask = mask >> (32-width);
             mask = mask << offset;
             let altered = mask & (value << offset);
-            //hprintln!("Altered {:b}", !altered).ok();
-            //hprintln!("Old     {:b}", (self.read()&!mask)).ok();
+            hprintln!("Mask    {:b}", mask).ok();
+            hprintln!("Altered {:b}", altered).ok();
+            hprintln!("Old     {:b}", (self.read()&!mask)).ok();
             self.write((self.read()&!mask) | altered);
         }
     }
@@ -159,16 +160,16 @@ fn test_modify() {
     //    ..0111000
     //    ---------
     //    000101000
-    //hprintln!("Current {:b}", t.read()).ok();
-    //hprintln!("Correct {:b}", 0b101 << 3).ok();
+    hprintln!("Current {:b}", t.read()).ok();
+    hprintln!("Correct {:b}", 0b101 << 3).ok();
     assert!(t.read() == 0b101 << 3);
     t.modify(4, 3, 0b10001);
     //    000101000
     //      111
     //      001
     //    000011000
-    //hprintln!("Current {:b}", t.read()).ok();
-    //hprintln!("Correct {:b}", 0b011 << 3).ok();
+    hprintln!("Current {:b}", t.read()).ok();
+    hprintln!("Correct {:b}", 0b011 << 3).ok();
     assert!(t.read() == 0b011 << 3);
     //
     // add more tests here if you like
-- 
GitLab