Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
e7020e_2019
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
Ridge
e7020e_2019
Commits
42377ea6
Commit
42377ea6
authored
6 years ago
by
Ridge
Browse files
Options
Downloads
Patches
Plain Diff
bare5_1
parent
8e495dd8
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/bare4.rs
+8
-8
8 additions, 8 deletions
examples/bare4.rs
examples/bare5.rs
+4
-4
4 additions, 4 deletions
examples/bare5.rs
with
12 additions
and
12 deletions
examples/bare4.rs
+
8
−
8
View file @
42377ea6
...
...
@@ -55,15 +55,13 @@ fn wait(i: u32) {
#[entry]
fn
main
()
->
!
{
// configure PA5 as output
let
r
=
read_u32
(
GPIOA_MODER
)
&
!
(
0b11
<<
(
5
*
2
));
// read and mask
write_u32
(
GPIOA_MODER
,
r
|
0b01
<<
(
5
*
2
));
// set output mode
// power on GPIOA
let
r
=
read_u32
(
RCC_AHB1ENR
);
// read
write_u32
(
RCC_AHB1ENR
,
r
|
1
);
// set enable
// configure PA5 as output
let
r
=
read_u32
(
GPIOA_MODER
)
&
!
(
0b11
<<
(
5
*
2
));
// read and mask
write_u32
(
GPIOA_MODER
,
r
|
0b01
<<
(
5
*
2
));
// set output mode
// and alter the data output through the BSRR register
// this is more efficient as the read register is not needed.
...
...
@@ -124,16 +122,18 @@ fn main() -> ! {
//
// Why is it important that ordering of volatile operations are ensured by the compiler?
//
// ** your answer here **
// Some operations have to be executed in a specific order or the code will not act as it's desired.
// Dependencies might also be affected by the order of code.
//
// Give an example in the above code, where reordering might make things go horribly wrong
// (hint, accessing a peripheral not being powered...)
//
// ** your answer here **
// Example is changing the configure of PA5 and putting it before the power on GPIO
// resulting in the LED not blinking.
//
// Without the non-reording proprety of `write_volatile/read_volatile` could that happen in theory
// (argue from the point of data dependencies).
//
//
** your answer here **
//
If we read/write in the wrong order, we'd end up getting unexpected results, which obviously isn't good.
//
// Commit your answers (bare4_3)
This diff is collapsed.
Click to expand it.
examples/bare5.rs
+
4
−
4
View file @
42377ea6
...
...
@@ -186,14 +186,14 @@ fn idle(rcc: &mut RCC, gpioa: &mut GPIOA) {
loop
{
// set PA5 high
gpioa
.BSRRH
.write
(
1
<<
5
);
// set bit, output hight (turn on led)
//
gpioa.ODR.write(gpioa.ODR.read() | (1 << 5));
//
gpioa.BSRRH.write(1 << 5); // set bit, output hight (turn on led)
gpioa
.ODR
.write
(
gpioa
.ODR
.read
()
|
(
1
<<
5
));
wait
(
10_000
);
// set PA5 low
gpioa
.BSRRL
.write
(
1
<<
5
);
// clear bit, output low (turn off led)
//
gpioa.ODR.write(gpioa.ODR.read() & !(1 << 5));
//
gpioa.BSRRL.write(1 << 5); // clear bit, output low (turn off led)
gpioa
.ODR
.write
(
gpioa
.ODR
.read
()
&
!
(
1
<<
5
));
wait
(
10_000
);
}
}
...
...
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