72 MHz clock (HSE+PLL), timer experiments
This commit is contained in:
parent
d657238c0c
commit
0225e6d074
1 changed files with 30 additions and 5 deletions
35
src/main.rs
35
src/main.rs
|
@ -14,7 +14,7 @@ use panic_halt as _;
|
||||||
use nb::block;
|
use nb::block;
|
||||||
|
|
||||||
use cortex_m_rt::entry;
|
use cortex_m_rt::entry;
|
||||||
use stm32f1xx_hal::{pac, prelude::*, timer::Timer};
|
use stm32f1xx_hal::{pac, prelude::*, rcc::Config, timer::Timer};
|
||||||
|
|
||||||
#[entry]
|
#[entry]
|
||||||
fn main() -> ! {
|
fn main() -> ! {
|
||||||
|
@ -30,7 +30,20 @@ fn main() -> ! {
|
||||||
|
|
||||||
// Freeze the configuration of all the clocks in the system and store the frozen frequencies in
|
// Freeze the configuration of all the clocks in the system and store the frozen frequencies in
|
||||||
// `clocks`
|
// `clocks`
|
||||||
let clocks = rcc.cfgr.freeze(&mut flash.acr);
|
let clocks = rcc.cfgr.freeze_with_config(
|
||||||
|
Config {
|
||||||
|
// HSE frequency
|
||||||
|
hse: Some(8_000_000),
|
||||||
|
// PLLMUL represented by an integer -2
|
||||||
|
pllmul: Some(9 - 2),
|
||||||
|
// PCLK1 freq must be 36 MHz or less
|
||||||
|
ppre1: stm32f1xx_hal::rcc::PPre::Div2,
|
||||||
|
// ADCCLK freq must be 14 MHz or less
|
||||||
|
adcpre: pac::rcc::cfgr::ADCPRE_A::Div6,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
&mut flash.acr,
|
||||||
|
);
|
||||||
|
|
||||||
// Acquire the GPIOC peripheral
|
// Acquire the GPIOC peripheral
|
||||||
let mut gpioc = dp.GPIOC.split();
|
let mut gpioc = dp.GPIOC.split();
|
||||||
|
@ -38,15 +51,27 @@ fn main() -> ! {
|
||||||
// Configure gpio C pin 13 as a push-pull output. The `crh` register is passed to the function
|
// Configure gpio C pin 13 as a push-pull output. The `crh` register is passed to the function
|
||||||
// in order to configure the port. For pins 0-7, crl should be passed instead.
|
// in order to configure the port. For pins 0-7, crl should be passed instead.
|
||||||
let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
|
let mut led = gpioc.pc13.into_push_pull_output(&mut gpioc.crh);
|
||||||
|
|
||||||
// Configure the syst timer to trigger an update every second
|
// Configure the syst timer to trigger an update every second
|
||||||
let mut timer = Timer::syst(cp.SYST, &clocks).counter_hz();
|
let mut timer = Timer::syst(cp.SYST, &clocks).counter_hz();
|
||||||
timer.start(1.Hz()).unwrap();
|
// at 72 MHz, timer of 1 Hz overflows, use 10 Hz instead (8 Hz experimental minimum)
|
||||||
|
timer.start(10.Hz()).unwrap();
|
||||||
|
|
||||||
|
// equivalent timers:
|
||||||
|
// let mut timer = Timer::syst(cp.SYST, &clocks).counter_us(); // us resolution
|
||||||
|
// let mut timer: SysCounter<1000> = Timer::syst(cp.SYST, &clocks).counter(); // ms resolution
|
||||||
|
// timer.start(100.millis()).unwrap();
|
||||||
|
|
||||||
// Wait for the timer to trigger an update and change the state of the LED
|
// Wait for the timer to trigger an update and change the state of the LED
|
||||||
loop {
|
loop {
|
||||||
block!(timer.wait()).unwrap();
|
for _ in 0..10 {
|
||||||
|
block!(timer.wait()).unwrap();
|
||||||
|
}
|
||||||
led.set_high();
|
led.set_high();
|
||||||
block!(timer.wait()).unwrap();
|
|
||||||
|
for _ in 0..10 {
|
||||||
|
block!(timer.wait()).unwrap();
|
||||||
|
}
|
||||||
led.set_low();
|
led.set_low();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue