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
95e6b2aa
Commit
95e6b2aa
authored
7 years ago
by
Per
Browse files
Options
Downloads
Patches
Plain Diff
bare 7
parent
6268c73d
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/bare7.rs
+40
-22
40 additions, 22 deletions
examples/bare7.rs
with
40 additions
and
22 deletions
examples/bare7.rs
+
40
−
22
View file @
95e6b2aa
//! Serial interface loopback
#![deny(unsafe_code)]
//
#![deny(warnings)]
#![deny(warnings)]
#![feature(proc_macro)]
#![no_std]
...
...
@@ -18,7 +18,7 @@ use f4::prelude::*;
use
f4
::
Serial
;
use
f4
::
time
::
Hertz
;
use
heapless
::
Vec
;
use
rtfm
::
{
app
,
Threshold
}
;
use
rtfm
::
app
;
// CONFIGURATION
const
BAUD_RATE
:
Hertz
=
Hertz
(
115_200
);
...
...
@@ -42,17 +42,21 @@ fn init(p: init::Peripherals) {
let
mut
buffer
:
Vec
<
u8
,
[
u8
;
4
]
>
=
Vec
::
new
();
loop
{
if
let
Ok
(
byte
)
=
block!
(
serial
.read
())
{
buffer
.push
(
byte
);
match
block!
(
serial
.read
())
{
Ok
(
byte
)
=>
{
let
_
=
buffer
.push
(
byte
);
ipln!
(
"Ok {:?}"
,
buffer
);
block!
(
serial
.write
(
byte
))
.ok
();
}
else
{
ipln!
(
"Error"
);
}
Err
(
err
)
=>
{
ipln!
(
"Error {:?}"
,
err
);
p
.USART2.dr
.read
();
// clear the error by reading the data register
}
}
}
}
//
IDLE LOOP
//
We will never reach `idle` since we burn the CPU arduino style :)
fn
idle
()
->
!
{
// Sleep
loop
{
...
...
@@ -76,27 +80,41 @@ fn idle() -> ! {
//
// you should now be able to send data and recive an echo from the MCU
//
// try sending: "abcd"
// try sending: "abcd" as a single sequence (set the option No end in moserial)
// (don't send the quation marks, just abcd)
//
// what did you receive
// what did you receive
, and what was the output of the ITM trace
// ** your answer here **
//
// try changing to baud rate 57600, both in the program and terminal settings,
// recompile and run
// now try sending 'a', 'b', 'c', 'd' character by character
// (just send the characters not the single quotes and commas)
// what did you receive, and what was the output of the ITM trace
// ** your answer here **
//
// try sending: "abcd"
// what did you receive
// why did the transmission fail? (hint, think about timing...)
// ** your answer here **
//
// commit your answers as (bare7_1)
// commit your answers (bare7_1)
//
// 2. now stress the buffer lengt sending a sequence
// 'a', 'b', 'c', 'd', 'e' character by character
// what did you receive, and what was the output of the ITM trace
// ** your answer here **
//
//
2. now you should make a buffer
//
static BUFFER [u8;8]
//
to store the incoming data
//
if done correctly you see an evedince of Rust's memory safety
//
the buffer will be saturated (all elements occupied)
//
but no buffer owerwrite will occur (outside the buffer)
//
//
this can be done in a resource
//
app
//
your job now is to check the API of `heapless`
//
https://docs.rs/heapless/0.2.1/heapless/
//
// when the buffer is full you should write the complete buffer
// and catch the case we are trying to write to a full buffer
// and write a suiteble error message
//
// commit your answers (bare7_2)
//
// !!!!! NOTICE !!!!!
// here we are not solving the underlying problem
// we are just mitigating the effects
// in bare8 we will se how to use interrupts for reliable
// high-speed communictation
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