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
2246228d
Commit
2246228d
authored
7 years ago
by
Per Lindgren
Browse files
Options
Downloads
Patches
Plain Diff
bare6 84hmz
parent
6deb811a
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/bare7.rs
+95
-0
95 additions, 0 deletions
examples/bare7.rs
with
95 additions
and
0 deletions
examples/bare7.rs
0 → 100644
+
95
−
0
View file @
2246228d
//! Serial interface loopback
#![deny(unsafe_code)]
#![deny(warnings)]
#![feature(proc_macro)]
#![no_std]
extern
crate
cortex_m_rtfm
as
rtfm
;
extern
crate
f4
;
use
f4
::
prelude
::
*
;
use
f4
::
Serial
;
use
f4
::
serial
::
Event
;
use
f4
::
time
::
Hertz
;
use
rtfm
::{
app
,
Threshold
};
// CONFIGURATION
const
BAUD_RATE
:
Hertz
=
Hertz
(
115_200
);
// TASKS & RESOURCES
app!
{
device
:
f4
::
stm32f40x
,
tasks
:
{
USART2
:
{
path
:
loopback
,
resources
:
[
USART2
],
},
}
}
// INITIALIZATION PHASE
fn
init
(
p
:
init
::
Peripherals
)
{
let
serial
=
Serial
(
p
.USART2
);
serial
.init
(
BAUD_RATE
.invert
(),
None
,
p
.GPIOA
,
p
.RCC
);
serial
.listen
(
Event
::
Rxne
);
}
// IDLE LOOP
fn
idle
()
->
!
{
// Sleep
loop
{
rtfm
::
wfi
();
}
}
// 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`
// connect to the port
//
// Device /dev/ttyACM0
// Baude Rate 115200
// Data Bits 8
// Stop Bits 1
// Parity None
// Handshake None
//
// (this is also known in short as 15200 8N1)
//
// you should now be able to send data and recive an echo from the MCU
//
// try sending: "abcd"
//
// what did you receive
// ** your answer here **
//
// try changing to baud rate 57600, both in the program and terminal settings,
// recompile and run
//
// try sending: "abcd"
// what did you receive
// ** your answer here **
//
// commit your answers as (bare7_1)
//
// 2. now you should make a buffer
// static BUFFER [u8;8]
// to store the incoming data
//
// this can be done in a resource
// app
//
// when the buffer is full you should write the complete buffer
//
//
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