diff --git a/cargo_klee_examples/examples/cyccnt.rs b/cargo_klee_examples/examples/cyccnt.rs index bc036db1d91adfbf7f86178287a9e52c3e2aa69c..7ba2663e4b82395db78aa7f9e40a12a9d1c9c8bf 100644 --- a/cargo_klee_examples/examples/cyccnt.rs +++ b/cargo_klee_examples/examples/cyccnt.rs @@ -9,8 +9,8 @@ extern crate panic_klee; #[no_mangle] fn main() { let mut core = cortex_m::Peripherals::take().unwrap(); - // core.DCB.enable_trace(); - // core.DWT.enable_cycle_counter(); + core.DCB.enable_trace(); + core.DWT.enable_cycle_counter(); let start: u32 = core.DWT.cyccnt.read(); @@ -208,9 +208,10 @@ fn main() { // Why does these values cause an error debug/dev build but not in a release build? // // [This line is causing the problem: let _time = end - start; -// When taking substraction of values two values there is a high risk that it will overflow, -// therefore the error occurs in debug/dev build. -// In release build the substractions occurs and no overflow is found then errors will not occurs. +// When taking substraction between two values with unsigned variable, +// there is a possibility that the value becomes negative. The u32 cant represent negative +// values therefore error occurs in debug/dev build. +// In release build the substractions occurs and no negative value is found then errors will not occur. // It seems like the release build is not detecting potential problems, only problems that occurs.] // // C) Fix the problem! @@ -223,8 +224,8 @@ fn main() { // There are numerous ways to solve the problem. // Argue for your solution in your own words. // -// [The substraction can overflow, to remove the error and make sure the substraction is almost always correct, -// we need to use wrapper_sub.] +// [I added wrapper_sub to the caculation. It will remove the error and make sure the substraction wrap around instead +// of giving an error when the differance is negative. ] // // D) Learning outcomes and major takeaways. // @@ -243,7 +244,13 @@ fn main() { // // How long time would lines 16/17 take to run to trigger the error? // -// [your answer here] +// [ +// They are hard do find becasue the error appears when the timer has wrapped around. +// The error is triggered when end is smaller than start. +// The CYCCNT is a 32 bit unsigned integer, it will wrap around when the value has reached 2^32. +// 2^32/8MHz = 537 s +// It would take at least 537s. +// ] // // Of course this is a contrived example, and may not occur in practice. // But, it represents a class of problems/errors/bugs that is