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
Per Lindgren
e7020e_2019
Commits
5555294d
Commit
5555294d
authored
6 years ago
by
Per
Browse files
Options
Downloads
Patches
Plain Diff
bare 6 assignment
parent
a065e320
No related branches found
No related tags found
No related merge requests found
Pipeline
#113
failed
6 years ago
Stage: build
Stage: test
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
examples/bare6.rs
+28
-10
28 additions, 10 deletions
examples/bare6.rs
with
28 additions
and
10 deletions
examples/bare6.rs
+
28
−
10
View file @
5555294d
...
@@ -38,7 +38,7 @@ fn main() -> ! {
...
@@ -38,7 +38,7 @@ fn main() -> ! {
loop
{}
loop
{}
}
}
//
// user application
// user application
fn
idle
(
stim
:
&
mut
Stim
,
rcc
:
RCC
,
gpioa
:
GPIOA
)
{
fn
idle
(
stim
:
&
mut
Stim
,
rcc
:
RCC
,
gpioa
:
GPIOA
)
{
iprintln!
(
stim
,
"idle"
);
iprintln!
(
stim
,
"idle"
);
...
@@ -83,8 +83,7 @@ fn clock_out(rcc: &RCC, gpioc: &GPIOC) {
...
@@ -83,8 +83,7 @@ fn clock_out(rcc: &RCC, gpioc: &GPIOC) {
// mco2 : SYSCLK = 0b00
// mco2 : SYSCLK = 0b00
// mcopre : divide by 4 = 0b110
// mcopre : divide by 4 = 0b110
rcc
.cfgr
rcc
.cfgr
//.modify(|_, w| unsafe { w.mco2().bits(0b00).mco2pre().bits(0b110) });
.modify
(|
_
,
w
|
unsafe
{
w
.mco2
()
.bits
(
0b00
)
.mco2pre
()
.bits
(
0b110
)
});
.modify
(|
_
,
w
|
w
.mco2
()
.sysclk
()
.mco2pre
()
.div4
());
// power on GPIOC, RM0368 6.3.11
// power on GPIOC, RM0368 6.3.11
rcc
.ahb1enr
.modify
(|
_
,
w
|
w
.gpiocen
()
.set_bit
());
rcc
.ahb1enr
.modify
(|
_
,
w
|
w
.gpiocen
()
.set_bit
());
...
@@ -94,15 +93,12 @@ fn clock_out(rcc: &RCC, gpioc: &GPIOC) {
...
@@ -94,15 +93,12 @@ fn clock_out(rcc: &RCC, gpioc: &GPIOC) {
// AF0, gpioc reset value = AF0
// AF0, gpioc reset value = AF0
// configure PC9 as alternate function 0b10, RM0368 6.2.10
// configure PC9 as alternate function 0b10, RM0368 6.2.10
gpioc
.moder
.modify
(|
_
,
w
|
w
.moder9
()
.alternate
());
gpioc
.moder
.modify
(|
_
,
w
|
w
.moder9
()
.bits
(
0b10
));
// gpioc.moder.modify(|_, w| w.moder9().bits(0b10));
// otyper reset state push/pull, in reset state (don't need to change)
// otyper reset state push/pull, in reset state (don't need to change)
// ospeedr 0b11 = very high speed
// ospeedr 0b11 = very high speed
gpioc
.ospeedr
.modify
(|
_
,
w
|
w
.ospeedr9
()
.bits
(
0b11
));
// gpioc.ospeedr.modify(|_, w| w.ospeedr9().bits(0b11));
gpioc
.ospeedr
.modify
(|
_
,
w
|
w
.ospeedr9
()
.very_high_speed
())
}
}
// 0. Compile and run the example, in 16Mhz
// 0. Compile and run the example, in 16Mhz
...
@@ -175,3 +171,25 @@ fn clock_out(rcc: &RCC, gpioc: &GPIOC) {
...
@@ -175,3 +171,25 @@ fn clock_out(rcc: &RCC, gpioc: &GPIOC) {
//
//
// commit your answers (bare6_4)
// commit your answers (bare6_4)
//
//
// 5. In the `clock_out` function, the setup of registers is done through
// setting bitpattens manually, e.g.
// rcc.cfgr
// .modify(|_, w| unsafe { w.mco2().bits(0b00).mco2pre().bits(0b110) });
//
// However based on the vendor SVD file the svd2rust API provides
// a better abstraction, based on pattern enums and functions.
//
// To view the API you can generate documentation for your crate:
//
// > cargo doc --features "hal rtfm" --open
//
// By searching for `mco2` you find the enumerations and functions.
// So here
// `w.mco2().bits{0b00}` is equivalent to
// `w.mco2().sysclk()` and improves readabiity.
//
// Replace the bitpatterns used by the function name equivalents.
//
// Test that the application still runs as before.
//
// Commit your code (bare6_4)
\ No newline at end of file
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