Skip to content

Automatic clock configuration for stm32g4xx-hal

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT
Notifications You must be signed in to change notification settings

mgottschlag/stm32g4xx-clkcfg

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

stm32g4xx-clkcfg

The STM32G4xx HAL does not provide a method to calculate the clock configuration - instead, the user is expected to manually provide a suitable PLL configuration and various prescalers. This library provides functions to automatically calculate a suitable clock configuration, similar to what is provided by STM32CubeMX. The user simply has to provide their frequency requirements, and the library loops through all possible configurations, selecting that which fulfills the requirements and deviates from the desired frequencies by as little as possible.

The library is expected to be used in build.rs and provides methods to generate code that can be included in projects using stm32g4xx-hal.

Usage Example

use std::io::stdout;

use embedded_time::rate::*;
use stm32g4xx_clkcfg::{ClockRequirements, Frequencies};

fn main() {
    println!("Configuration for the highest possible sysclk with a 48MHz USB clock from a 24 MHz crystal:");
    let req = ClockRequirements::new()
        .hse(24_000_000.Hz())
        .sysclk(170_000_000.Hz())
        .usb_rng_clk(true);
    match req.resolve(false) {
        Ok((cfg, freqs)) => {
            cfg.write_code(&mut stdout()).unwrap();
	    // _freqs holds the frequencies generated by the configuration.
        }
        Err(e) => {
            println!("Error: {:?}", e);
        }
    }
}

License

Licensed under either of

at your option.

Substantial code has been taken from src/rcc/config.rs of stm32f4xx-hal.

About

Automatic clock configuration for stm32g4xx-hal

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages