diff options
| -rw-r--r-- | embassy-stm32/src/rcc/g4.rs | 35 | ||||
| -rw-r--r-- | examples/stm32g4/src/bin/pll.rs | 4 |
2 files changed, 37 insertions, 2 deletions
diff --git a/embassy-stm32/src/rcc/g4.rs b/embassy-stm32/src/rcc/g4.rs index 7d061192b..6b1206c6a 100644 --- a/embassy-stm32/src/rcc/g4.rs +++ b/embassy-stm32/src/rcc/g4.rs | |||
| @@ -1,4 +1,6 @@ | |||
| 1 | use stm32_metapac::flash::vals::Latency; | ||
| 1 | use stm32_metapac::rcc::vals::{Hpre, Pllsrc, Ppre, Sw}; | 2 | use stm32_metapac::rcc::vals::{Hpre, Pllsrc, Ppre, Sw}; |
| 3 | use stm32_metapac::FLASH; | ||
| 2 | 4 | ||
| 3 | use crate::pac::{PWR, RCC}; | 5 | use crate::pac::{PWR, RCC}; |
| 4 | use crate::rcc::{set_freqs, Clocks}; | 6 | use crate::rcc::{set_freqs, Clocks}; |
| @@ -283,6 +285,39 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 283 | let freq = src_freq / prediv.to_div() * mul.to_mul() / div.to_div(); | 285 | let freq = src_freq / prediv.to_div() * mul.to_mul() / div.to_div(); |
| 284 | assert!(freq <= 170_000_000); | 286 | assert!(freq <= 170_000_000); |
| 285 | 287 | ||
| 288 | if freq >= 150_000_000 { | ||
| 289 | // Enable Core Boost mode ([RM0440] p234) | ||
| 290 | PWR.cr5() | ||
| 291 | .modify(|w: &mut stm32_metapac::pwr::regs::Cr5| w.set_r1mode(false)); | ||
| 292 | // Set flash wait state in boost mode based on frequency ([RM0440] p191) | ||
| 293 | if freq <= 36_000_000 { | ||
| 294 | FLASH.acr().modify(|w| w.set_latency(Latency::WS0)); | ||
| 295 | } else if freq <= 68_000_000 { | ||
| 296 | FLASH.acr().modify(|w| w.set_latency(Latency::WS1)); | ||
| 297 | } else if freq <= 102_000_000 { | ||
| 298 | FLASH.acr().modify(|w| w.set_latency(Latency::WS2)); | ||
| 299 | } else if freq <= 136_000_000 { | ||
| 300 | FLASH.acr().modify(|w| w.set_latency(Latency::WS3)); | ||
| 301 | } else { | ||
| 302 | FLASH.acr().modify(|w| w.set_latency(Latency::WS4)); | ||
| 303 | } | ||
| 304 | } else { | ||
| 305 | PWR.cr5() | ||
| 306 | .modify(|w: &mut stm32_metapac::pwr::regs::Cr5| w.set_r1mode(true)); | ||
| 307 | // Set flash wait state in normal mode based on frequency ([RM0440] p191) | ||
| 308 | if freq <= 30_000_000 { | ||
| 309 | FLASH.acr().modify(|w| w.set_latency(Latency::WS0)); | ||
| 310 | } else if freq <= 60_000_000 { | ||
| 311 | FLASH.acr().modify(|w| w.set_latency(Latency::WS1)); | ||
| 312 | } else if freq <= 80_000_000 { | ||
| 313 | FLASH.acr().modify(|w| w.set_latency(Latency::WS2)); | ||
| 314 | } else if freq <= 120_000_000 { | ||
| 315 | FLASH.acr().modify(|w| w.set_latency(Latency::WS3)); | ||
| 316 | } else { | ||
| 317 | FLASH.acr().modify(|w| w.set_latency(Latency::WS4)); | ||
| 318 | } | ||
| 319 | } | ||
| 320 | |||
| 286 | RCC.pllcfgr().write(move |w| { | 321 | RCC.pllcfgr().write(move |w| { |
| 287 | w.set_plln(mul.into()); | 322 | w.set_plln(mul.into()); |
| 288 | w.set_pllm(prediv.into()); | 323 | w.set_pllm(prediv.into()); |
diff --git a/examples/stm32g4/src/bin/pll.rs b/examples/stm32g4/src/bin/pll.rs index 580afe03d..bde30c284 100644 --- a/examples/stm32g4/src/bin/pll.rs +++ b/examples/stm32g4/src/bin/pll.rs | |||
| @@ -13,8 +13,8 @@ use {defmt_rtt as _, panic_probe as _}; | |||
| 13 | async fn main(_spawner: Spawner) { | 13 | async fn main(_spawner: Spawner) { |
| 14 | let mut config = Config::default(); | 14 | let mut config = Config::default(); |
| 15 | 15 | ||
| 16 | // Configure PLL to 128Mhz frequency | 16 | // Configure PLL to max frequency of 170 MHz |
| 17 | config.rcc.mux = ClockSrc::PLL(PllSrc::HSI16, PllM::Div4, PllN::Mul64, PllClkDiv::Div2); | 17 | config.rcc.mux = ClockSrc::PLL(PllSrc::HSI16, PllM::Div4, PllN::Mul85, PllClkDiv::Div2); |
| 18 | 18 | ||
| 19 | let _p = embassy_stm32::init(config); | 19 | let _p = embassy_stm32::init(config); |
| 20 | info!("Hello World!"); | 20 | info!("Hello World!"); |
