Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • student
1 result

Target

Select target project
  • pln/e7020e_2019
  • Henrik/e7020e_2019
  • wijk/e7020e_2019
  • sheepwall/e7020e_2019
  • Tiberg/e7020e_2019
  • Tyllstrom/e7020e_2019
  • Ridgep/e7020e_2019
7 results
Select Git revision
  • nrf52
  • student
2 results
Show changes
Commits on Source (19)
......@@ -28,19 +28,19 @@ optional = true
[dependencies.cortex-m]
version = "0.5.8"
# features = ["inline-asm"] # <- currently requires nightly compiler
features = ["inline-asm"] # <- currently requires nightly compiler
# Uncomment for the allocator example.
# alloc-cortex-m = "0.3.5"
[dependencies.stm32f4]
version = "0.5.0"
version = "0.6.0"
features = ["stm32f413", "rt"]
optional = true
[dependencies.stm32f4xx-hal]
git = "https://github.com/stm32-rs/stm32f4xx-hal.git"
version = "0.2.8"
version = "0.3.0"
features = ["stm32f413", "rt"]
optional = true
......
......@@ -19,7 +19,7 @@ extern crate panic_halt;
use cortex_m_rt::entry;
// a constant (cannot be changed at run-time)
const X_INIT: u32 = 10;
const X_INIT: u32 = u32::max_value();
// global mutabale variables (changed using unsafe code)
static mut X: u32 = X_INIT;
......@@ -31,15 +31,35 @@ fn main() -> ! {
let mut x = unsafe { X };
loop {
x += 1; // <- place breakpoint here (3)
x = x.wrapping_add(1); // <- place breakpoint here (3)
write_x(1);
write_y(read_x());
}
}
fn read_x() -> u32{
unsafe{
X += 1;
Y = X;
assert!(x == X && X == Y);
X
}
}
fn read_y() -> u32{
unsafe{
Y
}
}
fn write_x(i: u32){
unsafe{
X = X.wrapping_add(1);
}
}
fn write_y(i: u32){
unsafe{
Y = i;
}
}
// 0. Compile/build the example in debug (dev) mode.
//
// > cargo build --example bare0
......@@ -48,25 +68,26 @@ fn main() -> ! {
// 1. Run the program in the debugger, let the program run for a while and
// then press pause. Look in the (Local -vscode) Variables view what do you find.
//
// ** your answer here **
// x == 2309008
//
// In the Expressions (WATCH -vscode) view add X and Y
// what do you find
//
// ** your answer here **
// X == 2309008
// Y == 2309008
//
// Step through one complete iteration of the loop
// and see how the (Local) Variables are updated
// can you foresee what will eventually happen?
//
// ** place your answer here **
// The values of x, X and Y increase with the value of 1 and end up equaling 2309009 after one loop.
//
// Commit your answers (bare0_1)
//
// 2. Alter the constant X_INIT so that `x += 1` directly causes `x` to wrap
// what happens when `x` wraps
//
// ** your answer here **
// It causes a core panic.
//
// Commit your answers (bare0_2)
//
......@@ -74,10 +95,12 @@ fn main() -> ! {
//
// Change (both) += opertions to use wrapping_add
// load and run the progam, what happens
// ** your answer here **
//
// The local variable x and X goes back to 0 from max value.
//
// Now continue exectution, what happens
// ** your answer here **
//
// Adds 1 to the variables, will continue to do so until max value reached and then start over.
//
// Commit your answers (bare0_3)
//
......@@ -86,7 +109,7 @@ fn main() -> ! {
//
// 4. Change the asserion to `assert!(x == X && X == Y + 1)`, what happens?
//
// ** place your answer here **
// The newly added assert fails and takes us into the panic kernel.
//
// Commit your answers (bare0_4)
//
......
......@@ -55,10 +55,11 @@ fn main() -> ! {
// loop, (press pause/suspend to verify this).
// what is the output in the ITM console
//
// ** your answer here **
// Nothing, it is blank.
//
// What is the output in the semihosting (openocd) console
// ** your answer here **
//
// "semihosting is enabled" is the last printed line.
//
// Commit your answers (bare1_1)
//
......@@ -68,7 +69,38 @@ fn main() -> ! {
// What is the output of:
// (gdb) disassemble
//
// ** your answer here **
// Dump of assembler code for function main:
// 0x08000400 <+0>: sub sp, #16
// 0x08000402 <+2>: movs r0, #0
// 0x08000404 <+4>: str r0, [sp, #12]
// 0x08000406 <+6>: b.n 0x8000408 <main+8>
// 0x08000408 <+8>: ldr r0, [sp, #12]
// 0x0800040a <+10>: adds r1, r0, #1
// 0x0800040c <+12>: mov r2, r1
// 0x0800040e <+14>: cmp r1, r0
// 0x08000410 <+16>: str r2, [sp, #8]
// 0x08000412 <+18>: bvs.n 0x800042c <main+44>
// 0x08000414 <+20>: b.n 0x8000416 <main+22>
// 0x08000416 <+22>: ldr r0, [sp, #8]
// 0x08000418 <+24>: str r0, [sp, #12]
// 0x0800041a <+26>: ldr r1, [sp, #12]
// 0x0800041c <+28>: subs r2, r1, #1
// 0x0800041e <+30>: cmp r1, #1
// 0x08000420 <+32>: str r2, [sp, #4]
// 0x08000422 <+34>: bvs.n 0x800043a <main+58>
// 0x08000424 <+36>: b.n 0x8000426 <main+38>
// 0x08000426 <+38>: ldr r0, [sp, #4]
// 0x08000428 <+40>: str r0, [sp, #12]
// => 0x0800042a <+42>: b.n 0x8000408 <main+8>
// 0x0800042c <+44>: movw r0, #2268 ; 0x8dc
// 0x08000430 <+48>: movt r0, #2048 ; 0x800
// 0x08000434 <+52>: bl 0x800045c <panic>
// 0x08000438 <+56>: udf #254 ; 0xfe
// 0x0800043a <+58>: movw r0, #2340 ; 0x924
// 0x0800043e <+62>: movt r0, #2048 ; 0x800
// 0x08000442 <+66>: bl 0x800045c <panic>
// 0x08000446 <+70>: udf #254 ; 0xfe
// End of assembler dump.
//
// Commit your answers (bare1_2)
//
......@@ -78,7 +110,40 @@ fn main() -> ! {
// What is the output of:
// (gdb) disassemble
//
// ** your answer here **
// Dump of assembler code for function main:
// 0x08000404 <+0>: sub sp, #16
// 0x08000406 <+2>: movs r0, #0
// 0x08000408 <+4>: str r0, [sp, #12]
// 0x0800040a <+6>: b.n 0x800040c <main+8>
// 0x0800040c <+8>: ldr r0, [sp, #12]
// 0x0800040e <+10>: adds r1, r0, #1
// 0x08000410 <+12>: mov r2, r1
// 0x08000412 <+14>: cmp r1, r0
// 0x08000414 <+16>: str r2, [sp, #8]
// 0x08000416 <+18>: bvs.n 0x8000436 <main+50>
// 0x08000418 <+20>: b.n 0x800041a <main+22>
// 0x0800041a <+22>: ldr r0, [sp, #8]
// 0x0800041c <+24>: str r0, [sp, #12]
// 0x0800041e <+26>: bl 0x8000400 <cortex_m::asm::nop>
// 0x08000422 <+30>: b.n 0x8000424 <main+32>
// 0x08000424 <+32>: ldr r0, [sp, #12]
// 0x08000426 <+34>: subs r1, r0, #1
// 0x08000428 <+36>: cmp r0, #1
// 0x0800042a <+38>: str r1, [sp, #4]
// 0x0800042c <+40>: bvs.n 0x8000444 <main+64>
// 0x0800042e <+42>: b.n 0x8000430 <main+44>
// 0x08000430 <+44>: ldr r0, [sp, #4]
// 0x08000432 <+46>: str r0, [sp, #12]
// => 0x08000434 <+48>: b.n 0x800040c <main+8>
// 0x08000436 <+50>: movw r0, #2268 ; 0x8dc
// 0x0800043a <+54>: movt r0, #2048 ; 0x800
// 0x0800043e <+58>: bl 0x8000466 <panic>
// 0x08000442 <+62>: udf #254 ; 0xfe
// 0x08000444 <+64>: movw r0, #2340 ; 0x924
// 0x08000448 <+68>: movt r0, #2048 ; 0x800
// 0x0800044c <+72>: bl 0x8000466 <panic>
// 0x08000450 <+76>: udf #254 ; 0xfe
// End of assembler dump.
//
// Commit your answers (bare1_3)
//
......@@ -88,7 +153,42 @@ fn main() -> ! {
// What is the output of:
// (gdb) disassemble
//
// ** your answer here **
// Dump of assembler code for function main:
// 0x08000404 <+0>: sub sp, #16
// 0x08000406 <+2>: movs r0, #0
// 0x08000408 <+4>: str r0, [sp, #12]
// 0x0800040a <+6>: b.n 0x800040c <main+8>
// 0x0800040c <+8>: ldr r0, [sp, #12]
// 0x0800040e <+10>: adds r1, r0, #1
// 0x08000410 <+12>: mov r2, r1
// 0x08000412 <+14>: cmp r1, r0
// 0x08000414 <+16>: str r2, [sp, #8]
// 0x08000416 <+18>: bvs.n 0x800043a <main+54>
// 0x08000418 <+20>: b.n 0x800041a <main+22>
// 0x0800041a <+22>: ldr r0, [sp, #8]
// 0x0800041c <+24>: str r0, [sp, #12]
// 0x0800041e <+26>: bl 0x8000400 <cortex_m::asm::nop>
// 0x08000422 <+30>: b.n 0x8000424 <main+32>
// => 0x08000424 <+32>: bkpt 0x0000
// 0x08000426 <+34>: b.n 0x8000428 <main+36>
// 0x08000428 <+36>: ldr r0, [sp, #12]
// 0x0800042a <+38>: subs r1, r0, #1
// 0x0800042c <+40>: cmp r0, #1
// 0x0800042e <+42>: str r1, [sp, #4]
// 0x08000430 <+44>: bvs.n 0x8000448 <main+68>
// 0x08000432 <+46>: b.n 0x8000434 <main+48>
// 0x08000434 <+48>: ldr r0, [sp, #4]
// 0x08000436 <+50>: str r0, [sp, #12]
// 0x08000438 <+52>: b.n 0x800040c <main+8>
// 0x0800043a <+54>: movw r0, #2268 ; 0x8dc
// 0x0800043e <+58>: movt r0, #2048 ; 0x800
// 0x08000442 <+62>: bl 0x800046a <panic>
// 0x08000446 <+66>: udf #254 ; 0xfe
// 0x08000448 <+68>: movw r0, #2340 ; 0x924
// 0x0800044c <+72>: movt r0, #2048 ; 0x800
// 0x08000450 <+76>: bl 0x800046a <panic>
// 0x08000454 <+80>: udf #254 ; 0xfe
// End of assembler dump.
//
// Commit your answers (bare1_4)
//
......@@ -101,7 +201,17 @@ fn main() -> ! {
// Compare the generated assembly for the loop
// between the dev (unoptimized) and release (optimized) build.
//
// ** your answer here **
// The optimized version executes assembly commands that the unoptimized does not.
// It also is a lot longer with the length of the commands executed, due to this.
//
// Dump of assembler code for function main:
// 0x08000400 <+0>: nop
// 0x08000402 <+2>: bkpt 0x0000
// => 0x08000404 <+4>: b.n 0x8000400 <main>
// End of assembler dump.
//
// As seen on the assemble code from task 2-4 and compared to task 5, the unoptimized
// code is a lot longer and has more instructions than the optimized one.
//
// commit your answers (bare1_5)
//
......
......@@ -71,18 +71,21 @@ fn main() -> ! {
//
// What is the output in the ITM console?
//
// ** your answer here **
// The ITM console prints out:
// Start 524429147
// End 1149429355
//
// Rebuild and run in release mode
//
// > cargo build --example bare2 --release
//
// ** your answer here **
// Start 3475270830
// End 3479270838
//
// Compute the ratio between debug/release optimized code
// (the speedup).
//
// ** your answer here **
// diff(debug)/diff(released) = 156,249 ratio
//
// commit your answers (bare2_1)
//
......
......@@ -18,8 +18,12 @@ use cortex_m_semihosting::{hprint, hprintln};
#[entry]
fn main() -> ! {
hprintln!("bare3").unwrap();
let s = "ABCD";
let bs = s.as_bytes();
let s: &str = "ABCD";
let bs: &[u8] = s.as_bytes();
let c: &u8;
let i: i32;
let a: [u8; 4];
let mut a = [0u8; 4];
hprintln!("s = {}", s).unwrap();
hprintln!("bs = {:?}", bs).unwrap();
......@@ -32,12 +36,13 @@ fn main() -> ! {
hprintln!("iterate iterate using (raw) indexing").unwrap();
for i in 0..s.len() {
hprintln!("{},", bs[i]).unwrap();
a[i] = bs[i];
}
hprintln!("").unwrap();
let a = [65u8; 4];
//let mut a = [0u8; 4];
// a = [65u8; 4];
hprintln!("").unwrap();
hprintln!("a = {}", core::str::from_utf8(&a).unwrap()).unwrap();
......@@ -52,27 +57,38 @@ fn main() -> ! {
//
// 1. What is the output in the `openocd` (Adapter Output) console?
//
// ** your answer here **
// bare3
// s = ABCD
// bs = [65, 66, 67, 68]
// iterate over slice
// 65,66,67,68,iterate iterate using (raw) indexing
// 65,
// 66,
// 67,
// 68,
//
//
// a = AAAA
//
// What is the type of `s`?
//
// ** your answer here **
// type string
//
// What is the type of `bs`?
//
// ** your answer here **
// u8 byte array
//
// What is the type of `c`?
//
// ** your answer here **
// Pointer for an u8 element in the bs array.
//
// What is the type of `a`?
//
// ** your answer here **
// it's an array of u8
//
// What is the type of `i`?
//
// ** your answer here **
// a int variable, i32
//
// Commit your answers (bare3_1)
//
......@@ -81,10 +97,23 @@ fn main() -> ! {
// Commit your answers (bare3_2)
//
// 3. Uncomment line `let mut a = [0u8; 4];
//`
//
// Run the program, what happens and why?
//
// ** your answer here **
// bare3
// s = ABCD
// bs = [65, 66, 67, 68]
// iterate over slice
// 65,66,67,68,iterate iterate using (raw) indexing
// 65,
// 66,
// 67,
// 68,
//
//
// a =
//
// Since 0 in ASCII is nothing, then the value of our a array will be empty.
//
// Commit your answers (bare3_3)
//
......