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
Samuel Karlsson
rtfm-app
Commits
090c36bc
Commit
090c36bc
authored
7 years ago
by
Per Lindgren
Browse files
Options
Downloads
Patches
Plain Diff
tmp
parent
33bbe8dc
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/bare5.rs
+33
-21
33 additions, 21 deletions
examples/bare5.rs
with
33 additions
and
21 deletions
examples/bare5.rs
+
33
−
21
View file @
090c36bc
...
...
@@ -119,35 +119,47 @@ fn wait(i: u32) {
}
}
// system startup, can be hidden from the user
fn
main
()
{
// power on GPIOA, RM0368 6.3.11
let
rcc
=
RCC
::
get
();
// get the reference to RCC in memory
unsafe
{
let
r
=
(
*
rcc
)
.AHB1ENR
.read
();
// read
(
*
rcc
)
.AHB1ENR
.write
(
r
|
1
<<
(
0
));
// set enable
}
let
rcc
=
unsafe
{
&
mut
*
RCC
::
get
()
};
// get the reference to RCC in memory
let
gpioa
=
unsafe
{
&
mut
*
GPIOA
::
get
()
};
// get the reference to GPIOA in memory
idle
(
rcc
,
gpioa
);
}
// configure PA5 as output, RM0368 8.4.1
let
gpioa
=
GPIOA
::
get
();
// get the reference to GPIOA in memory
unsafe
{
let
r
=
(
*
gpioa
)
.MODER
.read
()
&
!
(
0b11
<<
(
5
*
2
));
// read and mask
(
*
gpioa
)
.MODE
R
.write
(
r
|
0b0
1
<<
(
5
*
2
));
// set
output mod
e
// user application
fn
idle
(
rcc
:
&
mut
RCC
,
gpioa
:
&
mut
GPIOA
)
{
// power on GPIOA
let
r
=
(
*
rcc
)
.AHB1ENR
.read
();
// read
(
*
rcc
)
.AHB1EN
R
.write
(
r
|
1
<<
(
0
));
// set
enabl
e
// and alter the data output through the BSRR register
// this is more efficient as the read register is not needed.
// configure PA5 as output
let
r
=
(
*
gpioa
)
.MODER
.read
()
&
!
(
0b11
<<
(
5
*
2
));
// read and mask
(
*
gpioa
)
.MODER
.write
(
r
|
0b01
<<
(
5
*
2
));
// set output mode
loop
{
// set PA5 high, RM0368 8.4.7
(
*
gpioa
)
.BSRRH
.write
(
1
<<
5
);
// set bit, output hight (turn on led)
wait
(
10_000
);
// and alter the data output through the BSRR register
// this is more efficient as the read register is not needed.
// set PA5 low, RM0368 8.4.7
(
*
gpioa
)
.BSRRL
.write
(
1
<<
5
);
// clear bit, output low (turn off led)
wait
(
10_000
);
}
loop
{
// set PA5 high
(
*
gpioa
)
.BSRRH
.write
(
1
<<
5
);
// set bit, output hight (turn on led)
wait
(
10_000
);
// set PA5 low
(
*
gpioa
)
.BSRRL
.write
(
1
<<
5
);
// clear bit, output low (turn off led)
wait
(
10_000
);
}
}
// 1. C like API
// In C the .h files are used for defining interfaces, like function signatures (prototypes),
// structs and macros (but usually not the functions themselves)
// here is a peripheral abstraction quite similar to what you would find in the .h files
// provided by ST (and other companies). Actually, the file presesnted here is mostly a
// cut/paste/replace of the stm32f40x.h, just Rustified.
//
// Here all peripheral access is unsafe, (as we are dereferencing raw pointers). In the code
// we have fairly large unsafe blocks. Your task here is to
// As we are not using interrupts, we just register a dummy catch all handler
#[link_section
=
".vector_table.interrupts"
]
#[used]
...
...
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