Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
e7020e_2021
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
Package registry
Model registry
Operate
Environments
Terraform modules
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
Tommy Andersson
e7020e_2021
Commits
4897099e
Commit
4897099e
authored
Mar 5, 2021
by
Jonas Jacobsson
Browse files
Options
Downloads
Patches
Plain Diff
Did my best
parent
7e456dfe
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/rtic_bare5.rs
+18
-17
18 additions, 17 deletions
examples/rtic_bare5.rs
with
18 additions
and
17 deletions
examples/rtic_bare5.rs
+
18
−
17
View file @
4897099e
//! bare5.rs
//!
rtic_
bare5.rs
//!
//! C Like Peripheral API
//!
...
...
@@ -11,6 +11,7 @@
extern
crate
cortex_m
;
extern
crate
panic_semihosting
;
//use bitvec::prelude::*; <-- Might wont to look in to this.
// C like API...
mod
stm32f40x
{
...
...
@@ -58,7 +59,9 @@ mod stm32f40x {
impl
VolatileCell
<
u32
>
{
#[inline(always)]
pub
fn
modify
(
&
self
,
offset
:
u8
,
width
:
u8
,
value
:
u32
)
{
// your code here
let
mut
value_mut
=
value
<<
32
-
width
;
value_mut
=
value_mut
>>
32
-
width
;
self
.write
(
value_mut
<<
offset
);
}
}
...
...
@@ -177,32 +180,31 @@ const APP: () = {
let
r
=
gpioa
.MODER
.read
()
&
!
(
0b11
<<
(
5
*
2
));
// read and mask
gpioa
.MODER
.write
(
r
|
0b01
<<
(
5
*
2
));
// set output mode
// test_modify();
test_modify
();
loop
{
// set PA5 high
gpioa
.BSRRH
.write
(
1
<<
5
);
// set bit, output hight (turn on led)
//
gpioa.BSRRH.write(1 << 5); // set bit, output hight (turn on led)
// alternatively to set the bit high we can
// read the value, or with PA5 (bit 5) and write back
//
gpioa.ODR.write(gpioa.ODR.read() | (1 << 5));
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.BSRRL.write(1 << 5); // clear bit, output low (turn off led)
// alternatively to clear the bit we can
// read the value, mask out PA5 (bit 5) and write back
//
gpioa.ODR.write(gpioa.ODR.read() & !(1 << 5));
gpioa
.ODR
.write
(
gpioa
.ODR
.read
()
&
!
(
1
<<
5
));
wait
(
10_000
);
}
}
};
// 0. Build and run the application.
//
// > cargo build --example bare5
// (or use the vscode)
//
// 1. C like API.
// Using C the .h files are used for defining interfaces, like function signatures (prototypes),
// structs and macros (but usually not the functions themselves).
...
...
@@ -211,9 +213,8 @@ const APP: () = {
// provided by ST (and other companies). Actually, the file presented here is mostly a
// cut/paste/replace of the stm32f40x.h, just Rustified.
//
//
// In the loop we access PA5 through bit set/clear operations.
// Comment out those operations and uncomment the
the ODR
accesses.
// Comment out those operations and uncomment the
ODR based
accesses.
// (They should have the same behavior, but is a bit less efficient.)
//
// Run and see that the program behaves the same.
...
...
@@ -228,12 +229,10 @@ const APP: () = {
//
// Implement and check that running `test` gives you expected behavior.
//
// Change the code into using your new API.
// Change the code into using your new
`modify`
API.
//
// Run and see that the program behaves the same.
//
// Commit your answers (bare5_2)
//
// Discussion:
// As with arithmetic operations, default semantics differ in between
// debug/dev and release builds.
...
...
@@ -247,4 +246,6 @@ const APP: () = {
// What if we could automatically generate that from Vendors specifications (SVD files)?
// Wouldn't that be great?
//
// ** your answer here **
// I got the first assert to work. But I don't understand the second. What are we supposed to do?
//
// Commit your answers (bare5_2)
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