Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
F
f429x
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
f429x
Commits
4e7c2ba0
Commit
4e7c2ba0
authored
7 years ago
by
Johannes Sjölund
Browse files
Options
Downloads
Patches
Plain Diff
Improve clock example docs
parent
62646472
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/mco.rs
+15
-7
15 additions, 7 deletions
examples/mco.rs
with
15 additions
and
7 deletions
examples/mco.rs
+
15
−
7
View file @
4e7c2ba0
//
#![deny(unsafe_code)]
//
! Set the clock frequency on the Nucleo-64 stm32f40x
//
#![deny(warnings)]
#![deny(warnings)]
#![feature(proc_macro)]
#![feature(proc_macro)]
#![no_std]
#![no_std]
extern
crate
cortex_m_rtfm
as
rtfm
;
extern
crate
cortex_m_rtfm
as
rtfm
;
#[macro_use]
extern
crate
f4
;
extern
crate
f4
;
use
rtfm
::
app
;
use
rtfm
::
app
;
...
@@ -18,7 +17,9 @@ app! {
...
@@ -18,7 +17,9 @@ app! {
// INITIALIZATION PHASE
// INITIALIZATION PHASE
fn
init
(
p
:
init
::
Peripherals
)
{
fn
init
(
p
:
init
::
Peripherals
)
{
// RM0368 6.2.10
// See RM0368 6.2.10 Clock-out capability
// PC9 outputs SYSCLK/4 MHz and PA8 the frequency of the HSI RC
// Configure PA8 as MCO_1 alternate function to output HSI clock
// Configure PA8 as MCO_1 alternate function to output HSI clock
p
.RCC.ahb1enr
.modify
(|
_
,
w
|
w
.gpioaen
()
.set_bit
());
//Enable GPIOA clock
p
.RCC.ahb1enr
.modify
(|
_
,
w
|
w
.gpioaen
()
.set_bit
());
//Enable GPIOA clock
p
.GPIOA.ospeedr
.modify
(|
_
,
w
|
w
.ospeedr8
()
.bits
(
0b11
));
//Highest output speed
p
.GPIOA.ospeedr
.modify
(|
_
,
w
|
w
.ospeedr8
()
.bits
(
0b11
));
//Highest output speed
...
@@ -39,10 +40,17 @@ fn init(p: init::Peripherals) {
...
@@ -39,10 +40,17 @@ fn init(p: init::Peripherals) {
p
.RCC.cfgr
.modify
(|
_
,
w
|
unsafe
{
w
.mco2
()
.bits
(
0b00
)
});
//MCO2 SYSCLK clock selected
p
.RCC.cfgr
.modify
(|
_
,
w
|
unsafe
{
w
.mco2
()
.bits
(
0b00
)
});
//MCO2 SYSCLK clock selected
p
.RCC.cfgr
.modify
(|
_
,
w
|
unsafe
{
w
.mco2pre
()
.bits
(
0b110
)
});
//Divide SYSCLK by 4
p
.RCC.cfgr
.modify
(|
_
,
w
|
unsafe
{
w
.mco2pre
()
.bits
(
0b110
)
});
//Divide SYSCLK by 4
let
sysclk
=
clock
::
set_100_mhz
(
&
p
.RCC
,
&
p
.FLASH
);
// Set the clock to 84 MHz for compatibility with stm32f401
println!
(
"SYSCLK set to {}"
,
sysclk
);
clock
::
set_84_mhz
(
&
p
.RCC
,
&
p
.FLASH
);
// PC9 should now output SYSCLK/4 MHz and PA8 the frequency of the HSI RC
// The stm32f411 supports 100 MHz.
// clock::set_100_mhz(&p.RCC, &p.FLASH);
// We can also use a lower frequency by providing valid PLL constants.
// Since the HSI RC is 16 MHz, we get 16/8*50/4 = 25 MHz
// clock::set(&p.RCC, &p.FLASH, 8, 50, 4);
// Light the green LED when we start idling.
led
::
init
(
&
p
.GPIOA
,
&
p
.RCC
);
led
::
init
(
&
p
.GPIOA
,
&
p
.RCC
);
}
}
...
...
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