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
  • master
1 result

Target

Select target project
  • pln/e7020e_2020
  • 97gushan/e7020e_2020
  • markhakansson/e7020e_2020
  • Grumme2/e7020e_2020
  • Hammarkvast/e7020e_2020
5 results
Select Git revision
  • master
1 result
Show changes
Commits on Source (5)
......@@ -4,6 +4,7 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
// Launch configuration for `app`
// - debug
// - semihosting
......@@ -16,8 +17,28 @@
"preLaunchTask": "cargo build",
"executable": "./target/thumbv7em-none-eabihf/debug/app",
"configFiles": [
"interface/stlink.cfg",
// "interface/stlink-v2-1.cfg", // deprecated setup script
"interface/stlink-v2-1.cfg",
"target/stm32f4x.cfg"
],
"postLaunchCommands": [
"monitor arm semihosting enable"
],
"runToMain": true,
"cwd": "${workspaceRoot}"
},
// Launch configuration for `app`
// - debug
// - semihosting
// - run to main
{
"type": "cortex-debug",
"request": "launch",
"servertype": "openocd",
"name": "examples (debug)",
"preLaunchTask": "cargo build --examples",
"executable": "./target/thumbv7em-none-eabihf/debug/examples/${fileBasenameNoExtension}",
"configFiles": [
"interface/stlink-v2-1.cfg",
"target/stm32f4x.cfg"
],
"postLaunchCommands": [
......@@ -39,8 +60,7 @@
"preLaunchTask": "cargo build --example",
"executable": "./target/thumbv7em-none-eabihf/debug/examples/${fileBasenameNoExtension}",
"configFiles": [
"interface/stlink.cfg",
// "interface/stlink-v2-1.cfg", // deprecated setup script
"interface/stlink-v2-1.cfg",
"target/stm32f4x.cfg"
],
"postLaunchCommands": [
......@@ -75,8 +95,7 @@
"preLaunchTask": "cargo build --example",
"executable": "./target/thumbv7em-none-eabihf/debug/examples/${fileBasenameNoExtension}",
"configFiles": [
"interface/stlink.cfg",
// "interface/stlink-v2-1.cfg", // deprecated setup script
"interface/stlink-v2-1.cfg",
"target/stm32f4x.cfg"
],
"postLaunchCommands": [
......@@ -150,8 +169,7 @@
"preLaunchTask": "cargo build --example --release",
"executable": "./target/thumbv7em-none-eabihf/release/examples/${fileBasenameNoExtension}",
"configFiles": [
"interface/stlink.cfg",
// "interface/stlink-v2-1.cfg", // deprecated setup script
"interface/stlink-v2-1.cfg",
"target/stm32f4x.cfg"
],
"postLaunchCommands": [
......@@ -175,8 +193,7 @@
"preLaunchTask": "cargo build --example --release --features stm32f4",
"executable": "./target/thumbv7em-none-eabihf/release/examples/${fileBasenameNoExtension}",
"configFiles": [
"interface/stlink.cfg",
// "interface/stlink-v2-1.cfg", // deprecated setup script
"interface/stlink-v2-1.cfg",
"target/stm32f4x.cfg"
],
"postLaunchCommands": [
......
......@@ -22,25 +22,49 @@ use panic_semihosting as _;
use cortex_m_rt::entry;
// a constant (cannot be changed at run-time)
const X_INIT: u32 = 10;
// const X_INIT: u32 = core::u32::MAX;
const X_INIT: u32 = core::u32::MAX;
// global mutable variables (changed using unsafe code)
static mut X: u32 = X_INIT;
static mut Y: u32 = 0;
fn write_x(x: u32, i: u32) {
unsafe{
X = x.wrapping_add(i);
}
}
fn write_y(y: u32) {
unsafe{
Y = y;
}
}
fn read_y() -> u32 {
unsafe{
Y
}
}
fn read_x() -> u32 {
unsafe{
X
}
}
#[entry]
fn main() -> ! {
// local mutable variable (changed in safe code)
let mut x = unsafe { X };
let mut x = read_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_x(read_x(), 1);
write_y(read_x());
assert!(x == read_x() && read_x() == read_y());
}
}
......@@ -56,12 +80,14 @@ fn main() -> ! {
//
// Look under Variables/Local what do you find.
//
// ** your answer here **
// x: 9389056
//
// In the Expressions (WATCH -vscode) view add X and Y
// what do you find
//
// ** your answer here **
// X: 9389055
// Y: <optimized out>
//
// Step through one complete iteration of the loop
// and see how the (Local) Variables are updated
......@@ -69,6 +95,10 @@ fn main() -> ! {
//
// ** place your answer here **
//
// x will update to 9389057
// eventually x will overflow and if rust runs in debug mode then rust will panic and
// if it runs in release mode rust wont check for the overflow and just do a wrap the value
//
// Commit your answers (bare0_1)
//
// 2. Alter the constant X_INIT so that `x += 1` directly causes `x` to wrap.
......@@ -76,6 +106,8 @@ fn main() -> ! {
// (Hint, look under OUTPUT/Adopter Output to see the `openocd` output.)
//
// ** your answer here **
// The program panics
// panicked at 'attempt to add with overflow', examples/bare0.rs:42:9
//
// Commit your answers (bare0_2)
//
......@@ -84,10 +116,12 @@ fn main() -> ! {
// Change (both) += operations to use wrapping_add
// load and run the program, what happens
// ** your answer here **
//
// x wrapps around and become 0
// X does nothing
// Now continue execution, what happens
// ** your answer here **
//
// x continues to add up
// X still does nothing
// Commit your answers (bare0_3)
//
// (If the program did not succeed back to the breakpoint
......@@ -96,6 +130,8 @@ fn main() -> ! {
// 4. Change the assertion to `assert!(x == X && X == Y + 1)`, what happens?
//
// ** place your answer here **
// panic because the assertion fails
// panicked at 'assertion failed: x == X && X == Y + 1', examples/bare0.rs:46:13
//
// Commit your answers (bare0_4)
//
......
......@@ -59,10 +59,16 @@ fn main() -> ! {
// (passing 3 breakpoints)
//
// ** your answer here **
// The program hits the first breakpoint again with a callstack
// with a lot of elements in the callstack pointing to 0x08000424
// local x variable contains various values
//
// What is the `ITM` output.
//
// ** your answer here **
// Program
// received signal SIGTRAP, Trace/breakpoint trap.
// bare1::__cortex_m_rt_main () at examples/bare1.rs:22
// 22 cortex_m::asm::bkpt();
//
// Commit your answer (bare1_1)
//
......@@ -74,16 +80,42 @@ fn main() -> ! {
// What is the output of:
// > disassemble
//
// ** your answer here **
// Please check OUTPUT tab (Adapter Output) for output from openocd
// disassemble
// Dump of assembler code for function bare1::__cortex_m_rt_main:
// 0x0800040a <+0>: sub sp, #8
// 0x0800040c <+2>: mvn.w r0, #1
// 0x08000410 <+6>: str r0, [sp, #4]
// 0x08000412 <+8>: bkpt 0x0000
// 0x08000414 <+10>: mov.w r0, #4294967295 ; 0xffffffff
// 0x08000418 <+14>: add r4, sp, #4
// 0x0800041a <+16>: str r0, [sp, #4]
// 0x0800041c <+18>: bkpt 0x0000
// 0x0800041e <+20>: mov r0, r4
// 0x08000420 <+22>: bl 0x8000400 <core::ptr::read_volatile>
// => 0x08000424 <+26>: bkpt 0x0000
// 0x08000426 <+28>: ldr r0, [sp, #4]
// 0x08000428 <+30>: adds r0, #1
// 0x0800042a <+32>: bcc.n 0x800041a <bare1::__cortex_m_rt_main+16>
// 0x0800042c <+34>: movw r0, #5984 ; 0x1760
// 0x08000430 <+38>: movt r0, #2048 ; 0x800
// 0x08000434 <+42>: movw r2, #5956 ; 0x1744
// 0x08000438 <+46>: movt r2, #2048 ; 0x800
// 0x0800043c <+50>: movs r1, #28
// 0x0800043e <+52>: bl 0x800053a <core::panicking::panic>
// 0x08000442 <+56>: udf #254 ; 0xfe
// End of assembler dump.
//
// How many instructions are in between the two `bkpt` instructions in the loop.
// Notice, the generated code may not be exactly what you expect :)
//
// ** your answer here **
// THere are 6 instrucations inbetween
//
// Which instruction stores the local variable on the stack.
//
// ** your answer here **
// 0x0800041a <+16>: str r0, [sp, #4]
//
// Commit your answers (bare1_2)
//
......@@ -99,15 +131,25 @@ fn main() -> ! {
// What is the output of:
// > disassemble
//
// ** your answer here **
// Dump of assembler code for function bare1::__cortex_m_rt_main:
// 0x08000406 <+0>: sub sp, #4
// 0x08000408 <+2>: mvn.w r0, #1
// 0x0800040c <+6>: str r0, [sp, #0]
// 0x0800040e <+8>: adds r0, #1
// 0x08000410 <+10>: bkpt 0x0000
// 0x08000412 <+12>: str r0, [sp, #0]
// => 0x08000414 <+14>: bkpt 0x0000
// 0x08000416 <+16>: ldr r0, [sp, #0]
// 0x08000418 <+18>: b.n 0x800040e <bare1::__cortex_m_rt_main+8>
// End of assembler dump.
//
// How many instructions are in between the two `bkpt` instructions.
//
// ** your answer here **
// 1
//
// Where is the local variable stored?
//
// ** your answer here **
// 0x08000412 <+12>: str r0, [sp, #0]
//
// Is there now any reference to the panic handler?
// If not, why is that the case?
......@@ -172,9 +214,21 @@ fn main() -> ! {
//
// What is now the disassembly of the loop (in debug/dev mode):
//
// ** your answer here **
//
// commit your answers (bare1_5)
// Dump of assembler code for function bare1::__cortex_m_rt_main:
// 0x0800040a <+0>: sub sp, #8
// 0x0800040c <+2>: mvn.w r0, #1
// 0x08000410 <+6>: str r0, [sp, #4]
// 0x08000412 <+8>: add r4, sp, #4
// 0x08000414 <+10>: bkpt 0x0000
// 0x08000416 <+12>: ldr r0, [sp, #4]
// 0x08000418 <+14>: adds r0, #1
// 0x0800041a <+16>: str r0, [sp, #4]
// => 0x0800041c <+18>: bkpt 0x0000
// 0x0800041e <+20>: mov r0, r4
// 0x08000420 <+22>: bl 0x8000400 <core::ptr::read_volatile>
// 0x08000424 <+26>: b.n 0x8000414 <bare1::__cortex_m_rt_main+10>
// End of assembler dump.
// commit your answers (bare1_4)
//
// Now restore the `.cargo/config` to its original state.
//
......
......@@ -18,7 +18,7 @@ use panic_halt as _;
use cortex_m::{iprintln, peripheral::DWT, Peripherals};
use cortex_m_rt::entry;
// burns CPU cycles by just looping `i` times
// burns CPU cycles by just 5looping `i` times
#[inline(never)]
fn wait(i: u32) {
for _ in 0..i {
......@@ -77,18 +77,24 @@ fn main() -> ! {
//
// What is the output in the ITM console?
//
// ** your answer here **
// bare2
// Start 2012359631
// End 2139359709
// Diff 127000078
//
// Rebuild and run in release mode
//
// > cargo build --example bare2 --release
//
// ** your answer here **
// bare2
// Start 3019839635
// End 3026839650
// Diff 7000015
//
// Compute the ratio between debug/release optimized code
// (the speedup).
//
// ** your answer here **
// 18,1428 times faster
//
// commit your answers (bare2_1)
//
......
source [find interface/stlink.cfg]
# deprecated
# source [find interface/stlink-v2-1.cfg]
source [find interface/stlink-v2-1.cfg]
transport select hla_swd
# increase working area to 64KB
......