aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreZio Pan <[email protected]>2023-11-06 18:30:59 +0800
committereZio Pan <[email protected]>2023-11-06 18:30:59 +0800
commit8f543062aa8bd44526e864e16deb9765618f191c (patch)
tree573aa04e36388215d42463b4d7f16ced241cbd65
parent74f70dc7b4db7ea9e10800384602bed48efe96b2 (diff)
check PLL settings before set VOS
-rw-r--r--embassy-stm32/src/rcc/f4f7.rs18
1 files changed, 8 insertions, 10 deletions
diff --git a/embassy-stm32/src/rcc/f4f7.rs b/embassy-stm32/src/rcc/f4f7.rs
index d507a6fd4..9e8c639d0 100644
--- a/embassy-stm32/src/rcc/f4f7.rs
+++ b/embassy-stm32/src/rcc/f4f7.rs
@@ -1,8 +1,9 @@
1use crate::pac::pwr::vals::Vos;
1pub use crate::pac::rcc::vals::{ 2pub use crate::pac::rcc::vals::{
2 Hpre as AHBPrescaler, Pllm as PllPreDiv, Plln as PllMul, Pllp, Pllq, Pllr, Pllsrc as PllSource, 3 Hpre as AHBPrescaler, Pllm as PllPreDiv, Plln as PllMul, Pllp, Pllq, Pllr, Pllsrc as PllSource,
3 Ppre as APBPrescaler, Sw as Sysclk, 4 Ppre as APBPrescaler, Sw as Sysclk,
4}; 5};
5use crate::pac::{FLASH, RCC}; 6use crate::pac::{FLASH, PWR, RCC};
6use crate::rcc::{set_freqs, Clocks}; 7use crate::rcc::{set_freqs, Clocks};
7use crate::time::Hertz; 8use crate::time::Hertz;
8 9
@@ -100,12 +101,17 @@ impl Default for Config {
100} 101}
101 102
102pub(crate) unsafe fn init(config: Config) { 103pub(crate) unsafe fn init(config: Config) {
104 // set VOS to SCALE1, if use PLL
105 // TODO: check real clock speed before set VOS
106 if config.pll.is_some() {
107 PWR.cr1().modify(|w| w.set_vos(Vos::SCALE1));
108 }
109
103 // always enable overdrive for now. Make it configurable in the future. 110 // always enable overdrive for now. Make it configurable in the future.
104 #[cfg(not(any( 111 #[cfg(not(any(
105 stm32f401, stm32f410, stm32f411, stm32f412, stm32f413, stm32f423, stm32f405, stm32f407, stm32f415, stm32f417 112 stm32f401, stm32f410, stm32f411, stm32f412, stm32f413, stm32f423, stm32f405, stm32f407, stm32f415, stm32f417
106 )))] 113 )))]
107 { 114 {
108 use crate::pac::PWR;
109 PWR.cr1().modify(|w| w.set_oden(true)); 115 PWR.cr1().modify(|w| w.set_oden(true));
110 while !PWR.csr1().read().odrdy() {} 116 while !PWR.csr1().read().odrdy() {}
111 117
@@ -113,14 +119,6 @@ pub(crate) unsafe fn init(config: Config) {
113 while !PWR.csr1().read().odswrdy() {} 119 while !PWR.csr1().read().odswrdy() {}
114 } 120 }
115 121
116 #[cfg(any(stm32f401, stm32f410, stm32f411, stm32f412, stm32f413, stm32f423))]
117 {
118 use crate::pac::pwr::vals::Vos;
119 use crate::pac::PWR;
120
121 PWR.cr1().modify(|w| w.set_vos(Vos::SCALE1));
122 }
123
124 // Configure HSI 122 // Configure HSI
125 let hsi = match config.hsi { 123 let hsi = match config.hsi {
126 false => { 124 false => {