Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
N
nucleo-64
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Per Lindgren
nucleo-64
Commits
7ea82ddd
Commit
7ea82ddd
authored
Oct 19, 2017
by
Per
Browse files
Options
Downloads
Patches
Plain Diff
println and gpio
parent
93ae125c
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
.vscode/tasks.json
+16
-5
16 additions, 5 deletions
.vscode/tasks.json
examples/gpio.rs
+8
-10
8 additions, 10 deletions
examples/gpio.rs
examples/usart1.rs
+11
-0
11 additions, 0 deletions
examples/usart1.rs
src/lib.rs
+12
-0
12 additions, 0 deletions
src/lib.rs
with
47 additions
and
15 deletions
.vscode/tasks.json
+
16
−
5
View file @
7ea82ddd
...
@@ -25,16 +25,27 @@
...
@@ -25,16 +25,27 @@
"command"
:
"xargo build --example gpio"
,
"command"
:
"xargo build --example gpio"
,
"problemMatcher"
:
[
"problemMatcher"
:
[
"$rustc"
"$rustc"
]
],
"group"
:
{
"kind"
:
"build"
,
"isDefault"
:
true
}
},
},
{
{
"taskName"
:
"xargo build --example usart1"
,
"taskName"
:
"xargo build --example usart1"
,
"type"
:
"shell"
,
"type"
:
"shell"
,
"command"
:
"xargo build --example usart1"
,
"command"
:
"xargo build --example usart1"
,
"
g
ro
up
"
:
{
"
p
ro
blemMatcher
"
:
[
"
kind"
:
"build"
,
"
$rustc"
"isDefault"
:
true
]
},
},
{
"type"
:
"shell"
,
"taskName"
:
"cargo build"
,
"command"
:
"cargo"
,
"args"
:
[
"build"
],
"problemMatcher"
:
[
"problemMatcher"
:
[
"$rustc"
"$rustc"
]
]
...
...
This diff is collapsed.
Click to expand it.
examples/gpio.rs
+
8
−
10
View file @
7ea82ddd
...
@@ -5,13 +5,11 @@
...
@@ -5,13 +5,11 @@
#![no_std]
#![no_std]
extern
crate
cortex_m_rtfm
as
rtfm
;
extern
crate
cortex_m_rtfm
as
rtfm
;
extern
crate
cortex_m_semihosting
as
semihosting
;
#[macro_use]
extern
crate
nucleo_64
;
extern
crate
nucleo_64
;
extern
crate
stm32f40x
;
extern
crate
stm32f40x
;
use
rtfm
::
app
;
use
rtfm
::
app
;
use
semihosting
::
hio
;
use
core
::
fmt
::
Write
;
use
nucleo_64
::
gpio
::
PA5
;
use
nucleo_64
::
gpio
::
PA5
;
app!
{
app!
{
...
@@ -19,7 +17,7 @@ app! {
...
@@ -19,7 +17,7 @@ app! {
}
}
fn
init
(
p
:
init
::
Peripherals
)
{
fn
init
(
p
:
init
::
Peripherals
)
{
w
rit
e
ln!
(
hio
::
hstdout
()
.unwrap
(),
"Init!"
)
.unwrap
(
);
p
ri
n
tln!
(
"Init!"
);
// RM0368 6.3.9
// RM0368 6.3.9
// enable clock to GPIOA
// enable clock to GPIOA
p
.RCC.ahb1enr
.modify
(|
_
,
w
|
w
.gpioaen
()
.enable
());
p
.RCC.ahb1enr
.modify
(|
_
,
w
|
w
.gpioaen
()
.enable
());
...
@@ -33,12 +31,12 @@ fn init(p: init::Peripherals) {
...
@@ -33,12 +31,12 @@ fn init(p: init::Peripherals) {
}
}
fn
idle
()
->
!
{
fn
idle
()
->
!
{
writeln!
(
hio
::
hstdout
()
.unwrap
(),
"PA5 high!"
)
.unwrap
();
loop
{
println!
(
"PA5 high!"
);
PA5
.high
();
PA5
.high
();
writeln!
(
hio
::
hstdout
()
.unwrap
(),
"PA5 low!"
)
.unwrap
();
rtfm
::
bkpt
();
println!
(
"PA5 low!"
);
PA5
.low
();
PA5
.low
();
// Sleep
rtfm
::
bkpt
();
loop
{
rtfm
::
wfi
();
}
}
}
}
This diff is collapsed.
Click to expand it.
examples/usart1.rs
+
11
−
0
View file @
7ea82ddd
...
@@ -11,6 +11,7 @@
...
@@ -11,6 +11,7 @@
extern
crate
cortex_m_rtfm
as
rtfm
;
extern
crate
cortex_m_rtfm
as
rtfm
;
extern
crate
cortex_m_semihosting
as
semihosting
;
extern
crate
cortex_m_semihosting
as
semihosting
;
#[macro_use]
extern
crate
nb
;
extern
crate
nb
;
extern
crate
nucleo_64
;
extern
crate
nucleo_64
;
extern
crate
stm32f40x
;
extern
crate
stm32f40x
;
...
@@ -109,6 +110,15 @@ fn init(p: init::Peripherals) {
...
@@ -109,6 +110,15 @@ fn init(p: init::Peripherals) {
// serial.init(BAUD_RATE.invert(), p.AFIO, None, p.GPIOA, p.RCC);
// serial.init(BAUD_RATE.invert(), p.AFIO, None, p.GPIOA, p.RCC);
// echo incoming
loop
{
let
b
=
block!
(
read
(
p
.USART2
))
.unwrap
();
write
(
p
.USART2
,
b
)
.unwrap
();
}
const
BYTE
:
u8
=
b'A'
;
const
BYTE
:
u8
=
b'A'
;
assert!
(
write
(
p
.USART2
,
BYTE
)
.is_ok
());
assert!
(
write
(
p
.USART2
,
BYTE
)
.is_ok
());
...
@@ -140,6 +150,7 @@ pub enum Error {
...
@@ -140,6 +150,7 @@ pub enum Error {
Overrun
,
Overrun
,
#[doc(hidden)]
_Extensible
,
#[doc(hidden)]
_Extensible
,
}
}
fn
write
(
usart2
:
&
USART2
,
byte
:
u8
)
->
Result
<
()
>
{
fn
write
(
usart2
:
&
USART2
,
byte
:
u8
)
->
Result
<
()
>
{
let
sr
=
usart2
.sr
.read
();
let
sr
=
usart2
.sr
.read
();
...
...
This diff is collapsed.
Click to expand it.
src/lib.rs
+
12
−
0
View file @
7ea82ddd
...
@@ -139,3 +139,15 @@ pub mod apb1 {
...
@@ -139,3 +139,15 @@ pub mod apb1 {
pub
mod
apb2
{
pub
mod
apb2
{
frequency!
(
16_000_000
);
frequency!
(
16_000_000
);
}
}
/// println over semihosting
#[macro_export]
macro_rules!
println
{
(
$e:expr
)
=>
{
{
extern
crate
cortex_m_semihosting
;
use
core
::
fmt
::
Write
;
writeln!
(
cortex_m_semihosting
::
hio
::
hstdout
()
.unwrap
(),
$e
)
.unwrap
();
}
}
}
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