Skip to content
Snippets Groups Projects
Commit 4e7c2ba0 authored by Johannes Sjölund's avatar Johannes Sjölund
Browse files

Improve clock example docs

parent 62646472
No related branches found
No related tags found
No related merge requests found
// #![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);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment