1// Copyright © 2025 David Haig
2// SPDX-License-Identifier: MIT
3
4use embassy_stm32::time::Hertz;
5use embassy_stm32::{rcc, Config, Peripherals};
6
7/// Sets up clocks for the stm32u5g9zj mcu
8/// change this if you plan to use a different microcontroller
9pub fn stm32u5g9zj_init() -> Peripherals {
10 // setup power and clocks for an STM32U5G9J-DK2 run from an external 16 Mhz external oscillator
11 let mut config: Config = Config::default();
12 config.rcc.hse = Some(rcc::Hse { freq: Hertz(16_000_000), mode: rcc::HseMode::Oscillator });
13 config.rcc.pll1 = Some(rcc::Pll {
14 source: rcc::PllSource::HSE,
15 prediv: rcc::PllPreDiv::DIV1,
16 mul: rcc::PllMul::MUL10,
17 divp: None,
18 divq: None,
19 divr: Some(rcc::PllDiv::DIV1),
20 });
21 config.rcc.sys = rcc::Sysclk::PLL1_R; // 160 Mhz
22 config.rcc.pll3 = Some(rcc::Pll {
23 source: rcc::PllSource::HSE,
24 prediv: rcc::PllPreDiv::DIV4, // PLL_M
25 mul: rcc::PllMul::MUL125, // PLL_N
26 divp: None,
27 divq: None,
28 divr: Some(rcc::PllDiv::DIV20),
29 });
30 config.rcc.mux.ltdcsel = rcc::mux::Ltdcsel::PLL3_R; // 25 MHz
31 embassy_stm32::init(config)
32}
33