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
Anton Grahn
e7020e_2020
Commits
9536bd2b
Commit
9536bd2b
authored
5 years ago
by
Per Lindgren
Browse files
Options
Downloads
Patches
Plain Diff
bare8 (updated to RTFM5)
parent
04d90f99
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/bare8.rs
+29
-44
29 additions, 44 deletions
examples/bare8.rs
with
29 additions
and
44 deletions
examples/bare8.rs
+
29
−
44
View file @
9536bd2b
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
extern
crate
panic_halt
;
extern
crate
panic_halt
;
use
cortex_m
::
{
asm
,
iprintln
}
;
use
cortex_m
::
iprintln
;
use
nb
::
block
;
use
nb
::
block
;
extern
crate
stm32f4xx_hal
as
hal
;
extern
crate
stm32f4xx_hal
as
hal
;
...
@@ -24,16 +24,21 @@ use hal::stm32::{ITM, USART2};
...
@@ -24,16 +24,21 @@ use hal::stm32::{ITM, USART2};
use
rtfm
::
app
;
use
rtfm
::
app
;
#[app(device
=
hal::stm32)]
#[app(device
=
hal::stm32
,
peripherals
=
true
)]
const
APP
:
()
=
{
const
APP
:
()
=
{
// Late resources
struct
Resources
{
static
mut
TX
:
Tx
<
USART2
>
=
();
// Late resources
static
mut
RX
:
Rx
<
USART2
>
=
();
TX
:
Tx
<
USART2
>
,
static
mut
ITM
:
ITM
=
();
RX
:
Rx
<
USART2
>
,
ITM
:
ITM
,
}
// init runs in an interrupt free section
// init runs in an interrupt free section
#[init]
#[init]
fn
init
()
{
fn
init
(
cx
:
init
::
Context
)
->
init
::
LateResources
{
let
mut
core
=
cx
.core
;
let
device
=
cx
.device
;
let
stim
=
&
mut
core
.ITM.stim
[
0
];
let
stim
=
&
mut
core
.ITM.stim
[
0
];
iprintln!
(
stim
,
"bare8"
);
iprintln!
(
stim
,
"bare8"
);
...
@@ -45,9 +50,7 @@ const APP: () = {
...
@@ -45,9 +50,7 @@ const APP: () = {
let
gpioa
=
device
.GPIOA
.split
();
let
gpioa
=
device
.GPIOA
.split
();
let
tx
=
gpioa
.pa2
.into_alternate_af7
();
let
tx
=
gpioa
.pa2
.into_alternate_af7
();
let
rx
=
gpioa
.pa3
.into_alternate_af7
();
let
rx
=
gpioa
.pa3
.into_alternate_af7
();
asm
::
bkpt
();
let
serial
=
Serial
::
usart2
(
let
serial
=
Serial
::
usart2
(
device
.USART2
,
device
.USART2
,
...
@@ -61,23 +64,25 @@ const APP: () = {
...
@@ -61,23 +64,25 @@ const APP: () = {
let
(
tx
,
rx
)
=
serial
.split
();
let
(
tx
,
rx
)
=
serial
.split
();
// Late resources
// Late resources
TX
=
tx
;
init
::
LateResources
{
RX
=
rx
;
TX
:
tx
,
ITM
=
core
.ITM
;
RX
:
rx
,
ITM
:
core
.ITM
,
}
}
}
// idle may be interrupted by other interrupt/tasks in the system
// idle may be interrupted by other interrupt
s
/tasks in the system
#[idle(resources
=
[
RX,
TX,
ITM]
)]
#[idle(resources
=
[
RX,
TX,
ITM]
)]
fn
idle
()
->
!
{
fn
idle
(
cx
:
idle
::
Context
)
->
!
{
let
rx
=
resources
.RX
;
let
rx
=
cx
.
resources.RX
;
let
tx
=
resources
.TX
;
let
tx
=
cx
.
resources.TX
;
let
stim
=
&
mut
resources
.ITM.stim
[
0
];
let
stim
=
&
mut
cx
.
resources.ITM.stim
[
0
];
loop
{
loop
{
match
block!
(
rx
.read
())
{
match
block!
(
rx
.read
())
{
Ok
(
byte
)
=>
{
Ok
(
byte
)
=>
{
iprintln!
(
stim
,
"Ok {:?}"
,
byte
);
iprintln!
(
stim
,
"Ok {:?}"
,
byte
);
tx
.write
(
byte
)
.unwrap
();
tx
.write
(
byte
)
.unwrap
();
}
}
Err
(
err
)
=>
{
Err
(
err
)
=>
{
iprintln!
(
stim
,
"Error {:?}"
,
err
);
iprintln!
(
stim
,
"Error {:?}"
,
err
);
...
@@ -87,32 +92,13 @@ const APP: () = {
...
@@ -87,32 +92,13 @@ const APP: () = {
}
}
};
};
// Optional assignment
// 0. Compile and run the example. Notice, we use the default 16MHz clock.
// 0. Compile and run the example. Notice, we use the default 16MHz clock.
//
//
// > cargo build --example bare
7
--features "
hal
rtfm"
// > cargo build --example bare
8
--features "rtfm"
// (or use the vscode build task)
// (or use the vscode build task)
//
//
// The "hal" feature enables the optional dependencies stm32f4xx-hal and rtfm".
// 1. What is the behavior in comparison to bare7.4 and bare7.5
//
// Cargo.toml:
//
// [dependencies.cortex-m-rtfm]
// version = "0.4.0"
// optional = true
//
// [dependencies.stm32f4xx-hal]
// git = "https://github.com/stm32-rs/stm32f4xx-hal.git"
// version = "0.2.8"
// features = ["stm32f413", "rt"]
// optional = true
//
// [features]
// pac = ["stm32f4"]
// hal = ["stm32f4xx-hal"]
// rtfm = ["cortex-m-rtfm"]
//
// 1. Our CPU now runs slower, did it effect the behavior?
//
//
// ** your answer here **
// ** your answer here **
//
//
...
@@ -129,7 +115,7 @@ const APP: () = {
...
@@ -129,7 +115,7 @@ const APP: () = {
// (are you know loosing more data)?
// (are you know loosing more data)?
//
//
// ** your answer here **
// ** your answer here **
//
//
// Commit your answer (bare8_3)
// Commit your answer (bare8_3)
//
//
// 4. *Optional
// 4. *Optional
...
@@ -140,6 +126,5 @@ const APP: () = {
...
@@ -140,6 +126,5 @@ const APP: () = {
// How did the optimized build compare to the debug build (performance/lost bytes)
// How did the optimized build compare to the debug build (performance/lost bytes)
//
//
// ** your answer here **
// ** your answer here **
//
//
// Commit your answer (bare8_4)
// Commit your answer (bare8_4)
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