diff options
| author | Dario Nieuwenhuis <[email protected]> | 2025-06-01 12:19:39 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-06-01 12:19:39 +0000 |
| commit | f3983328e0d24b90e82b9ecbfc69f1d3219c5c5c (patch) | |
| tree | bdb55f93e631de93548dbd7ada6ddfb61d2c7051 | |
| parent | a636ec439eda06a140ddf4c2cbb17b2fc245a7d1 (diff) | |
| parent | 44c53365ad387c8d1296751080f4f8117c7d7b5c (diff) | |
Merge pull request #4231 from ROMemories/feat/stm32-rcc-const-constructors
feat(stm32): provide a `const` constructor on `rcc::Config`
| -rw-r--r-- | embassy-stm32/src/rcc/bd.rs | 19 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/c0.rs | 15 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/f013.rs | 16 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/f247.rs | 14 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/g0.rs | 17 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/g4.rs | 17 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/h.rs | 16 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/hsi48.rs | 8 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/l.rs | 17 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/u5.rs | 16 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/wba.rs | 15 |
11 files changed, 115 insertions, 55 deletions
diff --git a/embassy-stm32/src/rcc/bd.rs b/embassy-stm32/src/rcc/bd.rs index 57aaba1c7..e2c704405 100644 --- a/embassy-stm32/src/rcc/bd.rs +++ b/embassy-stm32/src/rcc/bd.rs | |||
| @@ -92,6 +92,17 @@ pub struct LsConfig { | |||
| 92 | } | 92 | } |
| 93 | 93 | ||
| 94 | impl LsConfig { | 94 | impl LsConfig { |
| 95 | /// Creates an [`LsConfig`] using the LSI when possible. | ||
| 96 | pub const fn new() -> Self { | ||
| 97 | // on L5, just the fact that LSI is enabled makes things crash. | ||
| 98 | // TODO: investigate. | ||
| 99 | |||
| 100 | #[cfg(not(stm32l5))] | ||
| 101 | return Self::default_lsi(); | ||
| 102 | #[cfg(stm32l5)] | ||
| 103 | return Self::off(); | ||
| 104 | } | ||
| 105 | |||
| 95 | pub const fn default_lse() -> Self { | 106 | pub const fn default_lse() -> Self { |
| 96 | Self { | 107 | Self { |
| 97 | rtc: RtcClockSource::LSE, | 108 | rtc: RtcClockSource::LSE, |
| @@ -124,13 +135,7 @@ impl LsConfig { | |||
| 124 | 135 | ||
| 125 | impl Default for LsConfig { | 136 | impl Default for LsConfig { |
| 126 | fn default() -> Self { | 137 | fn default() -> Self { |
| 127 | // on L5, just the fact that LSI is enabled makes things crash. | 138 | Self::new() |
| 128 | // TODO: investigate. | ||
| 129 | |||
| 130 | #[cfg(not(stm32l5))] | ||
| 131 | return Self::default_lsi(); | ||
| 132 | #[cfg(stm32l5)] | ||
| 133 | return Self::off(); | ||
| 134 | } | 139 | } |
| 135 | } | 140 | } |
| 136 | 141 | ||
diff --git a/embassy-stm32/src/rcc/c0.rs b/embassy-stm32/src/rcc/c0.rs index 0b749bcff..cac2a9149 100644 --- a/embassy-stm32/src/rcc/c0.rs +++ b/embassy-stm32/src/rcc/c0.rs | |||
| @@ -59,9 +59,8 @@ pub struct Config { | |||
| 59 | pub mux: super::mux::ClockMux, | 59 | pub mux: super::mux::ClockMux, |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | impl Default for Config { | 62 | impl Config { |
| 63 | #[inline] | 63 | pub const fn new() -> Self { |
| 64 | fn default() -> Config { | ||
| 65 | Config { | 64 | Config { |
| 66 | hsi: Some(Hsi { | 65 | hsi: Some(Hsi { |
| 67 | sys_div: HsiSysDiv::DIV4, | 66 | sys_div: HsiSysDiv::DIV4, |
| @@ -71,12 +70,18 @@ impl Default for Config { | |||
| 71 | sys: Sysclk::HSISYS, | 70 | sys: Sysclk::HSISYS, |
| 72 | ahb_pre: AHBPrescaler::DIV1, | 71 | ahb_pre: AHBPrescaler::DIV1, |
| 73 | apb1_pre: APBPrescaler::DIV1, | 72 | apb1_pre: APBPrescaler::DIV1, |
| 74 | ls: Default::default(), | 73 | ls: crate::rcc::LsConfig::new(), |
| 75 | mux: Default::default(), | 74 | mux: super::mux::ClockMux::default(), |
| 76 | } | 75 | } |
| 77 | } | 76 | } |
| 78 | } | 77 | } |
| 79 | 78 | ||
| 79 | impl Default for Config { | ||
| 80 | fn default() -> Config { | ||
| 81 | Self::new() | ||
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 80 | pub(crate) unsafe fn init(config: Config) { | 85 | pub(crate) unsafe fn init(config: Config) { |
| 81 | // Turn on the HSI | 86 | // Turn on the HSI |
| 82 | match config.hsi { | 87 | match config.hsi { |
diff --git a/embassy-stm32/src/rcc/f013.rs b/embassy-stm32/src/rcc/f013.rs index cfa223d1f..1155b6acd 100644 --- a/embassy-stm32/src/rcc/f013.rs +++ b/embassy-stm32/src/rcc/f013.rs | |||
| @@ -126,13 +126,13 @@ pub struct Config { | |||
| 126 | pub ls: super::LsConfig, | 126 | pub ls: super::LsConfig, |
| 127 | } | 127 | } |
| 128 | 128 | ||
| 129 | impl Default for Config { | 129 | impl Config { |
| 130 | fn default() -> Self { | 130 | pub const fn new() -> Self { |
| 131 | Self { | 131 | Self { |
| 132 | hsi: true, | 132 | hsi: true, |
| 133 | hse: None, | 133 | hse: None, |
| 134 | #[cfg(crs)] | 134 | #[cfg(crs)] |
| 135 | hsi48: Some(Default::default()), | 135 | hsi48: Some(crate::rcc::Hsi48Config::new()), |
| 136 | sys: Sysclk::HSI, | 136 | sys: Sysclk::HSI, |
| 137 | pll: None, | 137 | pll: None, |
| 138 | 138 | ||
| @@ -147,7 +147,7 @@ impl Default for Config { | |||
| 147 | apb1_pre: APBPrescaler::DIV1, | 147 | apb1_pre: APBPrescaler::DIV1, |
| 148 | #[cfg(not(stm32f0))] | 148 | #[cfg(not(stm32f0))] |
| 149 | apb2_pre: APBPrescaler::DIV1, | 149 | apb2_pre: APBPrescaler::DIV1, |
| 150 | ls: Default::default(), | 150 | ls: crate::rcc::LsConfig::new(), |
| 151 | 151 | ||
| 152 | #[cfg(stm32f1)] | 152 | #[cfg(stm32f1)] |
| 153 | // ensure ADC is not out of range by default even if APB2 is maxxed out (36mhz) | 153 | // ensure ADC is not out of range by default even if APB2 is maxxed out (36mhz) |
| @@ -163,11 +163,17 @@ impl Default for Config { | |||
| 163 | #[cfg(stm32f107)] | 163 | #[cfg(stm32f107)] |
| 164 | i2s3_src: I2s2src::SYS, | 164 | i2s3_src: I2s2src::SYS, |
| 165 | 165 | ||
| 166 | mux: Default::default(), | 166 | mux: super::mux::ClockMux::default(), |
| 167 | } | 167 | } |
| 168 | } | 168 | } |
| 169 | } | 169 | } |
| 170 | 170 | ||
| 171 | impl Default for Config { | ||
| 172 | fn default() -> Self { | ||
| 173 | Self::new() | ||
| 174 | } | ||
| 175 | } | ||
| 176 | |||
| 171 | /// Initialize and Set the clock frequencies | 177 | /// Initialize and Set the clock frequencies |
| 172 | pub(crate) unsafe fn init(config: Config) { | 178 | pub(crate) unsafe fn init(config: Config) { |
| 173 | // Turn on the HSI | 179 | // Turn on the HSI |
diff --git a/embassy-stm32/src/rcc/f247.rs b/embassy-stm32/src/rcc/f247.rs index ee67f1cc0..8f2e8db5f 100644 --- a/embassy-stm32/src/rcc/f247.rs +++ b/embassy-stm32/src/rcc/f247.rs | |||
| @@ -108,8 +108,8 @@ pub struct Config { | |||
| 108 | pub voltage: VoltageScale, | 108 | pub voltage: VoltageScale, |
| 109 | } | 109 | } |
| 110 | 110 | ||
| 111 | impl Default for Config { | 111 | impl Config { |
| 112 | fn default() -> Self { | 112 | pub const fn new() -> Self { |
| 113 | Self { | 113 | Self { |
| 114 | hsi: true, | 114 | hsi: true, |
| 115 | hse: None, | 115 | hse: None, |
| @@ -127,15 +127,21 @@ impl Default for Config { | |||
| 127 | apb1_pre: APBPrescaler::DIV1, | 127 | apb1_pre: APBPrescaler::DIV1, |
| 128 | apb2_pre: APBPrescaler::DIV1, | 128 | apb2_pre: APBPrescaler::DIV1, |
| 129 | 129 | ||
| 130 | ls: Default::default(), | 130 | ls: crate::rcc::LsConfig::new(), |
| 131 | 131 | ||
| 132 | #[cfg(stm32f2)] | 132 | #[cfg(stm32f2)] |
| 133 | voltage: VoltageScale::Range3, | 133 | voltage: VoltageScale::Range3, |
| 134 | mux: Default::default(), | 134 | mux: super::mux::ClockMux::default(), |
| 135 | } | 135 | } |
| 136 | } | 136 | } |
| 137 | } | 137 | } |
| 138 | 138 | ||
| 139 | impl Default for Config { | ||
| 140 | fn default() -> Self { | ||
| 141 | Self::new() | ||
| 142 | } | ||
| 143 | } | ||
| 144 | |||
| 139 | pub(crate) unsafe fn init(config: Config) { | 145 | pub(crate) unsafe fn init(config: Config) { |
| 140 | // set VOS to SCALE1, if use PLL | 146 | // set VOS to SCALE1, if use PLL |
| 141 | // TODO: check real clock speed before set VOS | 147 | // TODO: check real clock speed before set VOS |
diff --git a/embassy-stm32/src/rcc/g0.rs b/embassy-stm32/src/rcc/g0.rs index e391b1210..ce6398afd 100644 --- a/embassy-stm32/src/rcc/g0.rs +++ b/embassy-stm32/src/rcc/g0.rs | |||
| @@ -97,9 +97,8 @@ pub struct Config { | |||
| 97 | pub mux: super::mux::ClockMux, | 97 | pub mux: super::mux::ClockMux, |
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | impl Default for Config { | 100 | impl Config { |
| 101 | #[inline] | 101 | pub const fn new() -> Self { |
| 102 | fn default() -> Config { | ||
| 103 | Config { | 102 | Config { |
| 104 | hsi: Some(Hsi { | 103 | hsi: Some(Hsi { |
| 105 | sys_div: HsiSysDiv::DIV1, | 104 | sys_div: HsiSysDiv::DIV1, |
| @@ -107,18 +106,24 @@ impl Default for Config { | |||
| 107 | hse: None, | 106 | hse: None, |
| 108 | sys: Sysclk::HSI, | 107 | sys: Sysclk::HSI, |
| 109 | #[cfg(crs)] | 108 | #[cfg(crs)] |
| 110 | hsi48: Some(Default::default()), | 109 | hsi48: Some(crate::rcc::Hsi48Config::new()), |
| 111 | pll: None, | 110 | pll: None, |
| 112 | ahb_pre: AHBPrescaler::DIV1, | 111 | ahb_pre: AHBPrescaler::DIV1, |
| 113 | apb1_pre: APBPrescaler::DIV1, | 112 | apb1_pre: APBPrescaler::DIV1, |
| 114 | low_power_run: false, | 113 | low_power_run: false, |
| 115 | ls: Default::default(), | 114 | ls: crate::rcc::LsConfig::new(), |
| 116 | voltage_range: VoltageRange::RANGE1, | 115 | voltage_range: VoltageRange::RANGE1, |
| 117 | mux: Default::default(), | 116 | mux: super::mux::ClockMux::default(), |
| 118 | } | 117 | } |
| 119 | } | 118 | } |
| 120 | } | 119 | } |
| 121 | 120 | ||
| 121 | impl Default for Config { | ||
| 122 | fn default() -> Config { | ||
| 123 | Self::new() | ||
| 124 | } | ||
| 125 | } | ||
| 126 | |||
| 122 | #[derive(Default)] | 127 | #[derive(Default)] |
| 123 | pub struct PllFreq { | 128 | pub struct PllFreq { |
| 124 | pub pll_p: Option<Hertz>, | 129 | pub pll_p: Option<Hertz>, |
diff --git a/embassy-stm32/src/rcc/g4.rs b/embassy-stm32/src/rcc/g4.rs index d7d5c7388..da13e16aa 100644 --- a/embassy-stm32/src/rcc/g4.rs +++ b/embassy-stm32/src/rcc/g4.rs | |||
| @@ -91,26 +91,31 @@ pub struct Config { | |||
| 91 | pub mux: super::mux::ClockMux, | 91 | pub mux: super::mux::ClockMux, |
| 92 | } | 92 | } |
| 93 | 93 | ||
| 94 | impl Default for Config { | 94 | impl Config { |
| 95 | #[inline] | 95 | pub const fn new() -> Self { |
| 96 | fn default() -> Config { | ||
| 97 | Config { | 96 | Config { |
| 98 | hsi: true, | 97 | hsi: true, |
| 99 | hse: None, | 98 | hse: None, |
| 100 | sys: Sysclk::HSI, | 99 | sys: Sysclk::HSI, |
| 101 | hsi48: Some(Default::default()), | 100 | hsi48: Some(crate::rcc::Hsi48Config::new()), |
| 102 | pll: None, | 101 | pll: None, |
| 103 | ahb_pre: AHBPrescaler::DIV1, | 102 | ahb_pre: AHBPrescaler::DIV1, |
| 104 | apb1_pre: APBPrescaler::DIV1, | 103 | apb1_pre: APBPrescaler::DIV1, |
| 105 | apb2_pre: APBPrescaler::DIV1, | 104 | apb2_pre: APBPrescaler::DIV1, |
| 106 | low_power_run: false, | 105 | low_power_run: false, |
| 107 | ls: Default::default(), | 106 | ls: crate::rcc::LsConfig::new(), |
| 108 | boost: false, | 107 | boost: false, |
| 109 | mux: Default::default(), | 108 | mux: super::mux::ClockMux::default(), |
| 110 | } | 109 | } |
| 111 | } | 110 | } |
| 112 | } | 111 | } |
| 113 | 112 | ||
| 113 | impl Default for Config { | ||
| 114 | fn default() -> Config { | ||
| 115 | Self::new() | ||
| 116 | } | ||
| 117 | } | ||
| 118 | |||
| 114 | #[derive(Default)] | 119 | #[derive(Default)] |
| 115 | pub struct PllFreq { | 120 | pub struct PllFreq { |
| 116 | pub pll_p: Option<Hertz>, | 121 | pub pll_p: Option<Hertz>, |
diff --git a/embassy-stm32/src/rcc/h.rs b/embassy-stm32/src/rcc/h.rs index eaba8cefb..383f48874 100644 --- a/embassy-stm32/src/rcc/h.rs +++ b/embassy-stm32/src/rcc/h.rs | |||
| @@ -218,13 +218,13 @@ pub struct Config { | |||
| 218 | pub mux: super::mux::ClockMux, | 218 | pub mux: super::mux::ClockMux, |
| 219 | } | 219 | } |
| 220 | 220 | ||
| 221 | impl Default for Config { | 221 | impl Config { |
| 222 | fn default() -> Self { | 222 | pub const fn new() -> Self { |
| 223 | Self { | 223 | Self { |
| 224 | hsi: Some(HSIPrescaler::DIV1), | 224 | hsi: Some(HSIPrescaler::DIV1), |
| 225 | hse: None, | 225 | hse: None, |
| 226 | csi: false, | 226 | csi: false, |
| 227 | hsi48: Some(Default::default()), | 227 | hsi48: Some(crate::rcc::Hsi48Config::new()), |
| 228 | sys: Sysclk::HSI, | 228 | sys: Sysclk::HSI, |
| 229 | pll1: None, | 229 | pll1: None, |
| 230 | pll2: None, | 230 | pll2: None, |
| @@ -248,16 +248,22 @@ impl Default for Config { | |||
| 248 | voltage_scale: VoltageScale::Scale0, | 248 | voltage_scale: VoltageScale::Scale0, |
| 249 | #[cfg(rcc_h7rs)] | 249 | #[cfg(rcc_h7rs)] |
| 250 | voltage_scale: VoltageScale::HIGH, | 250 | voltage_scale: VoltageScale::HIGH, |
| 251 | ls: Default::default(), | 251 | ls: crate::rcc::LsConfig::new(), |
| 252 | 252 | ||
| 253 | #[cfg(any(pwr_h7rm0399, pwr_h7rm0455, pwr_h7rm0468, pwr_h7rs))] | 253 | #[cfg(any(pwr_h7rm0399, pwr_h7rm0455, pwr_h7rm0468, pwr_h7rs))] |
| 254 | supply_config: SupplyConfig::LDO, | 254 | supply_config: SupplyConfig::LDO, |
| 255 | 255 | ||
| 256 | mux: Default::default(), | 256 | mux: super::mux::ClockMux::default(), |
| 257 | } | 257 | } |
| 258 | } | 258 | } |
| 259 | } | 259 | } |
| 260 | 260 | ||
| 261 | impl Default for Config { | ||
| 262 | fn default() -> Self { | ||
| 263 | Self::new() | ||
| 264 | } | ||
| 265 | } | ||
| 266 | |||
| 261 | pub(crate) unsafe fn init(config: Config) { | 267 | pub(crate) unsafe fn init(config: Config) { |
| 262 | #[cfg(any(stm32h7))] | 268 | #[cfg(any(stm32h7))] |
| 263 | let pwr_reg = PWR.cr3(); | 269 | let pwr_reg = PWR.cr3(); |
diff --git a/embassy-stm32/src/rcc/hsi48.rs b/embassy-stm32/src/rcc/hsi48.rs index efabd059f..3ea5c96c9 100644 --- a/embassy-stm32/src/rcc/hsi48.rs +++ b/embassy-stm32/src/rcc/hsi48.rs | |||
| @@ -18,9 +18,15 @@ pub struct Hsi48Config { | |||
| 18 | pub sync_from_usb: bool, | 18 | pub sync_from_usb: bool, |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | impl Hsi48Config { | ||
| 22 | pub const fn new() -> Self { | ||
| 23 | Self { sync_from_usb: false } | ||
| 24 | } | ||
| 25 | } | ||
| 26 | |||
| 21 | impl Default for Hsi48Config { | 27 | impl Default for Hsi48Config { |
| 22 | fn default() -> Self { | 28 | fn default() -> Self { |
| 23 | Self { sync_from_usb: false } | 29 | Self::new() |
| 24 | } | 30 | } |
| 25 | } | 31 | } |
| 26 | 32 | ||
diff --git a/embassy-stm32/src/rcc/l.rs b/embassy-stm32/src/rcc/l.rs index 863942f1a..81b89046e 100644 --- a/embassy-stm32/src/rcc/l.rs +++ b/embassy-stm32/src/rcc/l.rs | |||
| @@ -68,9 +68,8 @@ pub struct Config { | |||
| 68 | pub mux: super::mux::ClockMux, | 68 | pub mux: super::mux::ClockMux, |
| 69 | } | 69 | } |
| 70 | 70 | ||
| 71 | impl Default for Config { | 71 | impl Config { |
| 72 | #[inline] | 72 | pub const fn new() -> Self { |
| 73 | fn default() -> Config { | ||
| 74 | Config { | 73 | Config { |
| 75 | hse: None, | 74 | hse: None, |
| 76 | hsi: false, | 75 | hsi: false, |
| @@ -90,15 +89,21 @@ impl Default for Config { | |||
| 90 | #[cfg(any(stm32l47x, stm32l48x, stm32l49x, stm32l4ax, rcc_l4plus, stm32l5))] | 89 | #[cfg(any(stm32l47x, stm32l48x, stm32l49x, stm32l4ax, rcc_l4plus, stm32l5))] |
| 91 | pllsai2: None, | 90 | pllsai2: None, |
| 92 | #[cfg(crs)] | 91 | #[cfg(crs)] |
| 93 | hsi48: Some(Default::default()), | 92 | hsi48: Some(crate::rcc::Hsi48Config::new()), |
| 94 | ls: Default::default(), | 93 | ls: crate::rcc::LsConfig::new(), |
| 95 | #[cfg(any(stm32l0, stm32l1))] | 94 | #[cfg(any(stm32l0, stm32l1))] |
| 96 | voltage_scale: VoltageScale::RANGE1, | 95 | voltage_scale: VoltageScale::RANGE1, |
| 97 | mux: Default::default(), | 96 | mux: super::mux::ClockMux::default(), |
| 98 | } | 97 | } |
| 99 | } | 98 | } |
| 100 | } | 99 | } |
| 101 | 100 | ||
| 101 | impl Default for Config { | ||
| 102 | fn default() -> Config { | ||
| 103 | Self::new() | ||
| 104 | } | ||
| 105 | } | ||
| 106 | |||
| 102 | #[cfg(stm32wb)] | 107 | #[cfg(stm32wb)] |
| 103 | pub const WPAN_DEFAULT: Config = Config { | 108 | pub const WPAN_DEFAULT: Config = Config { |
| 104 | hse: Some(Hse { | 109 | hse: Some(Hse { |
diff --git a/embassy-stm32/src/rcc/u5.rs b/embassy-stm32/src/rcc/u5.rs index 93a327be7..ff70466b9 100644 --- a/embassy-stm32/src/rcc/u5.rs +++ b/embassy-stm32/src/rcc/u5.rs | |||
| @@ -97,14 +97,14 @@ pub struct Config { | |||
| 97 | pub mux: super::mux::ClockMux, | 97 | pub mux: super::mux::ClockMux, |
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | impl Default for Config { | 100 | impl Config { |
| 101 | fn default() -> Self { | 101 | pub const fn new() -> Self { |
| 102 | Self { | 102 | Self { |
| 103 | msis: Some(Msirange::RANGE_4MHZ), | 103 | msis: Some(Msirange::RANGE_4MHZ), |
| 104 | msik: Some(Msirange::RANGE_4MHZ), | 104 | msik: Some(Msirange::RANGE_4MHZ), |
| 105 | hse: None, | 105 | hse: None, |
| 106 | hsi: false, | 106 | hsi: false, |
| 107 | hsi48: Some(Default::default()), | 107 | hsi48: Some(crate::rcc::Hsi48Config::new()), |
| 108 | pll1: None, | 108 | pll1: None, |
| 109 | pll2: None, | 109 | pll2: None, |
| 110 | pll3: None, | 110 | pll3: None, |
| @@ -114,12 +114,18 @@ impl Default for Config { | |||
| 114 | apb2_pre: APBPrescaler::DIV1, | 114 | apb2_pre: APBPrescaler::DIV1, |
| 115 | apb3_pre: APBPrescaler::DIV1, | 115 | apb3_pre: APBPrescaler::DIV1, |
| 116 | voltage_range: VoltageScale::RANGE1, | 116 | voltage_range: VoltageScale::RANGE1, |
| 117 | ls: Default::default(), | 117 | ls: crate::rcc::LsConfig::new(), |
| 118 | mux: Default::default(), | 118 | mux: super::mux::ClockMux::default(), |
| 119 | } | 119 | } |
| 120 | } | 120 | } |
| 121 | } | 121 | } |
| 122 | 122 | ||
| 123 | impl Default for Config { | ||
| 124 | fn default() -> Self { | ||
| 125 | Self::new() | ||
| 126 | } | ||
| 127 | } | ||
| 128 | |||
| 123 | pub(crate) unsafe fn init(config: Config) { | 129 | pub(crate) unsafe fn init(config: Config) { |
| 124 | // Set the requested power mode | 130 | // Set the requested power mode |
| 125 | PWR.vosr().modify(|w| w.set_vos(config.voltage_range)); | 131 | PWR.vosr().modify(|w| w.set_vos(config.voltage_range)); |
diff --git a/embassy-stm32/src/rcc/wba.rs b/embassy-stm32/src/rcc/wba.rs index 1fee648d4..b9fc4e423 100644 --- a/embassy-stm32/src/rcc/wba.rs +++ b/embassy-stm32/src/rcc/wba.rs | |||
| @@ -37,9 +37,8 @@ pub struct Config { | |||
| 37 | pub mux: super::mux::ClockMux, | 37 | pub mux: super::mux::ClockMux, |
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | impl Default for Config { | 40 | impl Config { |
| 41 | #[inline] | 41 | pub const fn new() -> Self { |
| 42 | fn default() -> Config { | ||
| 43 | Config { | 42 | Config { |
| 44 | hse: None, | 43 | hse: None, |
| 45 | hsi: true, | 44 | hsi: true, |
| @@ -48,13 +47,19 @@ impl Default for Config { | |||
| 48 | apb1_pre: APBPrescaler::DIV1, | 47 | apb1_pre: APBPrescaler::DIV1, |
| 49 | apb2_pre: APBPrescaler::DIV1, | 48 | apb2_pre: APBPrescaler::DIV1, |
| 50 | apb7_pre: APBPrescaler::DIV1, | 49 | apb7_pre: APBPrescaler::DIV1, |
| 51 | ls: Default::default(), | 50 | ls: crate::rcc::LsConfig::new(), |
| 52 | voltage_scale: VoltageScale::RANGE2, | 51 | voltage_scale: VoltageScale::RANGE2, |
| 53 | mux: Default::default(), | 52 | mux: super::mux::ClockMux::default(), |
| 54 | } | 53 | } |
| 55 | } | 54 | } |
| 56 | } | 55 | } |
| 57 | 56 | ||
| 57 | impl Default for Config { | ||
| 58 | fn default() -> Config { | ||
| 59 | Self::new() | ||
| 60 | } | ||
| 61 | } | ||
| 62 | |||
| 58 | fn hsi_enable() { | 63 | fn hsi_enable() { |
| 59 | RCC.cr().modify(|w| w.set_hsion(true)); | 64 | RCC.cr().modify(|w| w.set_hsion(true)); |
| 60 | while !RCC.cr().read().hsirdy() {} | 65 | while !RCC.cr().read().hsirdy() {} |
