Skip to main content

RCC

Struct RCC 

Source
pub struct RCC {
Show 13 fields pub hsi32m: bool, pub osc32m: bool, pub lsi32k: bool, pub osc32k: bool, pub freq_monitor: FreqMonitor, pub ahb_div: u8, pub apb_m_div: u8, pub apb_p_div: u8, pub hsi32m_calibration_value: u8, pub lsi32k_calibration_value: u8, pub rtcclk: RtcClkMux, pub rtccpuclk: CpuRtcClkMux, pub clocks: Clocks,
}
Expand description

Конфигурация RCC.

Поля hsi32m, osc32m, lsi32k, osc32k задают, останется ли соответствующий генератор включенным после инициализации. RCC::init сначала включает все генераторы, нужные для безопасного переключения, а в конце отключает те, которые пользователь пометил как false.

Fields§

§hsi32m: bool

Оставить включенным внутренний 32 МГц генератор.

§osc32m: bool

Оставить включенным внешний 32 МГц генератор.

§lsi32k: bool

Оставить включенным внутренний 32 кГц генератор.

§osc32k: bool

Оставить включенным внешний 32 кГц генератор.

§freq_monitor: FreqMonitor

Выбор системного источника и поведение монитора частоты.

§ahb_div: u8

Сырое значение DIV_AHB: частота AHB = sysclk / (ahb_div + 1).

§apb_m_div: u8

Сырое значение DIV_APB_M: частота APB_M = ahbclk / (apb_m_div + 1).

§apb_p_div: u8

Сырое значение DIV_APB_P: частота APB_P = ahbclk / (apb_p_div + 1).

§hsi32m_calibration_value: u8

Калибровочное значение внутреннего 32 МГц генератора.

§lsi32k_calibration_value: u8

Калибровочное значение внутреннего 32 кГц генератора.

§rtcclk: RtcClkMux

Приоритетный источник RTC в backup-домене.

§rtccpuclk: CpuRtcClkMux

Источник RTC для системного таймера ядра.

§clocks: Clocks

Расчетные частоты по умолчанию. Для актуальных частот используйте результат RCC::init или функцию clocks.

Implementations§

Source§

impl RCC

Source

pub fn init(config: &RCC) -> Result<Clocks, Error>

Применяет RCC-конфигурацию и возвращает рассчитанные частоты шин.

Метод валидирует выбранные источники до записи регистров, чтобы не отключить генератор, который используется системной частотой, RTC или монитором частоты.

Examples found in repository?
examples/serial.rs (line 19)
15pub extern "C" fn main() -> ! {
16    let peripherals = Peripherals::take().unwrap();
17
18    let rcc_config = RCC::default();
19    RCC::init(&rcc_config).unwrap();
20
21    peripherals
22        .pm
23        .clk_apb_m_set()
24        .modify(|_, w| w.pad_config().enable().pm().enable());
25
26    let rx = Pin08::new().into_serial_port();
27    let tx = Pin09::new().into_serial_port();
28
29    let serial = Serial::new(peripherals.usart_1, (tx, rx), Config::default()).unwrap();
30    let (mut tx, _rx) = serial.split();
31
32    loop {
33        let _ = writeln!(tx, "Hello from MIK32 USART1");
34        delay(MESSAGE_DELAY_SPINS);
35    }
36}
More examples
Hide additional examples
examples/gpio.rs (line 16)
14pub extern "C" fn main() -> ! {
15    let rcc_config = RCC::default();
16    RCC::init(&rcc_config).unwrap();
17    let _gpio0 = gpio::init_port::<0>();
18
19    let mut led_pin = Pin09::new()
20        .into_output()
21        .with_drive_strength(DriveStrength::Ma8);
22    let mut button_pin = Pin10::new().into_pull_down_input();
23    let mut button_was_pressed = false;
24
25    loop {
26        let button_is_pressed = button_pin.is_high().unwrap();
27
28        if button_is_pressed && !button_was_pressed {
29            let _ = led_pin.toggle();
30        }
31
32        button_was_pressed = button_is_pressed;
33        delay(10_000);
34    }
35}
examples/tsense.rs (line 19)
15pub extern "C" fn main() -> ! {
16    let peripherals = Peripherals::take().unwrap();
17
18    let rcc_config = RCC::default();
19    let clocks = RCC::init(&rcc_config).unwrap();
20
21    let sensor_config = Config::default()
22        .clock_from_source(ClockSource::HSI32M)
23        .with_frequency(SENSOR_CLOCK_HZ);
24
25    let mut sensor = TSENS::new(peripherals.tsens, &clocks, sensor_config).unwrap();
26
27    let mut current_temperature_c = sensor.single_measurement(Some(STARTUP_TIMEOUT)).unwrap();
28    let mut min_temperature_c = current_temperature_c;
29    let mut max_temperature_c = current_temperature_c;
30
31    sensor.start_continuous();
32
33    loop {
34        current_temperature_c = sensor.get_temperature();
35
36        if current_temperature_c < min_temperature_c {
37            min_temperature_c = current_temperature_c;
38        }
39
40        if current_temperature_c > max_temperature_c {
41            max_temperature_c = current_temperature_c;
42        }
43
44        let _temperature_snapshot = (current_temperature_c, min_temperature_c, max_temperature_c);
45
46        delay(SAMPLE_DELAY_SPINS);
47    }
48}
Source

pub fn clocks(config: &RCC) -> Clocks

Рассчитывает дерево частот из RCC-конфигурации без записи регистров.

Trait Implementations§

Source§

impl Default for RCC

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for RCC

§

impl RefUnwindSafe for RCC

§

impl Send for RCC

§

impl Sync for RCC

§

impl Unpin for RCC

§

impl UnsafeUnpin for RCC

§

impl UnwindSafe for RCC

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.