diff options
| author | Dario Nieuwenhuis <[email protected]> | 2023-06-29 00:06:44 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-06-29 00:06:44 +0000 |
| commit | 8a0a7c81b6d94d23e59ed37e993c3cc807365413 (patch) | |
| tree | 27f53ff24ba4e89d0f0cda95d38cff6e3607ccb0 | |
| parent | 8cbe5b8e20999d77f032ee14f77d4f2c07a38088 (diff) | |
| parent | e892014b6572e74b58ea653cfed06614c496e6a5 (diff) | |
Merge pull request #1593 from embassy-rs/metapac-update
Update stm32-metapac, includes chiptool changes to use real Rust enums.
25 files changed, 121 insertions, 125 deletions
diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml index f15c6d0b7..b3fe9c1f5 100644 --- a/embassy-stm32/Cargo.toml +++ b/embassy-stm32/Cargo.toml | |||
| @@ -57,7 +57,7 @@ sdio-host = "0.5.0" | |||
| 57 | embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "a4f293d3a6f72158385f79c98634cb8a14d0d2fc", optional = true } | 57 | embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "a4f293d3a6f72158385f79c98634cb8a14d0d2fc", optional = true } |
| 58 | critical-section = "1.1" | 58 | critical-section = "1.1" |
| 59 | atomic-polyfill = "1.0.1" | 59 | atomic-polyfill = "1.0.1" |
| 60 | stm32-metapac = "11" | 60 | stm32-metapac = "12" |
| 61 | vcell = "0.1.3" | 61 | vcell = "0.1.3" |
| 62 | bxcan = "0.7.0" | 62 | bxcan = "0.7.0" |
| 63 | nb = "1.0.0" | 63 | nb = "1.0.0" |
| @@ -74,7 +74,7 @@ critical-section = { version = "1.1", features = ["std"] } | |||
| 74 | [build-dependencies] | 74 | [build-dependencies] |
| 75 | proc-macro2 = "1.0.36" | 75 | proc-macro2 = "1.0.36" |
| 76 | quote = "1.0.15" | 76 | quote = "1.0.15" |
| 77 | stm32-metapac = { version = "11", default-features = false, features = ["metadata"]} | 77 | stm32-metapac = { version = "12", default-features = false, features = ["metadata"]} |
| 78 | 78 | ||
| 79 | [features] | 79 | [features] |
| 80 | default = ["rt"] | 80 | default = ["rt"] |
diff --git a/embassy-stm32/src/adc/v3.rs b/embassy-stm32/src/adc/v3.rs index 94cdc86cd..3a6e58cf6 100644 --- a/embassy-stm32/src/adc/v3.rs +++ b/embassy-stm32/src/adc/v3.rs | |||
| @@ -211,10 +211,8 @@ impl<'d, T: Instance> Adc<'d, T> { | |||
| 211 | #[cfg(not(stm32g0))] | 211 | #[cfg(not(stm32g0))] |
| 212 | fn set_channel_sample_time(ch: u8, sample_time: SampleTime) { | 212 | fn set_channel_sample_time(ch: u8, sample_time: SampleTime) { |
| 213 | let sample_time = sample_time.into(); | 213 | let sample_time = sample_time.into(); |
| 214 | if ch <= 9 { | 214 | T::regs() |
| 215 | T::regs().smpr1().modify(|reg| reg.set_smp(ch as _, sample_time)); | 215 | .smpr(ch as usize / 10) |
| 216 | } else { | 216 | .modify(|reg| reg.set_smp(ch as usize % 10, sample_time)); |
| 217 | T::regs().smpr2().modify(|reg| reg.set_smp((ch - 10) as _, sample_time)); | ||
| 218 | } | ||
| 219 | } | 217 | } |
| 220 | } | 218 | } |
diff --git a/embassy-stm32/src/can/bxcan.rs b/embassy-stm32/src/can/bxcan.rs index 88eef528f..73861776a 100644 --- a/embassy-stm32/src/can/bxcan.rs +++ b/embassy-stm32/src/can/bxcan.rs | |||
| @@ -116,10 +116,10 @@ impl<'d, T: Instance> Can<'d, T> { | |||
| 116 | T::regs().ier().write(|w| { | 116 | T::regs().ier().write(|w| { |
| 117 | // TODO: fix metapac | 117 | // TODO: fix metapac |
| 118 | 118 | ||
| 119 | w.set_errie(Errie(1)); | 119 | w.set_errie(Errie::from_bits(1)); |
| 120 | w.set_fmpie(0, Fmpie(1)); | 120 | w.set_fmpie(0, Fmpie::from_bits(1)); |
| 121 | w.set_fmpie(1, Fmpie(1)); | 121 | w.set_fmpie(1, Fmpie::from_bits(1)); |
| 122 | w.set_tmeie(Tmeie(1)); | 122 | w.set_tmeie(Tmeie::from_bits(1)); |
| 123 | }); | 123 | }); |
| 124 | 124 | ||
| 125 | T::regs().mcr().write(|w| { | 125 | T::regs().mcr().write(|w| { |
diff --git a/embassy-stm32/src/eth/v1/rx_desc.rs b/embassy-stm32/src/eth/v1/rx_desc.rs index 01a073bb9..668378bea 100644 --- a/embassy-stm32/src/eth/v1/rx_desc.rs +++ b/embassy-stm32/src/eth/v1/rx_desc.rs | |||
| @@ -174,7 +174,7 @@ impl<'a> RDesRing<'a> { | |||
| 174 | // Receive descriptor unavailable | 174 | // Receive descriptor unavailable |
| 175 | Rps::SUSPENDED => RunningState::Stopped, | 175 | Rps::SUSPENDED => RunningState::Stopped, |
| 176 | // Closing receive descriptor | 176 | // Closing receive descriptor |
| 177 | Rps(0b101) => RunningState::Running, | 177 | Rps::_RESERVED_5 => RunningState::Running, |
| 178 | // Transferring the receive packet data from receive buffer to host memory | 178 | // Transferring the receive packet data from receive buffer to host memory |
| 179 | Rps::RUNNINGWRITING => RunningState::Running, | 179 | Rps::RUNNINGWRITING => RunningState::Running, |
| 180 | _ => RunningState::Unknown, | 180 | _ => RunningState::Unknown, |
diff --git a/embassy-stm32/src/pwm/complementary_pwm.rs b/embassy-stm32/src/pwm/complementary_pwm.rs index 0e153202e..4d64d005c 100644 --- a/embassy-stm32/src/pwm/complementary_pwm.rs +++ b/embassy-stm32/src/pwm/complementary_pwm.rs | |||
| @@ -243,7 +243,7 @@ mod tests { | |||
| 243 | for test_run in fn_results { | 243 | for test_run in fn_results { |
| 244 | let (ckd, bits) = compute_dead_time_value(test_run.value); | 244 | let (ckd, bits) = compute_dead_time_value(test_run.value); |
| 245 | 245 | ||
| 246 | assert_eq!(ckd.0, test_run.ckd.0); | 246 | assert_eq!(ckd.to_bits(), test_run.ckd.to_bits()); |
| 247 | assert_eq!(bits, test_run.bits); | 247 | assert_eq!(bits, test_run.bits); |
| 248 | } | 248 | } |
| 249 | } | 249 | } |
diff --git a/embassy-stm32/src/rcc/c0.rs b/embassy-stm32/src/rcc/c0.rs index 6c7b36647..df6e9047c 100644 --- a/embassy-stm32/src/rcc/c0.rs +++ b/embassy-stm32/src/rcc/c0.rs | |||
| @@ -126,7 +126,7 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 126 | }); | 126 | }); |
| 127 | while !RCC.cr().read().hsirdy() {} | 127 | while !RCC.cr().read().hsirdy() {} |
| 128 | 128 | ||
| 129 | (HSI_FREQ.0 >> div.0, Sw::HSI) | 129 | (HSI_FREQ.0 >> div.to_bits(), Sw::HSI) |
| 130 | } | 130 | } |
| 131 | ClockSrc::HSE(freq) => { | 131 | ClockSrc::HSE(freq) => { |
| 132 | // Enable HSE | 132 | // Enable HSE |
| @@ -157,7 +157,7 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 157 | let mut set_flash_latency_after = false; | 157 | let mut set_flash_latency_after = false; |
| 158 | FLASH.acr().modify(|w| { | 158 | FLASH.acr().modify(|w| { |
| 159 | // Is the current flash latency less than what we need at the new SYSCLK? | 159 | // Is the current flash latency less than what we need at the new SYSCLK? |
| 160 | if w.latency().0 <= target_flash_latency.0 { | 160 | if w.latency().to_bits() <= target_flash_latency.to_bits() { |
| 161 | // We must increase the number of wait states now | 161 | // We must increase the number of wait states now |
| 162 | w.set_latency(target_flash_latency) | 162 | w.set_latency(target_flash_latency) |
| 163 | } else { | 163 | } else { |
| @@ -171,12 +171,12 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 171 | // > Flash memory. | 171 | // > Flash memory. |
| 172 | // | 172 | // |
| 173 | // Enable flash prefetching if we have at least one wait state, and disable it otherwise. | 173 | // Enable flash prefetching if we have at least one wait state, and disable it otherwise. |
| 174 | w.set_prften(target_flash_latency.0 > 0); | 174 | w.set_prften(target_flash_latency.to_bits() > 0); |
| 175 | }); | 175 | }); |
| 176 | 176 | ||
| 177 | if !set_flash_latency_after { | 177 | if !set_flash_latency_after { |
| 178 | // Spin until the effective flash latency is compatible with the clock change | 178 | // Spin until the effective flash latency is compatible with the clock change |
| 179 | while FLASH.acr().read().latency().0 < target_flash_latency.0 {} | 179 | while FLASH.acr().read().latency().to_bits() < target_flash_latency.to_bits() {} |
| 180 | } | 180 | } |
| 181 | 181 | ||
| 182 | // Configure SYSCLK source, HCLK divisor, and PCLK divisor all at once | 182 | // Configure SYSCLK source, HCLK divisor, and PCLK divisor all at once |
| @@ -218,7 +218,7 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 218 | APBPrescaler::NotDivided => (ahb_freq, ahb_freq), | 218 | APBPrescaler::NotDivided => (ahb_freq, ahb_freq), |
| 219 | pre => { | 219 | pre => { |
| 220 | let pre: Ppre = pre.into(); | 220 | let pre: Ppre = pre.into(); |
| 221 | let pre: u8 = 1 << (pre.0 - 3); | 221 | let pre: u8 = 1 << (pre.to_bits() - 3); |
| 222 | let freq = ahb_freq / pre as u32; | 222 | let freq = ahb_freq / pre as u32; |
| 223 | (freq, freq * 2) | 223 | (freq, freq * 2) |
| 224 | } | 224 | } |
diff --git a/embassy-stm32/src/rcc/f0.rs b/embassy-stm32/src/rcc/f0.rs index eb62ab661..ca6eed284 100644 --- a/embassy-stm32/src/rcc/f0.rs +++ b/embassy-stm32/src/rcc/f0.rs | |||
| @@ -1,3 +1,5 @@ | |||
| 1 | use stm32_metapac::flash::vals::Latency; | ||
| 2 | |||
| 1 | use super::{set_freqs, Clocks}; | 3 | use super::{set_freqs, Clocks}; |
| 2 | use crate::pac::rcc::vals::{Hpre, Pllmul, Pllsrc, Ppre, Sw, Usbsw}; | 4 | use crate::pac::rcc::vals::{Hpre, Pllmul, Pllsrc, Ppre, Sw, Usbsw}; |
| 3 | use crate::pac::{FLASH, RCC}; | 5 | use crate::pac::{FLASH, RCC}; |
| @@ -85,14 +87,11 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 85 | let timer_mul = if ppre == 1 { 1 } else { 2 }; | 87 | let timer_mul = if ppre == 1 { 1 } else { 2 }; |
| 86 | 88 | ||
| 87 | FLASH.acr().write(|w| { | 89 | FLASH.acr().write(|w| { |
| 88 | let latency = if real_sysclk <= 24_000_000 { | 90 | w.set_latency(if real_sysclk <= 24_000_000 { |
| 89 | 0 | 91 | Latency::WS0 |
| 90 | } else if real_sysclk <= 48_000_000 { | ||
| 91 | 1 | ||
| 92 | } else { | 92 | } else { |
| 93 | 2 | 93 | Latency::WS1 |
| 94 | }; | 94 | }); |
| 95 | w.latency().0 = latency; | ||
| 96 | }); | 95 | }); |
| 97 | 96 | ||
| 98 | match (config.hse.is_some(), use_hsi48) { | 97 | match (config.hse.is_some(), use_hsi48) { |
| @@ -134,20 +133,20 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 134 | // TODO: Option to use CRS (Clock Recovery) | 133 | // TODO: Option to use CRS (Clock Recovery) |
| 135 | 134 | ||
| 136 | if let Some(pllmul_bits) = pllmul_bits { | 135 | if let Some(pllmul_bits) = pllmul_bits { |
| 137 | RCC.cfgr().modify(|w| w.set_pllmul(Pllmul(pllmul_bits))); | 136 | RCC.cfgr().modify(|w| w.set_pllmul(Pllmul::from_bits(pllmul_bits))); |
| 138 | 137 | ||
| 139 | RCC.cr().modify(|w| w.set_pllon(true)); | 138 | RCC.cr().modify(|w| w.set_pllon(true)); |
| 140 | while !RCC.cr().read().pllrdy() {} | 139 | while !RCC.cr().read().pllrdy() {} |
| 141 | 140 | ||
| 142 | RCC.cfgr().modify(|w| { | 141 | RCC.cfgr().modify(|w| { |
| 143 | w.set_ppre(Ppre(ppre_bits)); | 142 | w.set_ppre(Ppre::from_bits(ppre_bits)); |
| 144 | w.set_hpre(Hpre(hpre_bits)); | 143 | w.set_hpre(Hpre::from_bits(hpre_bits)); |
| 145 | w.set_sw(Sw::PLL) | 144 | w.set_sw(Sw::PLL) |
| 146 | }); | 145 | }); |
| 147 | } else { | 146 | } else { |
| 148 | RCC.cfgr().modify(|w| { | 147 | RCC.cfgr().modify(|w| { |
| 149 | w.set_ppre(Ppre(ppre_bits)); | 148 | w.set_ppre(Ppre::from_bits(ppre_bits)); |
| 150 | w.set_hpre(Hpre(hpre_bits)); | 149 | w.set_hpre(Hpre::from_bits(hpre_bits)); |
| 151 | 150 | ||
| 152 | if config.hse.is_some() { | 151 | if config.hse.is_some() { |
| 153 | w.set_sw(Sw::HSE); | 152 | w.set_sw(Sw::HSE); |
diff --git a/embassy-stm32/src/rcc/f1.rs b/embassy-stm32/src/rcc/f1.rs index 4769b7059..b6200231e 100644 --- a/embassy-stm32/src/rcc/f1.rs +++ b/embassy-stm32/src/rcc/f1.rs | |||
| @@ -106,11 +106,11 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 106 | // Only needed for stm32f103? | 106 | // Only needed for stm32f103? |
| 107 | FLASH.acr().write(|w| { | 107 | FLASH.acr().write(|w| { |
| 108 | w.set_latency(if real_sysclk <= 24_000_000 { | 108 | w.set_latency(if real_sysclk <= 24_000_000 { |
| 109 | Latency(0b000) | 109 | Latency::WS0 |
| 110 | } else if real_sysclk <= 48_000_000 { | 110 | } else if real_sysclk <= 48_000_000 { |
| 111 | Latency(0b001) | 111 | Latency::WS1 |
| 112 | } else { | 112 | } else { |
| 113 | Latency(0b010) | 113 | Latency::WS2 |
| 114 | }); | 114 | }); |
| 115 | }); | 115 | }); |
| 116 | 116 | ||
| @@ -147,12 +147,13 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 147 | 147 | ||
| 148 | if let Some(pllmul_bits) = pllmul_bits { | 148 | if let Some(pllmul_bits) = pllmul_bits { |
| 149 | let pllctpre_flag: u8 = if config.pllxtpre { 1 } else { 0 }; | 149 | let pllctpre_flag: u8 = if config.pllxtpre { 1 } else { 0 }; |
| 150 | RCC.cfgr().modify(|w| w.set_pllxtpre(Pllxtpre(pllctpre_flag))); | 150 | RCC.cfgr() |
| 151 | .modify(|w| w.set_pllxtpre(Pllxtpre::from_bits(pllctpre_flag))); | ||
| 151 | 152 | ||
| 152 | // enable PLL and wait for it to be ready | 153 | // enable PLL and wait for it to be ready |
| 153 | RCC.cfgr().modify(|w| { | 154 | RCC.cfgr().modify(|w| { |
| 154 | w.set_pllmul(Pllmul(pllmul_bits)); | 155 | w.set_pllmul(Pllmul::from_bits(pllmul_bits)); |
| 155 | w.set_pllsrc(Pllsrc(config.hse.is_some() as u8)); | 156 | w.set_pllsrc(Pllsrc::from_bits(config.hse.is_some() as u8)); |
| 156 | }); | 157 | }); |
| 157 | 158 | ||
| 158 | RCC.cr().modify(|w| w.set_pllon(true)); | 159 | RCC.cr().modify(|w| w.set_pllon(true)); |
| @@ -161,22 +162,19 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 161 | 162 | ||
| 162 | // Only needed for stm32f103? | 163 | // Only needed for stm32f103? |
| 163 | RCC.cfgr().modify(|w| { | 164 | RCC.cfgr().modify(|w| { |
| 164 | w.set_adcpre(Adcpre(apre_bits)); | 165 | w.set_adcpre(Adcpre::from_bits(apre_bits)); |
| 165 | w.set_ppre2(Ppre1(ppre2_bits)); | 166 | w.set_ppre2(Ppre1::from_bits(ppre2_bits)); |
| 166 | w.set_ppre1(Ppre1(ppre1_bits)); | 167 | w.set_ppre1(Ppre1::from_bits(ppre1_bits)); |
| 167 | w.set_hpre(Hpre(hpre_bits)); | 168 | w.set_hpre(Hpre::from_bits(hpre_bits)); |
| 168 | #[cfg(not(rcc_f100))] | 169 | #[cfg(not(rcc_f100))] |
| 169 | w.set_usbpre(Usbpre(usbpre as u8)); | 170 | w.set_usbpre(Usbpre::from_bits(usbpre as u8)); |
| 170 | w.set_sw(Sw(if pllmul_bits.is_some() { | 171 | w.set_sw(if pllmul_bits.is_some() { |
| 171 | // PLL | 172 | Sw::PLL |
| 172 | 0b10 | ||
| 173 | } else if config.hse.is_some() { | 173 | } else if config.hse.is_some() { |
| 174 | // HSE | 174 | Sw::HSE |
| 175 | 0b1 | ||
| 176 | } else { | 175 | } else { |
| 177 | // HSI | 176 | Sw::HSI |
| 178 | 0b0 | 177 | }); |
| 179 | })); | ||
| 180 | }); | 178 | }); |
| 181 | 179 | ||
| 182 | set_freqs(Clocks { | 180 | set_freqs(Clocks { |
diff --git a/embassy-stm32/src/rcc/f2.rs b/embassy-stm32/src/rcc/f2.rs index bcae64d0f..1525cc3c3 100644 --- a/embassy-stm32/src/rcc/f2.rs +++ b/embassy-stm32/src/rcc/f2.rs | |||
| @@ -485,7 +485,7 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 485 | w.set_ppre1(config.apb1_pre.into()); | 485 | w.set_ppre1(config.apb1_pre.into()); |
| 486 | w.set_ppre2(config.apb2_pre.into()); | 486 | w.set_ppre2(config.apb2_pre.into()); |
| 487 | }); | 487 | }); |
| 488 | while RCC.cfgr().read().sws() != sw.0 {} | 488 | while RCC.cfgr().read().sws().to_bits() != sw.to_bits() {} |
| 489 | 489 | ||
| 490 | // Turn off HSI to save power if we don't need it | 490 | // Turn off HSI to save power if we don't need it |
| 491 | if !config.hsi { | 491 | if !config.hsi { |
diff --git a/embassy-stm32/src/rcc/f4.rs b/embassy-stm32/src/rcc/f4.rs index bc430afb2..b84470440 100644 --- a/embassy-stm32/src/rcc/f4.rs +++ b/embassy-stm32/src/rcc/f4.rs | |||
| @@ -87,7 +87,7 @@ fn setup_pll(pllsrcclk: u32, use_hse: bool, pllsysclk: Option<u32>, plli2s: Opti | |||
| 87 | 87 | ||
| 88 | let sysclk = pllsysclk.unwrap_or(pllsrcclk); | 88 | let sysclk = pllsysclk.unwrap_or(pllsrcclk); |
| 89 | if pllsysclk.is_none() && !pll48clk { | 89 | if pllsysclk.is_none() && !pll48clk { |
| 90 | RCC.pllcfgr().modify(|w| w.set_pllsrc(Pllsrc(use_hse as u8))); | 90 | RCC.pllcfgr().modify(|w| w.set_pllsrc(Pllsrc::from_bits(use_hse as u8))); |
| 91 | 91 | ||
| 92 | return PllResults { | 92 | return PllResults { |
| 93 | use_pll: false, | 93 | use_pll: false, |
| @@ -141,9 +141,9 @@ fn setup_pll(pllsrcclk: u32, use_hse: bool, pllsysclk: Option<u32>, plli2s: Opti | |||
| 141 | RCC.pllcfgr().modify(|w| { | 141 | RCC.pllcfgr().modify(|w| { |
| 142 | w.set_pllm(pllm as u8); | 142 | w.set_pllm(pllm as u8); |
| 143 | w.set_plln(plln as u16); | 143 | w.set_plln(plln as u16); |
| 144 | w.set_pllp(Pllp(pllp as u8)); | 144 | w.set_pllp(Pllp::from_bits(pllp as u8)); |
| 145 | w.set_pllq(pllq as u8); | 145 | w.set_pllq(pllq as u8); |
| 146 | w.set_pllsrc(Pllsrc(use_hse as u8)); | 146 | w.set_pllsrc(Pllsrc::from_bits(use_hse as u8)); |
| 147 | }); | 147 | }); |
| 148 | 148 | ||
| 149 | let real_pllsysclk = vco_in * plln / sysclk_div; | 149 | let real_pllsysclk = vco_in * plln / sysclk_div; |
| @@ -323,7 +323,7 @@ fn flash_setup(sysclk: u32) { | |||
| 323 | critical_section::with(|_| { | 323 | critical_section::with(|_| { |
| 324 | FLASH | 324 | FLASH |
| 325 | .acr() | 325 | .acr() |
| 326 | .modify(|w| w.set_latency(Latency(((sysclk - 1) / FLASH_LATENCY_STEP) as u8))); | 326 | .modify(|w| w.set_latency(Latency::from_bits(((sysclk - 1) / FLASH_LATENCY_STEP) as u8))); |
| 327 | }); | 327 | }); |
| 328 | } | 328 | } |
| 329 | 329 | ||
| @@ -440,8 +440,8 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 440 | } | 440 | } |
| 441 | 441 | ||
| 442 | RCC.cfgr().modify(|w| { | 442 | RCC.cfgr().modify(|w| { |
| 443 | w.set_ppre2(Ppre(ppre2_bits)); | 443 | w.set_ppre2(Ppre::from_bits(ppre2_bits)); |
| 444 | w.set_ppre1(Ppre(ppre1_bits)); | 444 | w.set_ppre1(Ppre::from_bits(ppre1_bits)); |
| 445 | w.set_hpre(hpre_bits); | 445 | w.set_hpre(hpre_bits); |
| 446 | }); | 446 | }); |
| 447 | 447 | ||
diff --git a/embassy-stm32/src/rcc/f7.rs b/embassy-stm32/src/rcc/f7.rs index 71215cac5..85cb9c661 100644 --- a/embassy-stm32/src/rcc/f7.rs +++ b/embassy-stm32/src/rcc/f7.rs | |||
| @@ -30,7 +30,7 @@ fn setup_pll(pllsrcclk: u32, use_hse: bool, pllsysclk: Option<u32>, pll48clk: bo | |||
| 30 | 30 | ||
| 31 | let sysclk = pllsysclk.unwrap_or(pllsrcclk); | 31 | let sysclk = pllsysclk.unwrap_or(pllsrcclk); |
| 32 | if pllsysclk.is_none() && !pll48clk { | 32 | if pllsysclk.is_none() && !pll48clk { |
| 33 | RCC.pllcfgr().modify(|w| w.set_pllsrc(Pllsrc(use_hse as u8))); | 33 | RCC.pllcfgr().modify(|w| w.set_pllsrc(Pllsrc::from_bits(use_hse as u8))); |
| 34 | 34 | ||
| 35 | return PllResults { | 35 | return PllResults { |
| 36 | use_pll: false, | 36 | use_pll: false, |
| @@ -83,9 +83,9 @@ fn setup_pll(pllsrcclk: u32, use_hse: bool, pllsysclk: Option<u32>, pll48clk: bo | |||
| 83 | RCC.pllcfgr().modify(|w| { | 83 | RCC.pllcfgr().modify(|w| { |
| 84 | w.set_pllm(pllm as u8); | 84 | w.set_pllm(pllm as u8); |
| 85 | w.set_plln(plln as u16); | 85 | w.set_plln(plln as u16); |
| 86 | w.set_pllp(Pllp(pllp as u8)); | 86 | w.set_pllp(Pllp::from_bits(pllp as u8)); |
| 87 | w.set_pllq(pllq as u8); | 87 | w.set_pllq(pllq as u8); |
| 88 | w.set_pllsrc(Pllsrc(use_hse as u8)); | 88 | w.set_pllsrc(Pllsrc::from_bits(use_hse as u8)); |
| 89 | }); | 89 | }); |
| 90 | 90 | ||
| 91 | let real_pllsysclk = vco_in * plln / sysclk_div; | 91 | let real_pllsysclk = vco_in * plln / sysclk_div; |
| @@ -106,7 +106,7 @@ fn flash_setup(sysclk: u32) { | |||
| 106 | critical_section::with(|_| { | 106 | critical_section::with(|_| { |
| 107 | FLASH | 107 | FLASH |
| 108 | .acr() | 108 | .acr() |
| 109 | .modify(|w| w.set_latency(Latency(((sysclk - 1) / FLASH_LATENCY_STEP) as u8))); | 109 | .modify(|w| w.set_latency(Latency::from_bits(((sysclk - 1) / FLASH_LATENCY_STEP) as u8))); |
| 110 | }); | 110 | }); |
| 111 | } | 111 | } |
| 112 | 112 | ||
| @@ -246,8 +246,8 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 246 | } | 246 | } |
| 247 | 247 | ||
| 248 | RCC.cfgr().modify(|w| { | 248 | RCC.cfgr().modify(|w| { |
| 249 | w.set_ppre2(Ppre(ppre2_bits)); | 249 | w.set_ppre2(Ppre::from_bits(ppre2_bits)); |
| 250 | w.set_ppre1(Ppre(ppre1_bits)); | 250 | w.set_ppre1(Ppre::from_bits(ppre1_bits)); |
| 251 | w.set_hpre(hpre_bits); | 251 | w.set_hpre(hpre_bits); |
| 252 | }); | 252 | }); |
| 253 | 253 | ||
diff --git a/embassy-stm32/src/rcc/g0.rs b/embassy-stm32/src/rcc/g0.rs index 17c73c36b..5e3a7911a 100644 --- a/embassy-stm32/src/rcc/g0.rs +++ b/embassy-stm32/src/rcc/g0.rs | |||
| @@ -344,7 +344,7 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 344 | }); | 344 | }); |
| 345 | while !RCC.cr().read().hsirdy() {} | 345 | while !RCC.cr().read().hsirdy() {} |
| 346 | 346 | ||
| 347 | (HSI_FREQ.0 >> div.0, Sw::HSI) | 347 | (HSI_FREQ.0 >> div.to_bits(), Sw::HSI) |
| 348 | } | 348 | } |
| 349 | ClockSrc::HSE(freq) => { | 349 | ClockSrc::HSE(freq) => { |
| 350 | // Enable HSE | 350 | // Enable HSE |
| @@ -381,7 +381,7 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 381 | let mut set_flash_latency_after = false; | 381 | let mut set_flash_latency_after = false; |
| 382 | FLASH.acr().modify(|w| { | 382 | FLASH.acr().modify(|w| { |
| 383 | // Is the current flash latency less than what we need at the new SYSCLK? | 383 | // Is the current flash latency less than what we need at the new SYSCLK? |
| 384 | if w.latency().0 <= target_flash_latency.0 { | 384 | if w.latency().to_bits() <= target_flash_latency.to_bits() { |
| 385 | // We must increase the number of wait states now | 385 | // We must increase the number of wait states now |
| 386 | w.set_latency(target_flash_latency) | 386 | w.set_latency(target_flash_latency) |
| 387 | } else { | 387 | } else { |
| @@ -395,12 +395,12 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 395 | // > Flash memory. | 395 | // > Flash memory. |
| 396 | // | 396 | // |
| 397 | // Enable flash prefetching if we have at least one wait state, and disable it otherwise. | 397 | // Enable flash prefetching if we have at least one wait state, and disable it otherwise. |
| 398 | w.set_prften(target_flash_latency.0 > 0); | 398 | w.set_prften(target_flash_latency.to_bits() > 0); |
| 399 | }); | 399 | }); |
| 400 | 400 | ||
| 401 | if !set_flash_latency_after { | 401 | if !set_flash_latency_after { |
| 402 | // Spin until the effective flash latency is compatible with the clock change | 402 | // Spin until the effective flash latency is compatible with the clock change |
| 403 | while FLASH.acr().read().latency().0 < target_flash_latency.0 {} | 403 | while FLASH.acr().read().latency().to_bits() < target_flash_latency.to_bits() {} |
| 404 | } | 404 | } |
| 405 | 405 | ||
| 406 | // Configure SYSCLK source, HCLK divisor, and PCLK divisor all at once | 406 | // Configure SYSCLK source, HCLK divisor, and PCLK divisor all at once |
| @@ -442,7 +442,7 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 442 | APBPrescaler::NotDivided => (ahb_freq, ahb_freq), | 442 | APBPrescaler::NotDivided => (ahb_freq, ahb_freq), |
| 443 | pre => { | 443 | pre => { |
| 444 | let pre: Ppre = pre.into(); | 444 | let pre: Ppre = pre.into(); |
| 445 | let pre: u8 = 1 << (pre.0 - 3); | 445 | let pre: u8 = 1 << (pre.to_bits() - 3); |
| 446 | let freq = ahb_freq / pre as u32; | 446 | let freq = ahb_freq / pre as u32; |
| 447 | (freq, freq * 2) | 447 | (freq, freq * 2) |
| 448 | } | 448 | } |
diff --git a/embassy-stm32/src/rcc/h7.rs b/embassy-stm32/src/rcc/h7.rs index daa1cd61f..f3a98c794 100644 --- a/embassy-stm32/src/rcc/h7.rs +++ b/embassy-stm32/src/rcc/h7.rs | |||
| @@ -601,22 +601,22 @@ pub(crate) unsafe fn init(mut config: Config) { | |||
| 601 | 601 | ||
| 602 | // Core Prescaler / AHB Prescaler / APB3 Prescaler | 602 | // Core Prescaler / AHB Prescaler / APB3 Prescaler |
| 603 | RCC.d1cfgr().modify(|w| { | 603 | RCC.d1cfgr().modify(|w| { |
| 604 | w.set_d1cpre(Hpre(d1cpre_bits)); | 604 | w.set_d1cpre(Hpre::from_bits(d1cpre_bits)); |
| 605 | w.set_d1ppre(Dppre(ppre3_bits)); | 605 | w.set_d1ppre(Dppre::from_bits(ppre3_bits)); |
| 606 | w.set_hpre(hpre_bits) | 606 | w.set_hpre(hpre_bits) |
| 607 | }); | 607 | }); |
| 608 | // Ensure core prescaler value is valid before future lower | 608 | // Ensure core prescaler value is valid before future lower |
| 609 | // core voltage | 609 | // core voltage |
| 610 | while RCC.d1cfgr().read().d1cpre().0 != d1cpre_bits {} | 610 | while RCC.d1cfgr().read().d1cpre().to_bits() != d1cpre_bits {} |
| 611 | 611 | ||
| 612 | // APB1 / APB2 Prescaler | 612 | // APB1 / APB2 Prescaler |
| 613 | RCC.d2cfgr().modify(|w| { | 613 | RCC.d2cfgr().modify(|w| { |
| 614 | w.set_d2ppre1(Dppre(ppre1_bits)); | 614 | w.set_d2ppre1(Dppre::from_bits(ppre1_bits)); |
| 615 | w.set_d2ppre2(Dppre(ppre2_bits)); | 615 | w.set_d2ppre2(Dppre::from_bits(ppre2_bits)); |
| 616 | }); | 616 | }); |
| 617 | 617 | ||
| 618 | // APB4 Prescaler | 618 | // APB4 Prescaler |
| 619 | RCC.d3cfgr().modify(|w| w.set_d3ppre(Dppre(ppre4_bits))); | 619 | RCC.d3cfgr().modify(|w| w.set_d3ppre(Dppre::from_bits(ppre4_bits))); |
| 620 | 620 | ||
| 621 | // Peripheral Clock (per_ck) | 621 | // Peripheral Clock (per_ck) |
| 622 | RCC.d1ccipr().modify(|w| w.set_ckpersel(ckpersel)); | 622 | RCC.d1ccipr().modify(|w| w.set_ckpersel(ckpersel)); |
| @@ -640,7 +640,7 @@ pub(crate) unsafe fn init(mut config: Config) { | |||
| 640 | _ => Sw::HSI, | 640 | _ => Sw::HSI, |
| 641 | }; | 641 | }; |
| 642 | RCC.cfgr().modify(|w| w.set_sw(sw)); | 642 | RCC.cfgr().modify(|w| w.set_sw(sw)); |
| 643 | while RCC.cfgr().read().sws() != sw.0 {} | 643 | while RCC.cfgr().read().sws().to_bits() != sw.to_bits() {} |
| 644 | 644 | ||
| 645 | // IO compensation cell - Requires CSI clock and SYSCFG | 645 | // IO compensation cell - Requires CSI clock and SYSCFG |
| 646 | assert!(RCC.cr().read().csirdy()); | 646 | assert!(RCC.cr().read().csirdy()); |
| @@ -806,7 +806,8 @@ mod pll { | |||
| 806 | RCC.pllcfgr().modify(|w| w.set_pllfracen(plln, false)); | 806 | RCC.pllcfgr().modify(|w| w.set_pllfracen(plln, false)); |
| 807 | let vco_ck = ref_x_ck * pll_x_n; | 807 | let vco_ck = ref_x_ck * pll_x_n; |
| 808 | 808 | ||
| 809 | RCC.plldivr(plln).modify(|w| w.set_divp1(Divp((pll_x_p - 1) as u8))); | 809 | RCC.plldivr(plln) |
| 810 | .modify(|w| w.set_divp1(Divp::from_bits((pll_x_p - 1) as u8))); | ||
| 810 | RCC.pllcfgr().modify(|w| w.set_divpen(plln, true)); | 811 | RCC.pllcfgr().modify(|w| w.set_divpen(plln, true)); |
| 811 | 812 | ||
| 812 | // Calulate additional output dividers | 813 | // Calulate additional output dividers |
diff --git a/embassy-stm32/src/rcc/l0.rs b/embassy-stm32/src/rcc/l0.rs index d53b61069..46a528e31 100644 --- a/embassy-stm32/src/rcc/l0.rs +++ b/embassy-stm32/src/rcc/l0.rs | |||
| @@ -293,7 +293,7 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 293 | AHBPrescaler::NotDivided => sys_clk, | 293 | AHBPrescaler::NotDivided => sys_clk, |
| 294 | pre => { | 294 | pre => { |
| 295 | let pre: Hpre = pre.into(); | 295 | let pre: Hpre = pre.into(); |
| 296 | let pre = 1 << (pre.0 as u32 - 7); | 296 | let pre = 1 << (pre.to_bits() as u32 - 7); |
| 297 | sys_clk / pre | 297 | sys_clk / pre |
| 298 | } | 298 | } |
| 299 | }; | 299 | }; |
| @@ -302,7 +302,7 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 302 | APBPrescaler::NotDivided => (ahb_freq, ahb_freq), | 302 | APBPrescaler::NotDivided => (ahb_freq, ahb_freq), |
| 303 | pre => { | 303 | pre => { |
| 304 | let pre: Ppre = pre.into(); | 304 | let pre: Ppre = pre.into(); |
| 305 | let pre: u8 = 1 << (pre.0 - 3); | 305 | let pre: u8 = 1 << (pre.to_bits() - 3); |
| 306 | let freq = ahb_freq / pre as u32; | 306 | let freq = ahb_freq / pre as u32; |
| 307 | (freq, freq * 2) | 307 | (freq, freq * 2) |
| 308 | } | 308 | } |
| @@ -312,7 +312,7 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 312 | APBPrescaler::NotDivided => (ahb_freq, ahb_freq), | 312 | APBPrescaler::NotDivided => (ahb_freq, ahb_freq), |
| 313 | pre => { | 313 | pre => { |
| 314 | let pre: Ppre = pre.into(); | 314 | let pre: Ppre = pre.into(); |
| 315 | let pre: u8 = 1 << (pre.0 - 3); | 315 | let pre: u8 = 1 << (pre.to_bits() - 3); |
| 316 | let freq = ahb_freq / pre as u32; | 316 | let freq = ahb_freq / pre as u32; |
| 317 | (freq, freq * 2) | 317 | (freq, freq * 2) |
| 318 | } | 318 | } |
diff --git a/embassy-stm32/src/rcc/l1.rs b/embassy-stm32/src/rcc/l1.rs index c907fa88a..59a6eac8f 100644 --- a/embassy-stm32/src/rcc/l1.rs +++ b/embassy-stm32/src/rcc/l1.rs | |||
| @@ -294,7 +294,7 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 294 | AHBPrescaler::NotDivided => sys_clk, | 294 | AHBPrescaler::NotDivided => sys_clk, |
| 295 | pre => { | 295 | pre => { |
| 296 | let pre: Hpre = pre.into(); | 296 | let pre: Hpre = pre.into(); |
| 297 | let pre = 1 << (pre.0 as u32 - 7); | 297 | let pre = 1 << (pre.to_bits() as u32 - 7); |
| 298 | sys_clk / pre | 298 | sys_clk / pre |
| 299 | } | 299 | } |
| 300 | }; | 300 | }; |
| @@ -303,7 +303,7 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 303 | APBPrescaler::NotDivided => (ahb_freq, ahb_freq), | 303 | APBPrescaler::NotDivided => (ahb_freq, ahb_freq), |
| 304 | pre => { | 304 | pre => { |
| 305 | let pre: Ppre = pre.into(); | 305 | let pre: Ppre = pre.into(); |
| 306 | let pre: u8 = 1 << (pre.0 - 3); | 306 | let pre: u8 = 1 << (pre.to_bits() - 3); |
| 307 | let freq = ahb_freq / pre as u32; | 307 | let freq = ahb_freq / pre as u32; |
| 308 | (freq, freq * 2) | 308 | (freq, freq * 2) |
| 309 | } | 309 | } |
| @@ -313,7 +313,7 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 313 | APBPrescaler::NotDivided => (ahb_freq, ahb_freq), | 313 | APBPrescaler::NotDivided => (ahb_freq, ahb_freq), |
| 314 | pre => { | 314 | pre => { |
| 315 | let pre: Ppre = pre.into(); | 315 | let pre: Ppre = pre.into(); |
| 316 | let pre: u8 = 1 << (pre.0 - 3); | 316 | let pre: u8 = 1 << (pre.to_bits() - 3); |
| 317 | let freq = ahb_freq / pre as u32; | 317 | let freq = ahb_freq / pre as u32; |
| 318 | (freq, freq * 2) | 318 | (freq, freq * 2) |
| 319 | } | 319 | } |
diff --git a/embassy-stm32/src/rcc/l4.rs b/embassy-stm32/src/rcc/l4.rs index f8c1a6e06..20cb8c91c 100644 --- a/embassy-stm32/src/rcc/l4.rs +++ b/embassy-stm32/src/rcc/l4.rs | |||
| @@ -635,7 +635,7 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 635 | AHBPrescaler::NotDivided => sys_clk, | 635 | AHBPrescaler::NotDivided => sys_clk, |
| 636 | pre => { | 636 | pre => { |
| 637 | let pre: Hpre = pre.into(); | 637 | let pre: Hpre = pre.into(); |
| 638 | let pre = 1 << (pre.0 as u32 - 7); | 638 | let pre = 1 << (pre.to_bits() as u32 - 7); |
| 639 | sys_clk / pre | 639 | sys_clk / pre |
| 640 | } | 640 | } |
| 641 | }; | 641 | }; |
| @@ -644,7 +644,7 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 644 | APBPrescaler::NotDivided => (ahb_freq, ahb_freq), | 644 | APBPrescaler::NotDivided => (ahb_freq, ahb_freq), |
| 645 | pre => { | 645 | pre => { |
| 646 | let pre: Ppre = pre.into(); | 646 | let pre: Ppre = pre.into(); |
| 647 | let pre: u8 = 1 << (pre.0 - 3); | 647 | let pre: u8 = 1 << (pre.to_bits() - 3); |
| 648 | let freq = ahb_freq / pre as u32; | 648 | let freq = ahb_freq / pre as u32; |
| 649 | (freq, freq * 2) | 649 | (freq, freq * 2) |
| 650 | } | 650 | } |
| @@ -654,7 +654,7 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 654 | APBPrescaler::NotDivided => (ahb_freq, ahb_freq), | 654 | APBPrescaler::NotDivided => (ahb_freq, ahb_freq), |
| 655 | pre => { | 655 | pre => { |
| 656 | let pre: Ppre = pre.into(); | 656 | let pre: Ppre = pre.into(); |
| 657 | let pre: u8 = 1 << (pre.0 - 3); | 657 | let pre: u8 = 1 << (pre.to_bits() - 3); |
| 658 | let freq = ahb_freq / pre as u32; | 658 | let freq = ahb_freq / pre as u32; |
| 659 | (freq, freq * 2) | 659 | (freq, freq * 2) |
| 660 | } | 660 | } |
diff --git a/embassy-stm32/src/rcc/l5.rs b/embassy-stm32/src/rcc/l5.rs index f56fce365..16da65d5e 100644 --- a/embassy-stm32/src/rcc/l5.rs +++ b/embassy-stm32/src/rcc/l5.rs | |||
| @@ -461,7 +461,7 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 461 | AHBPrescaler::NotDivided => sys_clk, | 461 | AHBPrescaler::NotDivided => sys_clk, |
| 462 | pre => { | 462 | pre => { |
| 463 | let pre: Hpre = pre.into(); | 463 | let pre: Hpre = pre.into(); |
| 464 | let pre = 1 << (pre.0 as u32 - 7); | 464 | let pre = 1 << (pre.to_bits() as u32 - 7); |
| 465 | sys_clk / pre | 465 | sys_clk / pre |
| 466 | } | 466 | } |
| 467 | }; | 467 | }; |
| @@ -470,7 +470,7 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 470 | APBPrescaler::NotDivided => (ahb_freq, ahb_freq), | 470 | APBPrescaler::NotDivided => (ahb_freq, ahb_freq), |
| 471 | pre => { | 471 | pre => { |
| 472 | let pre: Ppre = pre.into(); | 472 | let pre: Ppre = pre.into(); |
| 473 | let pre: u8 = 1 << (pre.0 - 3); | 473 | let pre: u8 = 1 << (pre.to_bits() - 3); |
| 474 | let freq = ahb_freq / pre as u32; | 474 | let freq = ahb_freq / pre as u32; |
| 475 | (freq, freq * 2) | 475 | (freq, freq * 2) |
| 476 | } | 476 | } |
| @@ -480,7 +480,7 @@ pub(crate) unsafe fn init(config: Config) { | |||
| 480 | APBPrescaler::NotDivided => (ahb_freq, ahb_freq), | 480 | APBPrescaler::NotDivided => (ahb_freq, ahb_freq), |
| 481 | pre => { | 481 | pre => { |
| 482 | let pre: Ppre = pre.into(); | 482 | let pre: Ppre = pre.into(); |
| 483 | let pre: u8 = 1 << (pre.0 - 3); | 483 | let pre: u8 = 1 << (pre.to_bits() - 3); |
| 484 | let freq = ahb_freq / pre as u32; | 484 | let freq = ahb_freq / pre as u32; |
| 485 | (freq, freq * 2) | 485 | (freq, freq * 2) |
| 486 | } | 486 | } |
diff --git a/embassy-stm32/src/rcc/u5.rs b/embassy-stm32/src/rcc/u5.rs index 81507a4d6..cfc07f069 100644 --- a/embassy-stm32/src/rcc/u5.rs +++ b/embassy-stm32/src/rcc/u5.rs | |||
| @@ -126,7 +126,7 @@ pub enum PllM { | |||
| 126 | 126 | ||
| 127 | impl Into<Pllm> for PllM { | 127 | impl Into<Pllm> for PllM { |
| 128 | fn into(self) -> Pllm { | 128 | fn into(self) -> Pllm { |
| 129 | Pllm(self as u8) | 129 | Pllm::from_bits(self as u8) |
| 130 | } | 130 | } |
| 131 | } | 131 | } |
| 132 | 132 | ||
diff --git a/embassy-stm32/src/rtc/v2.rs b/embassy-stm32/src/rtc/v2.rs index e1615b34c..a2eace6d3 100644 --- a/embassy-stm32/src/rtc/v2.rs +++ b/embassy-stm32/src/rtc/v2.rs | |||
| @@ -36,7 +36,7 @@ impl<'d, T: Instance> super::Rtc<'d, T> { | |||
| 36 | #[cfg(rtc_v2wb)] | 36 | #[cfg(rtc_v2wb)] |
| 37 | let rtcsel = reg.rtcsel(); | 37 | let rtcsel = reg.rtcsel(); |
| 38 | #[cfg(not(rtc_v2wb))] | 38 | #[cfg(not(rtc_v2wb))] |
| 39 | let rtcsel = reg.rtcsel().0; | 39 | let rtcsel = reg.rtcsel().to_bits(); |
| 40 | 40 | ||
| 41 | if !reg.rtcen() || rtcsel != clock_config { | 41 | if !reg.rtcen() || rtcsel != clock_config { |
| 42 | #[cfg(not(any(rtc_v2l0, rtc_v2l1)))] | 42 | #[cfg(not(any(rtc_v2l0, rtc_v2l1)))] |
| @@ -54,7 +54,7 @@ impl<'d, T: Instance> super::Rtc<'d, T> { | |||
| 54 | 54 | ||
| 55 | // Select RTC source | 55 | // Select RTC source |
| 56 | #[cfg(not(rtc_v2wb))] | 56 | #[cfg(not(rtc_v2wb))] |
| 57 | w.set_rtcsel(Rtcsel(clock_config)); | 57 | w.set_rtcsel(Rtcsel::from_bits(clock_config)); |
| 58 | #[cfg(rtc_v2wb)] | 58 | #[cfg(rtc_v2wb)] |
| 59 | w.set_rtcsel(clock_config); | 59 | w.set_rtcsel(clock_config); |
| 60 | w.set_rtcen(true); | 60 | w.set_rtcen(true); |
diff --git a/embassy-stm32/src/rtc/v3.rs b/embassy-stm32/src/rtc/v3.rs index 7c91046a2..7e5c64d90 100644 --- a/embassy-stm32/src/rtc/v3.rs +++ b/embassy-stm32/src/rtc/v3.rs | |||
| @@ -26,7 +26,7 @@ impl<'d, T: Instance> super::Rtc<'d, T> { | |||
| 26 | 26 | ||
| 27 | let config_rtcsel = rtc_config.clock_config as u8; | 27 | let config_rtcsel = rtc_config.clock_config as u8; |
| 28 | #[cfg(not(any(rcc_wl5, rcc_wle)))] | 28 | #[cfg(not(any(rcc_wl5, rcc_wle)))] |
| 29 | let config_rtcsel = crate::pac::rcc::vals::Rtcsel(config_rtcsel); | 29 | let config_rtcsel = crate::pac::rcc::vals::Rtcsel::from_bits(config_rtcsel); |
| 30 | 30 | ||
| 31 | if !reg.rtcen() || reg.rtcsel() != config_rtcsel { | 31 | if !reg.rtcen() || reg.rtcsel() != config_rtcsel { |
| 32 | crate::pac::RCC.bdcr().modify(|w| w.set_bdrst(true)); | 32 | crate::pac::RCC.bdcr().modify(|w| w.set_bdrst(true)); |
diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs index 1cddac992..c3224073d 100644 --- a/embassy-stm32/src/spi/mod.rs +++ b/embassy-stm32/src/spi/mod.rs | |||
| @@ -650,7 +650,7 @@ fn compute_baud_rate(clocks: Hertz, freq: Hertz) -> Br { | |||
| 650 | _ => 0b111, | 650 | _ => 0b111, |
| 651 | }; | 651 | }; |
| 652 | 652 | ||
| 653 | Br(val) | 653 | Br::from_bits(val) |
| 654 | } | 654 | } |
| 655 | 655 | ||
| 656 | trait RegsExt { | 656 | trait RegsExt { |
| @@ -772,7 +772,7 @@ fn set_rxdmaen(regs: Regs, val: bool) { | |||
| 772 | 772 | ||
| 773 | fn finish_dma(regs: Regs) { | 773 | fn finish_dma(regs: Regs) { |
| 774 | #[cfg(spi_v2)] | 774 | #[cfg(spi_v2)] |
| 775 | while regs.sr().read().ftlvl() > 0 {} | 775 | while regs.sr().read().ftlvl().to_bits() > 0 {} |
| 776 | 776 | ||
| 777 | #[cfg(any(spi_v3, spi_v4, spi_v5))] | 777 | #[cfg(any(spi_v3, spi_v4, spi_v5))] |
| 778 | while !regs.sr().read().txc() {} | 778 | while !regs.sr().read().txc() {} |
diff --git a/embassy-stm32/src/usart/mod.rs b/embassy-stm32/src/usart/mod.rs index 47a79c187..c97efbf0a 100644 --- a/embassy-stm32/src/usart/mod.rs +++ b/embassy-stm32/src/usart/mod.rs | |||
| @@ -869,7 +869,7 @@ fn configure(r: Regs, config: &Config, pclk_freq: Hertz, kind: Kind, enable_rx: | |||
| 869 | _ => vals::Ps::EVEN, | 869 | _ => vals::Ps::EVEN, |
| 870 | }); | 870 | }); |
| 871 | #[cfg(not(usart_v1))] | 871 | #[cfg(not(usart_v1))] |
| 872 | w.set_over8(vals::Over8(over8 as _)); | 872 | w.set_over8(vals::Over8::from_bits(over8 as _)); |
| 873 | }); | 873 | }); |
| 874 | 874 | ||
| 875 | #[cfg(not(usart_v1))] | 875 | #[cfg(not(usart_v1))] |
diff --git a/embassy-stm32/src/usb/usb.rs b/embassy-stm32/src/usb/usb.rs index 01b158b17..ecdd1d0b8 100644 --- a/embassy-stm32/src/usb/usb.rs +++ b/embassy-stm32/src/usb/usb.rs | |||
| @@ -97,8 +97,8 @@ impl<T: Instance> interrupt::typelevel::Handler<T::Interrupt> for InterruptHandl | |||
| 97 | } | 97 | } |
| 98 | epr.set_dtog_rx(false); | 98 | epr.set_dtog_rx(false); |
| 99 | epr.set_dtog_tx(false); | 99 | epr.set_dtog_tx(false); |
| 100 | epr.set_stat_rx(Stat(0)); | 100 | epr.set_stat_rx(Stat::from_bits(0)); |
| 101 | epr.set_stat_tx(Stat(0)); | 101 | epr.set_stat_tx(Stat::from_bits(0)); |
| 102 | epr.set_ctr_rx(!epr.ctr_rx()); | 102 | epr.set_ctr_rx(!epr.ctr_rx()); |
| 103 | epr.set_ctr_tx(!epr.ctr_tx()); | 103 | epr.set_ctr_tx(!epr.ctr_tx()); |
| 104 | regs.epr(index).write_value(epr); | 104 | regs.epr(index).write_value(epr); |
| @@ -143,8 +143,8 @@ fn invariant(mut r: regs::Epr) -> regs::Epr { | |||
| 143 | r.set_ctr_tx(true); // don't clear | 143 | r.set_ctr_tx(true); // don't clear |
| 144 | r.set_dtog_rx(false); // don't toggle | 144 | r.set_dtog_rx(false); // don't toggle |
| 145 | r.set_dtog_tx(false); // don't toggle | 145 | r.set_dtog_tx(false); // don't toggle |
| 146 | r.set_stat_rx(Stat(0)); | 146 | r.set_stat_rx(Stat::from_bits(0)); |
| 147 | r.set_stat_tx(Stat(0)); | 147 | r.set_stat_tx(Stat::from_bits(0)); |
| 148 | r | 148 | r |
| 149 | } | 149 | } |
| 150 | 150 | ||
| @@ -551,7 +551,7 @@ impl<'d, T: Instance> driver::Bus for Bus<'d, T> { | |||
| 551 | true => Stat::STALL, | 551 | true => Stat::STALL, |
| 552 | }; | 552 | }; |
| 553 | let mut w = invariant(r); | 553 | let mut w = invariant(r); |
| 554 | w.set_stat_tx(Stat(r.stat_tx().0 ^ want_stat.0)); | 554 | w.set_stat_tx(Stat::from_bits(r.stat_tx().to_bits() ^ want_stat.to_bits())); |
| 555 | reg.write_value(w); | 555 | reg.write_value(w); |
| 556 | } | 556 | } |
| 557 | } | 557 | } |
| @@ -570,7 +570,7 @@ impl<'d, T: Instance> driver::Bus for Bus<'d, T> { | |||
| 570 | true => Stat::STALL, | 570 | true => Stat::STALL, |
| 571 | }; | 571 | }; |
| 572 | let mut w = invariant(r); | 572 | let mut w = invariant(r); |
| 573 | w.set_stat_rx(Stat(r.stat_rx().0 ^ want_stat.0)); | 573 | w.set_stat_rx(Stat::from_bits(r.stat_rx().to_bits() ^ want_stat.to_bits())); |
| 574 | reg.write_value(w); | 574 | reg.write_value(w); |
| 575 | } | 575 | } |
| 576 | } | 576 | } |
| @@ -606,7 +606,7 @@ impl<'d, T: Instance> driver::Bus for Bus<'d, T> { | |||
| 606 | break; | 606 | break; |
| 607 | } | 607 | } |
| 608 | let mut w = invariant(r); | 608 | let mut w = invariant(r); |
| 609 | w.set_stat_tx(Stat(r.stat_tx().0 ^ want_stat.0)); | 609 | w.set_stat_tx(Stat::from_bits(r.stat_tx().to_bits() ^ want_stat.to_bits())); |
| 610 | reg.write_value(w); | 610 | reg.write_value(w); |
| 611 | } | 611 | } |
| 612 | EP_IN_WAKERS[ep_addr.index()].wake(); | 612 | EP_IN_WAKERS[ep_addr.index()].wake(); |
| @@ -622,7 +622,7 @@ impl<'d, T: Instance> driver::Bus for Bus<'d, T> { | |||
| 622 | break; | 622 | break; |
| 623 | } | 623 | } |
| 624 | let mut w = invariant(r); | 624 | let mut w = invariant(r); |
| 625 | w.set_stat_rx(Stat(r.stat_rx().0 ^ want_stat.0)); | 625 | w.set_stat_rx(Stat::from_bits(r.stat_rx().to_bits() ^ want_stat.to_bits())); |
| 626 | reg.write_value(w); | 626 | reg.write_value(w); |
| 627 | } | 627 | } |
| 628 | EP_OUT_WAKERS[ep_addr.index()].wake(); | 628 | EP_OUT_WAKERS[ep_addr.index()].wake(); |
| @@ -763,8 +763,8 @@ impl<'d, T: Instance> driver::EndpointOut for Endpoint<'d, T, Out> { | |||
| 763 | regs.epr(index).write(|w| { | 763 | regs.epr(index).write(|w| { |
| 764 | w.set_ep_type(convert_type(self.info.ep_type)); | 764 | w.set_ep_type(convert_type(self.info.ep_type)); |
| 765 | w.set_ea(self.info.addr.index() as _); | 765 | w.set_ea(self.info.addr.index() as _); |
| 766 | w.set_stat_rx(Stat(Stat::NAK.0 ^ Stat::VALID.0)); | 766 | w.set_stat_rx(Stat::from_bits(Stat::NAK.to_bits() ^ Stat::VALID.to_bits())); |
| 767 | w.set_stat_tx(Stat(0)); | 767 | w.set_stat_tx(Stat::from_bits(0)); |
| 768 | w.set_ctr_rx(true); // don't clear | 768 | w.set_ctr_rx(true); // don't clear |
| 769 | w.set_ctr_tx(true); // don't clear | 769 | w.set_ctr_tx(true); // don't clear |
| 770 | }); | 770 | }); |
| @@ -805,8 +805,8 @@ impl<'d, T: Instance> driver::EndpointIn for Endpoint<'d, T, In> { | |||
| 805 | regs.epr(index).write(|w| { | 805 | regs.epr(index).write(|w| { |
| 806 | w.set_ep_type(convert_type(self.info.ep_type)); | 806 | w.set_ep_type(convert_type(self.info.ep_type)); |
| 807 | w.set_ea(self.info.addr.index() as _); | 807 | w.set_ea(self.info.addr.index() as _); |
| 808 | w.set_stat_tx(Stat(Stat::NAK.0 ^ Stat::VALID.0)); | 808 | w.set_stat_tx(Stat::from_bits(Stat::NAK.to_bits() ^ Stat::VALID.to_bits())); |
| 809 | w.set_stat_rx(Stat(0)); | 809 | w.set_stat_rx(Stat::from_bits(0)); |
| 810 | w.set_ctr_rx(true); // don't clear | 810 | w.set_ctr_rx(true); // don't clear |
| 811 | w.set_ctr_tx(true); // don't clear | 811 | w.set_ctr_tx(true); // don't clear |
| 812 | }); | 812 | }); |
| @@ -869,19 +869,19 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> { | |||
| 869 | let mut stat_tx = 0; | 869 | let mut stat_tx = 0; |
| 870 | if first { | 870 | if first { |
| 871 | // change NAK -> VALID | 871 | // change NAK -> VALID |
| 872 | stat_rx ^= Stat::NAK.0 ^ Stat::VALID.0; | 872 | stat_rx ^= Stat::NAK.to_bits() ^ Stat::VALID.to_bits(); |
| 873 | stat_tx ^= Stat::NAK.0 ^ Stat::STALL.0; | 873 | stat_tx ^= Stat::NAK.to_bits() ^ Stat::STALL.to_bits(); |
| 874 | } | 874 | } |
| 875 | if last { | 875 | if last { |
| 876 | // change STALL -> VALID | 876 | // change STALL -> VALID |
| 877 | stat_tx ^= Stat::STALL.0 ^ Stat::NAK.0; | 877 | stat_tx ^= Stat::STALL.to_bits() ^ Stat::NAK.to_bits(); |
| 878 | } | 878 | } |
| 879 | // Note: if this is the first AND last transfer, the above effectively | 879 | // Note: if this is the first AND last transfer, the above effectively |
| 880 | // changes stat_tx like NAK -> NAK, so noop. | 880 | // changes stat_tx like NAK -> NAK, so noop. |
| 881 | regs.epr(0).write(|w| { | 881 | regs.epr(0).write(|w| { |
| 882 | w.set_ep_type(EpType::CONTROL); | 882 | w.set_ep_type(EpType::CONTROL); |
| 883 | w.set_stat_rx(Stat(stat_rx)); | 883 | w.set_stat_rx(Stat::from_bits(stat_rx)); |
| 884 | w.set_stat_tx(Stat(stat_tx)); | 884 | w.set_stat_tx(Stat::from_bits(stat_tx)); |
| 885 | w.set_ctr_rx(true); // don't clear | 885 | w.set_ctr_rx(true); // don't clear |
| 886 | w.set_ctr_tx(true); // don't clear | 886 | w.set_ctr_tx(true); // don't clear |
| 887 | }); | 887 | }); |
| @@ -908,11 +908,11 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> { | |||
| 908 | 908 | ||
| 909 | regs.epr(0).write(|w| { | 909 | regs.epr(0).write(|w| { |
| 910 | w.set_ep_type(EpType::CONTROL); | 910 | w.set_ep_type(EpType::CONTROL); |
| 911 | w.set_stat_rx(Stat(match last { | 911 | w.set_stat_rx(Stat::from_bits(match last { |
| 912 | // If last, set STAT_RX=STALL. | 912 | // If last, set STAT_RX=STALL. |
| 913 | true => Stat::NAK.0 ^ Stat::STALL.0, | 913 | true => Stat::NAK.to_bits() ^ Stat::STALL.to_bits(), |
| 914 | // Otherwise, set STAT_RX=VALID, to allow the host to send the next packet. | 914 | // Otherwise, set STAT_RX=VALID, to allow the host to send the next packet. |
| 915 | false => Stat::NAK.0 ^ Stat::VALID.0, | 915 | false => Stat::NAK.to_bits() ^ Stat::VALID.to_bits(), |
| 916 | })); | 916 | })); |
| 917 | w.set_ctr_rx(true); // don't clear | 917 | w.set_ctr_rx(true); // don't clear |
| 918 | w.set_ctr_tx(true); // don't clear | 918 | w.set_ctr_tx(true); // don't clear |
| @@ -937,17 +937,17 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> { | |||
| 937 | let mut stat_rx = 0; | 937 | let mut stat_rx = 0; |
| 938 | if first { | 938 | if first { |
| 939 | // change NAK -> STALL | 939 | // change NAK -> STALL |
| 940 | stat_rx ^= Stat::NAK.0 ^ Stat::STALL.0; | 940 | stat_rx ^= Stat::NAK.to_bits() ^ Stat::STALL.to_bits(); |
| 941 | } | 941 | } |
| 942 | if last { | 942 | if last { |
| 943 | // change STALL -> VALID | 943 | // change STALL -> VALID |
| 944 | stat_rx ^= Stat::STALL.0 ^ Stat::VALID.0; | 944 | stat_rx ^= Stat::STALL.to_bits() ^ Stat::VALID.to_bits(); |
| 945 | } | 945 | } |
| 946 | // Note: if this is the first AND last transfer, the above effectively | 946 | // Note: if this is the first AND last transfer, the above effectively |
| 947 | // does a change of NAK -> VALID. | 947 | // does a change of NAK -> VALID. |
| 948 | regs.epr(0).write(|w| { | 948 | regs.epr(0).write(|w| { |
| 949 | w.set_ep_type(EpType::CONTROL); | 949 | w.set_ep_type(EpType::CONTROL); |
| 950 | w.set_stat_rx(Stat(stat_rx)); | 950 | w.set_stat_rx(Stat::from_bits(stat_rx)); |
| 951 | w.set_ep_kind(last); // set OUT_STATUS if last. | 951 | w.set_ep_kind(last); // set OUT_STATUS if last. |
| 952 | w.set_ctr_rx(true); // don't clear | 952 | w.set_ctr_rx(true); // don't clear |
| 953 | w.set_ctr_tx(true); // don't clear | 953 | w.set_ctr_tx(true); // don't clear |
| @@ -977,7 +977,7 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> { | |||
| 977 | let regs = T::regs(); | 977 | let regs = T::regs(); |
| 978 | regs.epr(0).write(|w| { | 978 | regs.epr(0).write(|w| { |
| 979 | w.set_ep_type(EpType::CONTROL); | 979 | w.set_ep_type(EpType::CONTROL); |
| 980 | w.set_stat_tx(Stat(Stat::NAK.0 ^ Stat::VALID.0)); | 980 | w.set_stat_tx(Stat::from_bits(Stat::NAK.to_bits() ^ Stat::VALID.to_bits())); |
| 981 | w.set_ep_kind(last); // set OUT_STATUS if last. | 981 | w.set_ep_kind(last); // set OUT_STATUS if last. |
| 982 | w.set_ctr_rx(true); // don't clear | 982 | w.set_ctr_rx(true); // don't clear |
| 983 | w.set_ctr_tx(true); // don't clear | 983 | w.set_ctr_tx(true); // don't clear |
| @@ -998,8 +998,8 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> { | |||
| 998 | let epr = regs.epr(0).read(); | 998 | let epr = regs.epr(0).read(); |
| 999 | regs.epr(0).write(|w| { | 999 | regs.epr(0).write(|w| { |
| 1000 | w.set_ep_type(EpType::CONTROL); | 1000 | w.set_ep_type(EpType::CONTROL); |
| 1001 | w.set_stat_rx(Stat(epr.stat_rx().0 ^ Stat::STALL.0)); | 1001 | w.set_stat_rx(Stat::from_bits(epr.stat_rx().to_bits() ^ Stat::STALL.to_bits())); |
| 1002 | w.set_stat_tx(Stat(epr.stat_tx().0 ^ Stat::VALID.0)); | 1002 | w.set_stat_tx(Stat::from_bits(epr.stat_tx().to_bits() ^ Stat::VALID.to_bits())); |
| 1003 | w.set_ctr_rx(true); // don't clear | 1003 | w.set_ctr_rx(true); // don't clear |
| 1004 | w.set_ctr_tx(true); // don't clear | 1004 | w.set_ctr_tx(true); // don't clear |
| 1005 | }); | 1005 | }); |
| @@ -1029,8 +1029,8 @@ impl<'d, T: Instance> driver::ControlPipe for ControlPipe<'d, T> { | |||
| 1029 | let epr = regs.epr(0).read(); | 1029 | let epr = regs.epr(0).read(); |
| 1030 | regs.epr(0).write(|w| { | 1030 | regs.epr(0).write(|w| { |
| 1031 | w.set_ep_type(EpType::CONTROL); | 1031 | w.set_ep_type(EpType::CONTROL); |
| 1032 | w.set_stat_rx(Stat(epr.stat_rx().0 ^ Stat::STALL.0)); | 1032 | w.set_stat_rx(Stat::from_bits(epr.stat_rx().to_bits() ^ Stat::STALL.to_bits())); |
| 1033 | w.set_stat_tx(Stat(epr.stat_tx().0 ^ Stat::STALL.0)); | 1033 | w.set_stat_tx(Stat::from_bits(epr.stat_tx().to_bits() ^ Stat::STALL.to_bits())); |
| 1034 | w.set_ctr_rx(true); // don't clear | 1034 | w.set_ctr_rx(true); // don't clear |
| 1035 | w.set_ctr_tx(true); // don't clear | 1035 | w.set_ctr_tx(true); // don't clear |
| 1036 | }); | 1036 | }); |
diff --git a/embassy-stm32/src/usb_otg/usb.rs b/embassy-stm32/src/usb_otg/usb.rs index 6c00c93d6..6783db28d 100644 --- a/embassy-stm32/src/usb_otg/usb.rs +++ b/embassy-stm32/src/usb_otg/usb.rs | |||
| @@ -97,7 +97,7 @@ impl<T: Instance> interrupt::typelevel::Handler<T::Interrupt> for InterruptHandl | |||
| 97 | vals::Pktstsd::SETUP_DATA_DONE => { | 97 | vals::Pktstsd::SETUP_DATA_DONE => { |
| 98 | trace!("SETUP_DATA_DONE ep={}", ep_num); | 98 | trace!("SETUP_DATA_DONE ep={}", ep_num); |
| 99 | } | 99 | } |
| 100 | x => trace!("unknown PKTSTS: {}", x.0), | 100 | x => trace!("unknown PKTSTS: {}", x.to_bits()), |
| 101 | } | 101 | } |
| 102 | } | 102 | } |
| 103 | 103 | ||
| @@ -920,7 +920,7 @@ impl<'d, T: Instance> embassy_usb_driver::Bus for Bus<'d, T> { | |||
| 920 | trace!("enumdne"); | 920 | trace!("enumdne"); |
| 921 | 921 | ||
| 922 | let speed = r.dsts().read().enumspd(); | 922 | let speed = r.dsts().read().enumspd(); |
| 923 | trace!(" speed={}", speed.0); | 923 | trace!(" speed={}", speed.to_bits()); |
| 924 | 924 | ||
| 925 | r.gusbcfg().modify(|w| { | 925 | r.gusbcfg().modify(|w| { |
| 926 | w.set_trdt(calculate_trdt(speed, T::frequency())); | 926 | w.set_trdt(calculate_trdt(speed, T::frequency())); |
diff --git a/embassy-stm32/src/wdg/mod.rs b/embassy-stm32/src/wdg/mod.rs index 5907a4e54..b03e81d6e 100644 --- a/embassy-stm32/src/wdg/mod.rs +++ b/embassy-stm32/src/wdg/mod.rs | |||
| @@ -49,7 +49,7 @@ impl<'d, T: Instance> IndependentWatchdog<'d, T> { | |||
| 49 | 49 | ||
| 50 | let wdg = T::regs(); | 50 | let wdg = T::regs(); |
| 51 | wdg.kr().write(|w| w.set_key(Key::ENABLE)); | 51 | wdg.kr().write(|w| w.set_key(Key::ENABLE)); |
| 52 | wdg.pr().write(|w| w.set_pr(Pr(pr))); | 52 | wdg.pr().write(|w| w.set_pr(Pr::from_bits(pr))); |
| 53 | wdg.rlr().write(|w| w.set_rl(rl)); | 53 | wdg.rlr().write(|w| w.set_rl(rl)); |
| 54 | 54 | ||
| 55 | trace!( | 55 | trace!( |
