Skip to content

Commit

Permalink
WIP clock configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
H1rono committed Sep 5, 2024
1 parent f208a1d commit ddeba80
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use embedded_alloc::LlffHeap;
use embedded_hal::digital::v2::{OutputPin, ToggleableOutputPin};
use embedded_hal::timer::CountDown;
use embedded_time::duration::Extensions as DurationExt;
use embedded_time::rate::Extensions as RateExt;
use hal::flash::FlashExt;
use hal::gpio::GpioExt;
use hal::interrupt;
Expand Down Expand Up @@ -51,9 +52,19 @@ fn main() -> ! {

let mut flash = dp.FLASH.constrain();
let mut rcc = dp.RCC.constrain();
let clocks = rcc.cfgr.freeze(&mut flash.acr);
let clocks = rcc
.cfgr
// .use_hse(8.MHz())
.sysclk(48.MHz())
.pclk1(24.MHz())
.pclk2(24.MHz())
.freeze(&mut flash.acr);
let mut timer = Timer::new(dp.TIM2, clocks, &mut rcc.apb1);

// FIXME: .use_hseをしないとこのassertで落ちるが、8.MHz()では動かない
// 適切な値を見つける必要がある
// defmt::assert!(clocks.usbclk_valid());

let mut gpiob = dp.GPIOB.split(&mut rcc.ahb);
let led = {
let mut l = gpiob
Expand All @@ -67,15 +78,16 @@ fn main() -> ! {
LED.borrow(cs).replace(Some(led));
});

#[allow(unsafe_code)]
unsafe {
NVIC::unmask(timer.interrupt());
}
timer.enable_interrupt(TimerEvent::Update);
timer.start(1000.milliseconds());
let interrupt_number = timer.interrupt();
cortex_m::interrupt::free(move |cs| {
TIMER.borrow(cs).replace(Some(timer));
});
#[allow(unsafe_code)]
unsafe {
NVIC::unmask(interrupt_number);
}
defmt::debug!("done initializing");

loop {
Expand Down

0 comments on commit ddeba80

Please sign in to comment.