pub fn init(timer: Timer, clocks: Clocks) {
    let frequency_in = enable_timer_clock(clocks);

    // Configure prescaler so 1 tick = 1 microsecond (1 megahertz)
    let prescaler = frequency_in / 1_000_000;
    assert!(prescaler > 0, "Clock input to timer 6 is too slow");
    let prescaler_bits: u16 = (prescaler - 1)
        .try_into()
        .expect("Clock input to timer 6 is too fast");
    timer.psc.write(|w| w.psc().bits(prescaler_bits));

    // Reload upon reaching 65536
    // With this setup, the timer will overflow every 65.536 milliseconds.
    #[allow(unused_unsafe)] // ARR_W.bits() is unsafe on some microcontroller models.
    timer.arr.write(|w| unsafe { w.arr().bits(u16::MAX) });

    // Trigger update event to load the registers
    timer.cr1.modify(|_, w| w.urs().counter_only());
    timer.egr.write(|w| w.ug().update());
    timer.cr1.modify(|_, w| w.urs().any_event());

    // Enable update (overflow) interrupt
    timer.dier.modify(|_, w| w.uie().enabled());

    // Start counting
    timer.cr1.modify(|_, w| w.cen().enabled());

    // Indicate to the other code that the clock is ready
    unsafe {
        OVERFLOW_COUNT = 0;
        INITIALIZED = true;
    }
}
/// Initializes the clock using a timer
///
/// After calling this function, the timer interrupt must be unmasked in the nested vector interrupt
/// controller.
Initializes the clock using a timer
After calling this function, the timer interrupt must be unmasked in the nested vector interrupt
controller.
Initializes the clock using a timer After calling this function the timer interrupt must be unmasked in the nested vector interrupt controller .
pub fn init(timer: Timer, clocks: Clocks) {
    let frequency_in = enable_timer_clock(clocks);
    // Configure prescaler so 1 tick = 1 microsecond (1 megahertz)
    let prescaler = frequency_in / 1_000_000;
    assert!(prescaler > 0, "Clock input to timer 6 is too slow");
    let prescaler_bits: u16 = (prescaler - 1)
        .try_into()
        .expect("Clock input to timer 6 is too fast");
    timer.psc.write(|w| w.psc().bits(prescaler_bits));
    // Reload upon reaching 65536
    // With this setup, the timer will overflow every 65.536 milliseconds.
    #[allow(unused_unsafe)] // ARR_W.bits() is unsafe on some microcontroller models.
    timer.arr.write(|w| unsafe { w.arr().bits(u16::MAX) });
    // Trigger update event to load the registers
    timer.cr1.modify(|_, w| w.urs().counter_only());
    timer.egr.write(|w| w.ug().update());
    timer.cr1.modify(|_, w| w.urs().any_event());
    // Enable update (overflow) interrupt
    timer.dier.modify(|_, w| w.uie().enabled());
    // Start counting
    timer.cr1.modify(|_, w| w.cen().enabled());
    // Indicate to the other code that the clock is ready
    unsafe {
        OVERFLOW_COUNT = 0;
        INITIALIZED = true;
    }
}
pub fn init ( timer : Timer , clocks : Clocks ) { let frequency_in = enable_timer_clock ( clocks ) ; // Configure prescaler so 1 tick = 1 microsecond (1 megahertz) let prescaler = frequency_in / 1_000_000 ; assert ! ( prescaler 0 " " ) ; let prescaler_bits : u16 = ( prescaler - 1 ) . try_into ( ) . expect ( " " ) ; timer . psc . write ( | w | w . psc ( ) . bits ( prescaler_bits ) ) ; // Reload upon reaching 65536 // With this setup, the timer will overflow every 65.536 milliseconds. # [ allow ( unused_unsafe ) ] // ARR_W.bits() is unsafe on some microcontroller models. timer . arr . write ( | w | unsafe { w . arr ( ) . bits ( u16 :: MAX ) } ) ; // Trigger update event to load the registers timer . cr1 . modify ( | _ , w | w . urs ( ) . counter_only ( ) ) ; timer . egr . write ( | w | w . ug ( ) . update ( ) ) ; timer . cr1 . modify ( | _ , w | w . urs ( ) . any_event ( ) ) ; // Enable update (overflow) interrupt timer . dier . modify ( | _ , w | w . uie ( ) . enabled ( ) ) ; // Start counting timer . cr1 . modify ( | _ , w | w . cen ( ) . enabled ( ) ) ; // Indicate to the other code that the clock is ready unsafe { OVERFLOW_COUNT = 0 ; INITIALIZED = true ; } }
Initializes the clock using a timer
After calling this function, the timer interrupt must be unmasked in the nested vector interrupt
controller.
Initializes the clock using a timer After calling this function the timer interrupt must be unmasked in the nested vector interrupt controller .
timer
Timer
clocks
Clocks
timer
Timer
clocks
Clocks