Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rust-stm32f4-examples
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
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Florian Jung
rust-stm32f4-examples
Commits
0fa98325
Commit
0fa98325
authored
5 years ago
by
Florian Jung
Browse files
Options
Downloads
Patches
Plain Diff
usart support
parent
8dd413c1
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
blinky-hal/Cargo.lock
+1
-0
1 addition, 0 deletions
blinky-hal/Cargo.lock
blinky-hal/Cargo.toml
+2
-0
2 additions, 0 deletions
blinky-hal/Cargo.toml
blinky-hal/src/main.rs
+39
-4
39 additions, 4 deletions
blinky-hal/src/main.rs
with
42 additions
and
4 deletions
blinky-hal/Cargo.lock
+
1
−
0
View file @
0fa98325
...
...
@@ -38,6 +38,7 @@ dependencies = [
"cortex-m 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)",
"cortex-m-rt 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
"embedded-hal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"nb 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"panic-halt 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"stm32f4xx-hal 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
...
...
This diff is collapsed.
Click to expand it.
blinky-hal/Cargo.toml
+
2
−
0
View file @
0fa98325
...
...
@@ -39,3 +39,5 @@ version = "0.6.4"
[dependencies.panic-halt]
version
=
"0.2.0"
[dependencies.nb]
This diff is collapsed.
Click to expand it.
blinky-hal/src/main.rs
+
39
−
4
View file @
0fa98325
...
...
@@ -10,12 +10,18 @@ extern crate embedded_hal as hal;
use
cortex_m_rt
::
entry
;
use
core
::
fmt
::
Write
;
use
mcu
::
delay
::
Delay
;
use
mcu
::
prelude
::
*
;
use
mcu
::
stm32
;
use
mcu
::
gpio
;
use
mcu
::
gpio
::
gpiod
::{
PD12
,
PD13
,
PD14
,
PD15
};
use
mcu
::
serial
;
use
mcu
::
nb
::
block
;
use
hal
::
digital
::
OutputPin
;
...
...
@@ -32,6 +38,13 @@ struct Leds {
fn
main
()
->
!
{
if
let
(
Some
(
p
),
Some
(
cp
))
=
(
stm32
::
Peripherals
::
take
(),
Peripherals
::
take
())
{
let
gpiod
=
p
.GPIOD
.split
();
let
gpioa
=
p
.GPIOA
.split
();
// Constrain clock registers
let
mut
rcc
=
p
.RCC
.constrain
();
// Configure clock to 168 MHz (i.e. the maximum) and freeze it
let
clocks
=
rcc
.cfgr
.sysclk
(
84
.mhz
())
.freeze
();
// Configure LED outputs
let
mut
leds
=
Leds
{
...
...
@@ -41,11 +54,14 @@ fn main() -> ! {
blue
:
gpiod
.pd15
.into_push_pull_output
(),
};
// Constrain clock registers
let
mut
rcc
=
p
.RCC
.constrain
();
let
pin_tx
=
gpioa
.pa2
.into_alternate_af7
();
//let pin_rx = gpioa.pa3.into_alternate_af7();
let
pin_rx
=
serial
::
NoRx
;
let
mut
usart
=
serial
::
Serial
::
usart2
(
p
.USART2
,
(
pin_tx
,
pin_rx
),
serial
::
config
::
Config
::
default
()
.baudrate
(
115200
.bps
()),
clocks
)
.unwrap
();
// separate into tx and rx channels
let
(
mut
tx
,
mut
rx
)
=
usart
.split
();
// Configure clock to 168 MHz (i.e. the maximum) and freeze it
let
clocks
=
rcc
.cfgr
.sysclk
(
84
.mhz
())
.freeze
();
// Get delay provider
let
mut
delay
=
Delay
::
new
(
cp
.SYST
,
clocks
);
...
...
@@ -54,6 +70,25 @@ fn main() -> ! {
// Turn LED on
leds
.blue
.set_high
();
/*tx.write(b'h').ok();
tx.write(b'e').ok();
tx.write(b'l').ok();
tx.write(b'l').ok();
tx.write(b'o').ok();
tx.write(b'\r').ok();
tx.write(b'\n').ok();*/
/*block!(usart.write(b'h')).ok();
block!(usart.write(b'e')).ok();
block!(usart.write(b'l')).ok();
block!(usart.write(b'l')).ok();
block!(usart.write(b'o')).ok();*/
//usart.write_str("foo");
tx
.write_str
(
"foo"
);
writeln!
(
tx
,
"bar"
);
// Delay twice for half a second due to limited timer resolution
delay
.delay_ms
(
500_u16
);
delay
.delay_ms
(
500_u16
);
...
...
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