Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raise default clock speed #38

Open
jschneider-bensch opened this issue Jan 13, 2025 · 1 comment
Open

Raise default clock speed #38

jschneider-bensch opened this issue Jan 13, 2025 · 1 comment

Comments

@jschneider-bensch
Copy link
Contributor

No description provided.

@jschneider-bensch
Copy link
Contributor Author

The reference manual for the STM32L4+ Series indicates in Section 6.2.8 (p.252) that, indeed, after a system reset, the system clock is provided by the multispeed internal RC oscillator (MSI) set at 4MHz and details a procedure to switch to a high speed clock source with an intermediate frequency step.

We also have an example (for a different STM32 board) on how to do this with embassy_stm32:

    let mut config = Config::default();

    {
        use embassy_stm32::rcc::*;

        // By default, HSE on the board comes from a 8 MHz clock signal (not a crystal)
        config.rcc.hse = Some(Hse {
            freq: Hertz(8_000_000),
            mode: HseMode::Bypass,
        });
        // PLL uses HSE as the clock source
        config.rcc.pll_src = PllSource::HSE;
        config.rcc.pll = Some(Pll {
            // 8 MHz clock source / 8 = 1 MHz PLL input
            prediv: unwrap!(PllPreDiv::try_from(8)),
            // 1 MHz PLL input * 240 = 240 MHz PLL VCO
            mul: unwrap!(PllMul::try_from(240)),
            // 240 MHz PLL VCO / 2 = 120 MHz main PLL output
            divp: Some(PllPDiv::DIV2),
            // 240 MHz PLL VCO / 5 = 48 MHz PLL48 output
            divq: Some(PllQDiv::DIV5),
            divr: None,
        });
        // System clock comes from PLL (= the 120 MHz main PLL output)
        config.rcc.sys = Sysclk::PLL1_P;
        // 120 MHz / 4 = 30 MHz APB1 frequency
        config.rcc.apb1_pre = APBPrescaler::DIV4;
        // 120 MHz / 2 = 60 MHz APB2 frequency
        config.rcc.apb2_pre = APBPrescaler::DIV2;
    }

    let _p = embassy_stm32::init(config);

I still need to learn why the values in the example are set as they are, but providing a config like that for our reference board should fix this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant