stm32-rs / stm32g0xx-hal

Peripheral access API for STM32G0 series microcontrollers
Apache License 2.0
73 stars 51 forks source link

Add support for using PLLQ with TIM1/TIM15 #115

Closed davidlattimore closed 2 years ago

davidlattimore commented 2 years ago

I tested this on a G071 and was able to produce a 56MHz output while running the CPU at 875KHz.

        let config = hal::rcc::Config::pll()
            .pll_cfg(hal::rcc::PllConfig {
                n: 21,
                r: 6,
                q: Some(3),
                ..hal::rcc::PllConfig::default()
            })
            .ahb_psc(Prescaler::Div64);
        let mut rcc = dp.RCC.freeze(config);

        defmt::println!(
            "SYS: {} AHP: {} APB: {} PLLQ: {}",
            rcc.clocks.sys_clk.raw() / 1_000,
            rcc.clocks.ahb_clk.raw() / 1_000,
            rcc.clocks.apb_clk.raw() / 1_000,
            rcc.clocks.pll_clk.q.unwrap().raw() / 1_000
        );

        let gpioa = dp.GPIOA.split(&mut rcc);
        let pwm = dp.TIM1.pwm_q(56.MHz(), &mut rcc);

        let mut pwm_ch1 = pwm.bind_pin(gpioa.pa9.set_speed(Speed::VeryHigh));

        let max = pwm_ch1.get_max_duty();
        pwm_ch1.set_duty((max + 1) / 2);
        pwm_ch1.enable();
dotcypress commented 2 years ago

Thank you @davidlattimore 🚀