Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
e7020e_2020
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
Mark Hakansson
e7020e_2020
Commits
1e2daa2c
Commit
1e2daa2c
authored
5 years ago
by
Per Lindgren
Browse files
Options
Downloads
Patches
Plain Diff
bare0/1 polish
parent
c45dc28a
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/bare0.rs
+5
-9
5 additions, 9 deletions
examples/bare0.rs
examples/bare1.rs
+40
-10
40 additions, 10 deletions
examples/bare1.rs
with
45 additions
and
19 deletions
examples/bare0.rs
+
5
−
9
View file @
1e2daa2c
...
...
@@ -15,19 +15,15 @@
// no standard main, we declare main using [entry]
#![no_main]
// Minimal runtime / startup for Cortex-M microcontrollers
//extern crate cortex_m_rt as rt;
// Panic handler, for textual output using semihosting
extern
crate
panic_semihosting
;
// Panic handler, infinite loop on panic
// extern crate panic_halt;
use
panic_semihosting
as
_
;
// import entry point
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
;
...
...
@@ -50,10 +46,10 @@ fn main() -> ! {
// Here we assume you are using `vscode` with `cortex-debug`.
//
// 0. Compile/build the example in debug (dev) mode.
// 0. Compile/build
and run
the example in debug (dev) mode.
//
// > cargo
build
--example bare0
// (or use
the
vscode
build task
)
// > cargo
run
--example bare0
// (or use vscode)
//
// 1. Run the program in the debugger, let the program run for a while and
// then press pause.
...
...
This diff is collapsed.
Click to expand it.
examples/bare1.rs
+
40
−
10
View file @
1e2daa2c
...
...
@@ -10,7 +10,7 @@
#![no_main]
#![no_std]
extern
crat
e
panic_itm
;
us
e
panic_itm
as
_
;
use
cortex_m_rt
::
entry
;
...
...
@@ -49,14 +49,14 @@ fn main() -> ! {
//
// 1. Build and run the application
//
// > cargo
build
--example bare1
// (or use the
vsco
de
bu
ild task
)
// > cargo
run
--example bare1
// (or use the
`itm fifo (
debu
g)` or the `itm internal (debug)` launch configuration.
)
//
// Make sure you have followed the instructions for fifo `ITM` tracing.
// Debug using the `itm fifo (debug)` launch configuration.
// Make sure you have followed the instructions for fifo `ITM` tracing accordingly.
//
// When debugging the application it should hit the `bkpt` instruction.
// What happens when you continue (second iteration of the loop)?
// (passing 3 breakpoints)
//
// ** your answer here **
//
...
...
@@ -91,7 +91,7 @@ fn main() -> ! {
// Rebuild `bare1.rs` in release (optimized mode).
//
// > cargo build --example bare1 --release
// (or using the vscode
build task
)
// (or using the vscode)
//
// Compare the generated assembly for the loop
// between the dev (un-optimized) and release (optimized) build.
...
...
@@ -109,6 +109,11 @@ fn main() -> ! {
//
// ** your answer here **
//
// Is there now any reference to the panic handler?
// If not, why is that the case?
//
// ** your answer here **
//
// commit your answers (bare1_3)
//
// Discussion:
...
...
@@ -131,7 +136,32 @@ fn main() -> ! {
// Later we will demonstrate how we can get guarantees of panic free execution.
// This is very important to improve reliability.
//
// 4. *Optional
// 4. Now comment out the `read_volatile`.
//
// > cargo build --example bare1 --release
// (or using the vscode)
//
// Compare the generated assembly for the loop
// between the dev (un-optimized) and release (optimized) build.
//
// What is the output of:
// > disassemble
//
// ** your answer here **
//
// How many instructions are in between the two `bkpt` instructions.
//
// ** your answer here **
//
// Where is the local variable stored?
// What happened, and why is Rust + LLVM allowed to do that?
//
// ** your answer here **
//
// commit your answers (bare1_4)
//
//
// 5. *Optional
// You can pass additional flags to the Rust `rustc` compiler.
//
// `-Z force-overflow-checks=off`
...
...
@@ -144,11 +174,11 @@ fn main() -> ! {
//
// ** your answer here **
//
// commit your answers (bare1_
4
)
// commit your answers (bare1_
5
)
//
// Now restore the `.cargo/config` to its original state.
//
//
5
. *Optional
//
6
. *Optional
// There is another way to conveniently use wrapping arithmetics
// without passing flags to the compiler.
//
...
...
@@ -164,7 +194,7 @@ fn main() -> ! {
//
// ** your answer here **
//
// commit your answers (bare1_
5
)
// commit your answers (bare1_
6
)
//
// Final discussion:
//
...
...
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