Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
app
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Per Lindgren
app
Commits
f6e957a9
Commit
f6e957a9
authored
6 years ago
by
Per Lindgren
Browse files
Options
Downloads
Patches
Plain Diff
bare0
parent
111fa3d7
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
.vscode/launch.json
+13
-0
13 additions, 0 deletions
.vscode/launch.json
.vscode/tasks.json
+12
-0
12 additions, 0 deletions
.vscode/tasks.json
examples/bare0.rs
+101
-0
101 additions, 0 deletions
examples/bare0.rs
with
126 additions
and
0 deletions
.vscode/launch.json
+
13
−
0
View file @
f6e957a9
...
@@ -155,6 +155,19 @@
...
@@ -155,6 +155,19 @@
"svdFile"
:
"STM32F413.svd"
,
"svdFile"
:
"STM32F413.svd"
,
"cwd"
:
"${workspaceRoot}"
"cwd"
:
"${workspaceRoot}"
},
},
{
"type"
:
"cortex-debug"
,
"request"
:
"launch"
,
"servertype"
:
"openocd"
,
"name"
:
"bare0 (debug)"
,
"preLaunchTask"
:
"cargo build --example bare0"
,
"executable"
:
"./target/thumbv7em-none-eabihf/debug/examples/bare0"
,
"configFiles"
:
[
"interface/stlink.cfg"
,
"target/stm32f4x.cfg"
],
"cwd"
:
"${workspaceRoot}"
},
{
{
"type"
:
"cortex-debug"
,
"type"
:
"cortex-debug"
,
"request"
:
"launch"
,
"request"
:
"launch"
,
...
...
This diff is collapsed.
Click to expand it.
.vscode/tasks.json
+
12
−
0
View file @
f6e957a9
...
@@ -75,5 +75,17 @@
...
@@ -75,5 +75,17 @@
"isDefault"
:
true
"isDefault"
:
true
}
}
},
},
{
"type"
:
"shell"
,
"label"
:
"cargo build --example bare0"
,
"command"
:
"cargo build --example bare0"
,
"problemMatcher"
:
[
"$rustc"
],
"group"
:
{
"kind"
:
"build"
,
"isDefault"
:
true
}
},
]
]
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
examples/bare0.rs
0 → 100644
+
101
−
0
View file @
f6e957a9
//! bare0.rs
//!
//! Simple bare metal application
//! What it covers:
//! - constants
//! - global (static) variables
//! - checked vs. wrapping arithmetics
//! - safe and unsafe code
//! - making a safe API
//!
// build without the Rust standard library
#![no_std]
// no standard main, we declare main using [entry]
#![no_main]
extern
crate
panic_halt
;
// Minimal runtime / startup for Cortex-M microcontrollers
use
cortex_m_rt
::
entry
;
// a constant (cannot be changed)
const
X_INIT
:
u32
=
10
;
// global mutabale variables (changed using unsafe code)
static
mut
X
:
u32
=
X_INIT
;
static
mut
Y
:
u32
=
0
;
#[entry]
fn
main
()
->
!
{
// local mutabale variable (changed in safe code)
let
mut
x
=
unsafe
{
X
};
loop
{
x
+=
1
;
// <- place breakpoint here (3)
unsafe
{
X
+=
1
;
Y
=
X
;
assert!
(
x
==
X
&&
X
==
Y
);
}
}
}
// 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 **
//
// in the Expressions (WATCH -vscode) view add X and Y
// what do you find
//
// ** your answer here **
// 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 **
//
// 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 **
//
// commit your answers (bare0_2)
//
// 3. place a breakpoint at `x += 1`
// change (both) += opertions to use wrapping_add
// load and run the progam, what happens
// ** your answer here **
//
// now continue exectution, what happens
// ** your answer here **
//
// commit your answers (bare0_3)
//
// (if the program did not succeed back to the breakpoint
// 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
// ** place your answer here **
//
// commit your answers (bare0_4)
//
// 5. remove the assertion and
//
// make "safe" functions for reading and writing X and Y
// e.g. read_x, read_y, write_x, write_y
//
// rewrite the program to use ONLY "safe" code besides the
// read/write functions (which are internally "unsafe")
//
// commit your solution (bare0_5)
//
// 6*. optional
// implement a read_u32/write_u32, taking a reference to a
// "static" variable
//
// rewrite the program to use this abstraction instead of "read_x", etc.
//
// commit your solution (bare0_6)
//
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment