Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
rtfm-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
rtfm-app
Commits
73157781
Commit
73157781
authored
7 years ago
by
Per
Browse files
Options
Downloads
Patches
Plain Diff
bare7 broken
parent
e037976e
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/bare7.rs
+28
-21
28 additions, 21 deletions
examples/bare7.rs
with
28 additions
and
21 deletions
examples/bare7.rs
+
28
−
21
View file @
73157781
//! Serial interface loopback
#![deny(unsafe_code)]
#![deny(warnings)]
//
#![deny(warnings)]
#![feature(proc_macro)]
#![no_std]
extern
crate
cortex_m_rtfm
as
rtfm
;
extern
crate
f4
;
extern
crate
heapless
;
#[macro_use(block)]
extern
crate
nb
;
#[macro_use]
extern
crate
cortex_m_debug
;
use
f4
::
prelude
::
*
;
use
f4
::
Serial
;
use
f4
::
serial
::
Event
;
use
f4
::
time
::
Hertz
;
use
heapless
::
Vec
;
use
rtfm
::{
app
,
Threshold
};
// CONFIGURATION
const
BAUD_RATE
:
Hertz
=
Hertz
(
115_200
);
//
TASKS & RESOURCES
//
RTFM FRAMEWORK
app!
{
device
:
f4
::
stm32f40x
,
tasks
:
{
USART2
:
{
path
:
loopback
,
resources
:
[
USART2
],
},
}
}
// static BUFFER: Vec<u8, [u8; 8]> = Vec::new();
// INITIALIZATION PHASE
// Init executes with interrupts disabled
// Hence its safe to access all peripherals (no race-conditions)
//
// In this case init will never return
// This is not the typical use-case as we will see later
fn
init
(
p
:
init
::
Peripherals
)
{
ipln!
(
"init"
);
let
serial
=
Serial
(
p
.USART2
);
serial
.init
(
BAUD_RATE
.invert
(),
None
,
p
.GPIOA
,
p
.RCC
);
serial
.listen
(
Event
::
Rxne
);
let
mut
buffer
:
Vec
<
u8
,
[
u8
;
4
]
>
=
Vec
::
new
();
loop
{
if
let
Ok
(
byte
)
=
block!
(
serial
.read
())
{
buffer
.push
(
byte
);
ipln!
(
"Ok {:?}"
,
buffer
);
block!
(
serial
.write
(
byte
))
.ok
();
}
else
{
ipln!
(
"Error"
);
}
}
}
// IDLE LOOP
...
...
@@ -44,15 +60,6 @@ fn idle() -> ! {
}
}
// TASKS
// Send back the received byte
fn
loopback
(
_t
:
&
mut
Threshold
,
r
:
USART2
::
Resources
)
{
let
serial
=
Serial
(
&**
r
.USART2
);
let
byte
=
serial
.read
()
.unwrap
();
serial
.write
(
byte
)
.unwrap
();
}
// 1. compile and run the project at 16MHz
// make sure its running (not paused)
// start a terminal program, e.g., `moserial`
...
...
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