diff --git a/examples/rtic_bare4.rs b/examples/rtic_bare4.rs index f6e3e299ff67aa20f7e7d602a638af518a4f5a84..8f01d938e436e4a7a14217b2826311225ad182b5 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 b62fad244e5fba92abfe27bc7dcfc761bc677998..4defae4fe3bf9d4bcba2c2d6d986f44e74728e5c 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