Skip to content
Snippets Groups Projects
Commit 23771265 authored by Jonas Jacobsson's avatar Jonas Jacobsson Committed by Tommy Andersson
Browse files

Fixed this.

parent fed46a06
No related branches found
No related tags found
No related merge requests found
...@@ -36,7 +36,6 @@ use address::*; ...@@ -36,7 +36,6 @@ use address::*;
#[inline(always)] #[inline(always)]
fn read_u32(addr: u32) -> u32 { fn read_u32(addr: u32) -> u32 {
unsafe { core::ptr::read_volatile(addr as *const _) } unsafe { core::ptr::read_volatile(addr as *const _) }
// core::ptr::read_volatile(addr as *const _)
} }
#[inline(always)] #[inline(always)]
...@@ -83,7 +82,7 @@ const APP: () = { ...@@ -83,7 +82,7 @@ const APP: () = {
// //
// 1. Did you enjoy the blinking? // 1. Did you enjoy the blinking?
// //
// ** your answer here ** // Yeah
// //
// Now lookup the data-sheets, and read each section referred, // Now lookup the data-sheets, and read each section referred,
// 6.3.11, 8.4.1, 8.4.7 // 6.3.11, 8.4.1, 8.4.7
...@@ -100,12 +99,20 @@ const APP: () = { ...@@ -100,12 +99,20 @@ const APP: () = {
// //
// What was the error message and explain why. // What was the error message and explain why.
// //
// ** your answer here ** /*
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
--> examples\rtic_bare4.rs:39:5
|
39 | core::ptr::read_volatile(addr as *const _)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
|
= note: consult the function's documentation for information on how to avoid undefined behavior
*/
// //
// Digging a bit deeper, why do you think `read_volatile` is declared `unsafe`. // Digging a bit deeper, why do you think `read_volatile` is declared `unsafe`.
// (https://doc.rust-lang.org/core/ptr/fn.read_volatile.html, for some food for thought ) // (https://doc.rust-lang.org/core/ptr/fn.read_volatile.html, for some food for thought )
// //
// ** your answer here ** // It is not safe. You create a copy of a register without using borrow checking so Rust consider it unsafe.
// //
// Commit your answers (bare4_2) // Commit your answers (bare4_2)
// //
...@@ -118,16 +125,18 @@ const APP: () = { ...@@ -118,16 +125,18 @@ const APP: () = {
// //
// Why is it important that ordering of volatile operations are ensured by the compiler? // Why is it important that ordering of volatile operations are ensured by the compiler?
// //
// ** your answer here ** // Because we are messing around with the registers and the stack in a specific way and want it to behave exactly the way we specified.
// Thats the whole point with volatile operations.
// //
// Give an example in the above code, where reordering might make things go horribly wrong // Give an example in the above code, where reordering might make things go horribly wrong
// (hint, accessing a peripheral not being powered...) // (hint, accessing a peripheral not being powered...)
// //
// ** your answer here ** // When we specify a specific address we really mean that address and want to know that we get exactly that address and nothing else.
// Line 44 and 38 is places where it could be really bad if the compiler assumes something else.
// //
// Without the non-reordering property of `write_volatile/read_volatile` could that happen in theory // Without the non-reordering property of `write_volatile/read_volatile` could that happen in theory
// (argue from the point of data dependencies). // (argue from the point of data dependencies).
// //
// ** your answer here ** // We write/read from some unwanted address and get/set the wrong information. This could lead to unwanted behaviors and is not very good.
// //
// Commit your answers (bare4_3) // Commit your answers (bare4_3)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment