Skip to main content
Sign in
Snippets Groups Projects
Commit 5b681bee authored by Per Lindgren's avatar Per Lindgren
Browse files

bare1

parent f6e957a9
No related branches found
No related tags found
No related merge requests found
...@@ -23,6 +23,9 @@ rustflags = [ ...@@ -23,6 +23,9 @@ rustflags = [
# "-C", "linker=arm-none-eabi-gcc", # "-C", "linker=arm-none-eabi-gcc",
# "-C", "link-arg=-Wl,-Tlink.x", # "-C", "link-arg=-Wl,-Tlink.x",
# "-C", "link-arg=-nostartfiles", # "-C", "link-arg=-nostartfiles",
# uncomment for unchecked wrapping arithmetics also in dev mode
# "-Z", "force-overflow-checks=off",
] ]
[build] [build]
... ...
......
...@@ -168,6 +168,64 @@ ...@@ -168,6 +168,64 @@
], ],
"cwd": "${workspaceRoot}" "cwd": "${workspaceRoot}"
}, },
{
"type": "cortex-debug",
"request": "launch",
"servertype": "openocd",
"name": "bare1 (debug)",
"preLaunchTask": "cargo build --example bare1",
"executable": "./target/thumbv7em-none-eabihf/debug/examples/bare1",
"postLaunchCommands": [
"monitor arm semihosting enable"
],
"swoConfig": {
"enabled": true,
"cpuFrequency": 16000000,
"swoFrequency": 2000000,
"source": "probe",
"decoders": [
{
"type": "console",
"label": "ITM",
"port": 0
}
]
},
"configFiles": [
"interface/stlink.cfg",
"target/stm32f4x.cfg"
],
"cwd": "${workspaceRoot}"
},
{
"type": "cortex-debug",
"request": "launch",
"servertype": "openocd",
"name": "bare1 (release)",
"preLaunchTask": "cargo build --example bare1",
"executable": "./target/thumbv7em-none-eabihf/release/examples/bare1",
"postLaunchCommands": [
"monitor arm semihosting enable"
],
"swoConfig": {
"enabled": true,
"cpuFrequency": 16000000,
"swoFrequency": 2000000,
"source": "probe",
"decoders": [
{
"type": "console",
"label": "ITM",
"port": 0
}
]
},
"configFiles": [
"interface/stlink.cfg",
"target/stm32f4x.cfg"
],
"cwd": "${workspaceRoot}"
},
{ {
"type": "cortex-debug", "type": "cortex-debug",
"request": "launch", "request": "launch",
... ...
......
...@@ -87,5 +87,29 @@ ...@@ -87,5 +87,29 @@
"isDefault": true "isDefault": true
} }
}, },
{
"type": "shell",
"label": "cargo build --example bare1",
"command": "cargo build --example bare1",
"problemMatcher": [
"$rustc"
],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "shell",
"label": "cargo build --example bare1 --release",
"command": "cargo build --example bare1 --release",
"problemMatcher": [
"$rustc"
],
"group": {
"kind": "build",
"isDefault": true
}
},
] ]
} }
\ No newline at end of file
...@@ -5,8 +5,11 @@ readme = "README.md" ...@@ -5,8 +5,11 @@ readme = "README.md"
name = "app" name = "app"
version = "0.1.0" version = "0.1.0"
[dependencies.cortex-m]
version = "0.5.8"
features = ["inline-asm"] # <- currently requires nightly compiler
[dependencies] [dependencies]
cortex-m = "0.5.8"
cortex-m-rt = "0.6.7" cortex-m-rt = "0.6.7"
cortex-m-semihosting = "0.3.2" cortex-m-semihosting = "0.3.2"
panic-halt = "0.2.0" panic-halt = "0.2.0"
... ...
......
...@@ -18,7 +18,7 @@ extern crate panic_halt; ...@@ -18,7 +18,7 @@ extern crate panic_halt;
// Minimal runtime / startup for Cortex-M microcontrollers // Minimal runtime / startup for Cortex-M microcontrollers
use cortex_m_rt::entry; use cortex_m_rt::entry;
// a constant (cannot be changed) // a constant (cannot be changed at run-time)
const X_INIT: u32 = 10; const X_INIT: u32 = 10;
// global mutabale variables (changed using unsafe code) // global mutabale variables (changed using unsafe code)
...@@ -40,62 +40,65 @@ fn main() -> ! { ...@@ -40,62 +40,65 @@ fn main() -> ! {
} }
} }
// 1. run the program in the debugger, // 1. Run the program in the debugger, let the program run for a while and
// let the program run for a while and then press pause // then press pause. Look in the (Local -vscode) Variables view what do you find.
// look in the (Local -vscode) Variables view what do you find //
// ** your answer here ** // ** your answer here **
// //
// in the Expressions (WATCH -vscode) view add X and Y // In the Expressions (WATCH -vscode) view add X and Y
// what do you find // what do you find
// //
// ** your answer here ** // ** your answer here **
// step through one complete iteration of the loop //
// Step through one complete iteration of the loop
// and see how the (Local) Variables are updated // and see how the (Local) Variables are updated
// can you foresee what will eventually happen? // can you foresee what will eventually happen?
//
// ** place your answer here ** // ** place your answer here **
// //
// commit your answers (bare0_1) // commit your answers (bare0_1)
// //
// 2. alter the constant X_INIT so that `x += 1` directly causes `x` to wrap // 2. Alter the constant X_INIT so that `x += 1` directly causes `x` to wrap
// what happens when `x` wraps // what happens when `x` wraps
//
// ** your answer here ** // ** your answer here **
// //
// commit your answers (bare0_2) // commit your answers (bare0_2)
// //
// 3. place a breakpoint at `x += 1` // 3. Place a breakpoint at `x += 1`
// change (both) += opertions to use wrapping_add //
// Change (both) += opertions to use wrapping_add
// load and run the progam, what happens // load and run the progam, what happens
// ** your answer here ** // ** your answer here **
// //
// now continue exectution, what happens // Now continue exectution, what happens
// ** your answer here ** // ** your answer here **
// //
// commit your answers (bare0_3) // commit your answers (bare0_3)
// //
// (if the program did not succeed back to the breakpoint // (If the program did not succeed back to the breakpoint
// you have some fault in the program and go back to 3) // you have some fault in the program and go back to 3.)
//
// 4. Change the asserion to `assert!(x == X && X == Y + 1)`, what happens?
// //
// 4. change the asserion to `assert!(x == X && X == Y + 1)`, what happens
// ** place your answer here ** // ** place your answer here **
// //
// commit your answers (bare0_4) // commit your answers (bare0_4)
// //
// 5. remove the assertion and // 5. Remove the assertion and implement "safe" functions for
// // reading and writing X and Y
// make "safe" functions for reading and writing X and Y
// e.g. read_x, read_y, write_x, write_y // e.g. read_x, read_y, write_x, write_y
// //
// rewrite the program to use ONLY "safe" code besides the // Rewrite the program to use ONLY "safe" code besides the
// read/write functions (which are internally "unsafe") // read/write functions (which are internally "unsafe")
// //
// commit your solution (bare0_5) // commit your solution (bare0_5)
// //
// 6*. optional // 6. *Optional
// implement a read_u32/write_u32, taking a reference to a // Implement a read_u32/write_u32, taking a reference to a
// "static" variable // "static" variable
// //
// rewrite the program to use this abstraction instead of "read_x", etc. // Rewrite the program to use this abstraction instead of "read_x", etc.
// //
// commit your solution (bare0_6) // commit your solution (bare0_6)
// //
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment