stm32-rs / stm32f7xx-hal

A Rust embedded-hal HAL for all MCUs in the STM32 F7 family
Apache License 2.0
117 stars 68 forks source link

RCC: Add mco{1,2} to CFGR struct #151

Closed systec-ms closed 3 years ago

systec-ms commented 3 years ago

Add MCO configuration based on PLLP. Tested with a STM32F767.

Motivation: Add functionality to configure MCO via the HAL abstraction.

For example:

    p.RCC.cfgr.modify(|_r, w| {
        w.mco2()
            .variant(stm32_eth::hal::pac::rcc::cfgr::MCO2_A::PLLI2S)
            .mco2pre()
            .div4()
    });

    let rcc = p.RCC.constrain();

Outcome:

    let hseclock = HSEClock::new(24.MHz(), HSEClockMode::Oscillator);
    let clocks = rcc
        .cfgr
        .hse(hseclock)
        .pllm(12)
        .plln(200)
        .pllp(PLLP::Div2)
        .plli2sn(100)
        .plli2sr(2)
        .use_pll()
        .use_plli2s()
        .sysclk(200.MHz())
        .mco2(MCO2::Plli2s)
        .mco2pre(MCO2PRE::Div4)
        .freeze();
hannobraun commented 3 years ago

Thank you, @systec-ms!