Enable timer clock in RCC on timer start

* Moves the tim2-specific code into macro which always uses TIM2
* For peripherals without clock specified, attempt to locate enable and
  reset registers in the RCC block matching the peripheral name. This
  could be useful for peripherals where deducing the clock name might
  not be feasible, but it remains to be tested with more chip families
  to see if it is sufficiently accurate.
This commit is contained in:
Ulf Lilleengen
2021-06-10 09:31:41 +02:00
parent 37fbc5fcc4
commit 0a9022d59f
3 changed files with 44 additions and 45 deletions

View File

@ -16,7 +16,10 @@ pub fn generate(embassy_prefix: &ModulePrefix, config: syn::Expr) -> TokenStream
interrupt::take!(TIM2),
);
let clock = unsafe { make_static(&mut c) };
clock.start_tim2();
// TODO: Is TIM2 always APB1?
let timer_freq = unsafe { #embassy_stm32_path::rcc::get_freqs().apb1_clk };
clock.start(timer_freq);
let mut alarm = clock.alarm1();
unsafe { #embassy_path::time::set_clock(clock) };