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 (7)
......@@ -59,7 +59,7 @@
"preLaunchTask": "cargo build --example itm",
"executable": "./target/thumbv7em-none-eabihf/debug/examples/itm",
"configFiles": [
"interface/stlink.cfg",
"interface/stlink-v2-1.cfg",
"target/stm32f4x.cfg"
],
"postLaunchCommands": [
......@@ -89,7 +89,7 @@
"preLaunchTask": "cargo build --example panic",
"executable": "./target/thumbv7em-none-eabihf/debug/examples/panic",
"configFiles": [
"interface/stlink.cfg",
"interface/stlink-v2-1.cfg",
"target/stm32f4x.cfg"
],
"postLaunchCommands": [
......@@ -119,7 +119,7 @@
"preLaunchTask": "cargo build --example exception_itm --release",
"executable": "./target/thumbv7em-none-eabihf/release/examples/exception_itm",
"configFiles": [
"interface/stlink.cfg",
"interface/stlink-v2-1.cfg",
"target/stm32f4x.cfg"
],
"swoConfig": {
......@@ -145,7 +145,7 @@
"preLaunchTask": "cargo build --example exception_itm_raw",
"executable": "./target/thumbv7em-none-eabihf/debug/examples/exception_itm_raw",
"configFiles": [
"interface/stlink.cfg",
"interface/stlink-v2-1.cfg",
"target/stm32f4x.cfg"
],
"swoConfig": {
......@@ -302,7 +302,7 @@
"preLaunchTask": "cargo build --example bare0",
"executable": "./target/thumbv7em-none-eabihf/debug/examples/bare0",
"configFiles": [
"interface/stlink.cfg",
"interface/stlink-v2-1.cfg",
"target/stm32f4x.cfg"
],
"cwd": "${workspaceRoot}"
......@@ -331,7 +331,7 @@
]
},
"configFiles": [
"interface/stlink.cfg",
"interface/stlink-v2-1.cfg",
"target/stm32f4x.cfg"
],
"cwd": "${workspaceRoot}"
......@@ -360,7 +360,7 @@
]
},
"configFiles": [
"interface/stlink.cfg",
"interface/stlink-v2-1.cfg",
"target/stm32f4x.cfg"
],
"cwd": "${workspaceRoot}"
......@@ -389,7 +389,7 @@
]
},
"configFiles": [
"interface/stlink.cfg",
"interface/stlink-v2-1.cfg",
"target/stm32f4x.cfg"
],
"cwd": "${workspaceRoot}"
......@@ -418,7 +418,7 @@
]
},
"configFiles": [
"interface/stlink.cfg",
"interface/stlink-v2-1.cfg",
"target/stm32f4x.cfg"
],
"cwd": "${workspaceRoot}"
......@@ -434,7 +434,7 @@
"monitor arm semihosting enable"
],
"configFiles": [
"interface/stlink.cfg",
"interface/stlink-v2-1.cfg",
"target/stm32f4x.cfg"
],
"cwd": "${workspaceRoot}"
......@@ -450,7 +450,7 @@
"monitor arm semihosting enable"
],
"configFiles": [
"interface/stlink.cfg",
"interface/stlink-v2-1.cfg",
"target/stm32f4x.cfg"
],
"cwd": "${workspaceRoot}"
......@@ -466,7 +466,7 @@
"monitor arm semihosting enable"
],
"configFiles": [
"interface/stlink.cfg",
"interface/stlink-v2-1.cfg",
"target/stm32f4x.cfg"
],
"cwd": "${workspaceRoot}"
......@@ -482,7 +482,7 @@
"monitor arm semihosting enable"
],
"configFiles": [
"interface/stlink.cfg",
"interface/stlink-v2-1.cfg",
"target/stm32f4x.cfg"
],
"cwd": "${workspaceRoot}"
......@@ -495,7 +495,7 @@
"preLaunchTask": "cargo build --example bare6",
"executable": "./target/thumbv7em-none-eabihf/debug/examples/bare6",
"configFiles": [
"interface/stlink.cfg",
"interface/stlink-v2-1.cfg",
"target/stm32f4x.cfg"
],
"postLaunchCommands": [
......@@ -524,7 +524,7 @@
"preLaunchTask": "cargo build --example bare6",
"executable": "./target/thumbv7em-none-eabihf/debug/examples/bare6",
"configFiles": [
"interface/stlink.cfg",
"interface/stlink-v2-1.cfg",
"target/stm32f4x.cfg"
],
"postLaunchCommands": [
......@@ -585,7 +585,7 @@
"preLaunchTask": "cargo build --example bare7",
"executable": "./target/thumbv7em-none-eabihf/debug/examples/bare7",
"configFiles": [
"interface/stlink.cfg",
"interface/stlink-v2-1.cfg",
"target/stm32f4x.cfg"
],
"postLaunchCommands": [
......@@ -616,7 +616,7 @@
"executable": "./target/thumbv7em-none-eabihf/debug/examples/bare7",
// uses local config files
"configFiles": [
"interface/stlink.cfg",
"interface/stlink-v2-1.cfg",
"target/stm32f4x.cfg"
],
"postLaunchCommands": [
......@@ -646,7 +646,7 @@
"preLaunchTask": "cargo build --example bare8",
"executable": "./target/thumbv7em-none-eabihf/debug/examples/bare8",
"configFiles": [
"interface/stlink.cfg",
"interface/stlink-v2-1.cfg",
"target/stm32f4x.cfg"
],
"swoConfig": {
......@@ -673,7 +673,7 @@
"preLaunchTask": "cargo build --example bare9",
"executable": "./target/thumbv7em-none-eabihf/debug/examples/bare9",
"configFiles": [
"interface/stlink.cfg",
"interface/stlink-v2-1.cfg",
"target/stm32f4x.cfg"
],
"swoConfig": {
......@@ -700,7 +700,7 @@
"preLaunchTask": "cargo build --example bare9 --release",
"executable": "./target/thumbv7em-none-eabihf/release/examples/bare9",
"configFiles": [
"interface/stlink.cfg",
"interface/stlink-v2-1.cfg",
"target/stm32f4x.cfg"
],
"swoConfig": {
......@@ -727,7 +727,7 @@
"preLaunchTask": "cargo build --example bare10 --release",
"executable": "./target/thumbv7em-none-eabihf/release/examples/bare10",
"configFiles": [
"interface/stlink.cfg",
"interface/stlink-v2-1.cfg",
"target/stm32f4x.cfg"
],
"swoConfig": {
......@@ -759,7 +759,7 @@
"preLaunchTask": "cargo build --example bare10",
"executable": "./target/thumbv7em-none-eabihf/debug/examples/bare10",
"configFiles": [
"interface/stlink.cfg",
"interface/stlink-v2-1.cfg",
"target/stm32f4x.cfg"
],
"swoConfig": {
......@@ -791,7 +791,7 @@
"preLaunchTask": "cargo build --example marcus --release",
"executable": "./target/thumbv7em-none-eabihf/release/examples/marcus",
"configFiles": [
"interface/stlink.cfg",
"interface/stlink-v2-1.cfg",
"target/stm32f4x.cfg"
],
"swoConfig": {
......@@ -823,7 +823,7 @@
"preLaunchTask": "cargo build --example equivalence --release",
"executable": "./target/thumbv7em-none-eabihf/release/examples/equivalence",
"configFiles": [
"interface/stlink.cfg",
"interface/stlink-v2-1.cfg",
"target/stm32f4x.cfg"
],
"swoConfig": {
......
......@@ -18,26 +18,43 @@ extern crate panic_halt;
// Minimal runtime / startup for Cortex-M microcontrollers
use cortex_m_rt::entry;
use core::cell::UnsafeCell;
struct U32 {
data: UnsafeCell<u32>,
}
// a constant (cannot be changed at run-time)
const X_INIT: u32 = 10;
const X_INIT: u32 = 0xffffffff;
// global mutabale variables (changed using unsafe code)
static mut X: u32 = X_INIT;
static mut Y: u32 = 0;
static X: U32 = U32 {
data: UnsafeCell::new(X_INIT),
};
static Y: U32 = U32 {
data: UnsafeCell::new(0),
};
unsafe impl Sync for U32 {}
#[entry]
fn main() -> ! {
// local mutabale variable (changed in safe code)
let mut x = unsafe { X };
let mut x = read_u32(&X);
loop {
x += 1; // <- place breakpoint here (3)
unsafe {
X += 1;
Y = X;
assert!(x == X && X == Y);
x = x.wrapping_add(1); // <- place breakpoint here (3)
write_u32(&X, read_u32(&X).wrapping_add(1) );
write_u32(&Y, read_u32(&X));
assert!(x == read_u32(&X) && read_u32(&X) == read_u32(&Y) );
}
}
fn read_u32(uint: &U32) -> u32 {
return unsafe{ *uint.data.get()};
}
fn write_u32(write_to: &U32, value: u32) {
unsafe{ *write_to.data.get() = value };
}
// 0. Compile/build the example in debug (dev) mode.
......@@ -48,25 +65,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: 962669 ***
//
// In the Expressions (WATCH -vscode) view add X and Y
// what do you find
//
// ** your answer here **
// *** Watch X and Y didn't work, added watch to 'bare0::X::h2583a8be644794f3' and 'bare0::Y::hef3986a5288bec08' to be able to read the variables
// X = 962669, Y = 962668 ***
//
// 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 **
// *** x is incremented. Eventually x will wrap. ***
//
// 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 **
// ** We end up in the panic handler **
//
// Commit your answers (bare0_2)
//
......@@ -74,10 +92,10 @@ fn main() -> ! {
//
// Change (both) += opertions to use wrapping_add
// load and run the progam, what happens
// ** your answer here **
// ** x value wraps around u32 max 4294967295 and get value 0**
//
// Now continue exectution, what happens
// ** your answer here **
// ** X,Y and x is incremented and wraps around max **
//
// Commit your answers (bare0_3)
//
......@@ -86,7 +104,7 @@ fn main() -> ! {
//
// 4. Change the asserion to `assert!(x == X && X == Y + 1)`, what happens?
//
// ** place your answer here **
// ** The assert fails and we go into panic handler **
//
// Commit your answers (bare0_4)
//
......
......@@ -3,6 +3,6 @@
# Depending on the hardware revision you got you'll have to pick ONE of these
# interfaces. At any time only one interface should be commented out.
source [find interface/stlink.cfg]
source [find interface/stlink-v2-1.cfg]
source [find target/stm32f4x.cfg]