embassy
embassy copied to clipboard
Clock Configuration for USB
I was trying to follow the usb_serial.rs example for STM32H7 and my computer wasn't detecting the usb. I made sure to set vbus_detection to false. I think the issue is with the rcc config and wasn't sure how to setup the rcc config while having an HSE of 48Mhz.
config.rcc.hse = Some(Hse{ freq: Hertz::mhz(48), mode: HseMode::Oscillator });
config.rcc.ls.lse = Some(LseConfig{ frequency: Hertz::khz(32), mode: LseMode::Oscillator(LseDrive::High) });
config.rcc.pll1 = Some(Pll {
source: PllSource::HSE,
prediv: PllPreDiv::DIV4,
mul: PllMul::MUL49,
divp: Some(PllDiv::DIV2),
divq: Some(PllDiv::DIV8), // SPI1 cksel defaults to pll1_q
divr: None,
});
config.rcc.pll2 = Some(Pll {
source: PllSource::HSE,
prediv: PllPreDiv::DIV8,
mul: PllMul::MUL50,
divp: Some(PllDiv::DIV4), // 100mhz
divq: None,
divr: None,
});
config.rcc.sys = Sysclk::PLL1_P; // 400 Mhz
config.rcc.ahb_pre = AHBPrescaler::DIV2; // 200 Mhz
config.rcc.apb1_pre = APBPrescaler::DIV2; // 100 Mhz
config.rcc.apb2_pre = APBPrescaler::DIV2; // 100 Mhz
config.rcc.apb3_pre = APBPrescaler::DIV2; // 100 Mhz
config.rcc.apb4_pre = APBPrescaler::DIV2; // 100 Mhz
config.rcc.voltage_scale = VoltageScale::Scale1;
config.rcc.mux.adcsel = mux::Adcsel::PLL2_P;
config.rcc.mux.usbsel = mux::Usbsel::PLL1_Q;
}