diff options
| author | eZio Pan <[email protected]> | 2023-12-25 21:29:17 +0800 |
|---|---|---|
| committer | eZio Pan <[email protected]> | 2023-12-25 22:03:32 +0800 |
| commit | d90a97aa4c5977e3d071fb4ed94656e6666d965c (patch) | |
| tree | 04a904e569fb1870817aff3335958ef4e20b56e7 | |
| parent | 8b6c6c7df68088abc4a572a825a03e79c9b8694a (diff) | |
update metapac after stm32-data PR323
and refactor a few code with cargo clippy
| -rw-r--r-- | embassy-stm32/Cargo.toml | 4 | ||||
| -rw-r--r-- | embassy-stm32/src/can/bxcan.rs | 21 | ||||
| -rw-r--r-- | embassy-stm32/src/rtc/v2.rs | 8 | ||||
| -rw-r--r-- | embassy-stm32/src/rtc/v3.rs | 8 | ||||
| -rw-r--r-- | embassy-stm32/src/spi/mod.rs | 2 | ||||
| -rw-r--r-- | examples/stm32f4/src/bin/ws2812_pwm_dma.rs | 3 | ||||
| -rw-r--r-- | examples/stm32h7/src/bin/dac_dma.rs | 6 | ||||
| -rw-r--r-- | examples/stm32l4/src/bin/dac_dma.rs | 6 |
8 files changed, 28 insertions, 30 deletions
diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml index 83db7c4bf..16d1cca4c 100644 --- a/embassy-stm32/Cargo.toml +++ b/embassy-stm32/Cargo.toml | |||
| @@ -57,7 +57,7 @@ futures = { version = "0.3.17", default-features = false, features = ["async-awa | |||
| 57 | rand_core = "0.6.3" | 57 | rand_core = "0.6.3" |
| 58 | sdio-host = "0.5.0" | 58 | sdio-host = "0.5.0" |
| 59 | critical-section = "1.1" | 59 | critical-section = "1.1" |
| 60 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-2234f380f51d16d0398b8e547088b33ea623cc7c" } | 60 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-8caf2f0bda28baf4393899dc67ba57f058087f5a" } |
| 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" |
| @@ -75,7 +75,7 @@ critical-section = { version = "1.1", features = ["std"] } | |||
| 75 | [build-dependencies] | 75 | [build-dependencies] |
| 76 | proc-macro2 = "1.0.36" | 76 | proc-macro2 = "1.0.36" |
| 77 | quote = "1.0.15" | 77 | quote = "1.0.15" |
| 78 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-2234f380f51d16d0398b8e547088b33ea623cc7c", default-features = false, features = ["metadata"]} | 78 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-8caf2f0bda28baf4393899dc67ba57f058087f5a", default-features = false, features = ["metadata"]} |
| 79 | 79 | ||
| 80 | 80 | ||
| 81 | [features] | 81 | [features] |
diff --git a/embassy-stm32/src/can/bxcan.rs b/embassy-stm32/src/can/bxcan.rs index 3c663b452..cc87b2565 100644 --- a/embassy-stm32/src/can/bxcan.rs +++ b/embassy-stm32/src/can/bxcan.rs | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | use core::convert::AsMut; | ||
| 1 | use core::future::poll_fn; | 2 | use core::future::poll_fn; |
| 2 | use core::marker::PhantomData; | 3 | use core::marker::PhantomData; |
| 3 | use core::ops::{Deref, DerefMut}; | 4 | use core::ops::{Deref, DerefMut}; |
| @@ -10,7 +11,7 @@ use futures::FutureExt; | |||
| 10 | 11 | ||
| 11 | use crate::gpio::sealed::AFType; | 12 | use crate::gpio::sealed::AFType; |
| 12 | use crate::interrupt::typelevel::Interrupt; | 13 | use crate::interrupt::typelevel::Interrupt; |
| 13 | use crate::pac::can::vals::{Lec, RirIde}; | 14 | use crate::pac::can::vals::{Ide, Lec}; |
| 14 | use crate::rcc::RccPeripheral; | 15 | use crate::rcc::RccPeripheral; |
| 15 | use crate::time::Hertz; | 16 | use crate::time::Hertz; |
| 16 | use crate::{interrupt, peripherals, Peripheral}; | 17 | use crate::{interrupt, peripherals, Peripheral}; |
| @@ -148,15 +149,11 @@ impl<'d, T: Instance> Can<'d, T> { | |||
| 148 | T::enable_and_reset(); | 149 | T::enable_and_reset(); |
| 149 | 150 | ||
| 150 | { | 151 | { |
| 151 | use crate::pac::can::vals::{Errie, Fmpie, Tmeie}; | ||
| 152 | |||
| 153 | T::regs().ier().write(|w| { | 152 | T::regs().ier().write(|w| { |
| 154 | // TODO: fix metapac | 153 | w.set_errie(true); |
| 155 | 154 | w.set_fmpie(0, true); | |
| 156 | w.set_errie(Errie::from_bits(1)); | 155 | w.set_fmpie(1, true); |
| 157 | w.set_fmpie(0, Fmpie::from_bits(1)); | 156 | w.set_tmeie(true); |
| 158 | w.set_fmpie(1, Fmpie::from_bits(1)); | ||
| 159 | w.set_tmeie(Tmeie::from_bits(1)); | ||
| 160 | }); | 157 | }); |
| 161 | 158 | ||
| 162 | T::regs().mcr().write(|w| { | 159 | T::regs().mcr().write(|w| { |
| @@ -276,7 +273,7 @@ impl<'d, T: Instance> Can<'d, T> { | |||
| 276 | } | 273 | } |
| 277 | 274 | ||
| 278 | let rir = fifo.rir().read(); | 275 | let rir = fifo.rir().read(); |
| 279 | let id = if rir.ide() == RirIde::STANDARD { | 276 | let id = if rir.ide() == Ide::STANDARD { |
| 280 | Id::from(StandardId::new_unchecked(rir.stid())) | 277 | Id::from(StandardId::new_unchecked(rir.stid())) |
| 281 | } else { | 278 | } else { |
| 282 | let stid = (rir.stid() & 0x7FF) as u32; | 279 | let stid = (rir.stid() & 0x7FF) as u32; |
| @@ -403,9 +400,11 @@ impl<'d, T: Instance> Can<'d, T> { | |||
| 403 | let (tx, rx0, rx1) = self.can.split_by_ref(); | 400 | let (tx, rx0, rx1) = self.can.split_by_ref(); |
| 404 | (CanTx { tx }, CanRx { rx0, rx1 }) | 401 | (CanTx { tx }, CanRx { rx0, rx1 }) |
| 405 | } | 402 | } |
| 403 | } | ||
| 406 | 404 | ||
| 405 | impl<'d, T: Instance> AsMut<bxcan::Can<BxcanInstance<'d, T>>> for Can<'d, T> { | ||
| 407 | /// Get mutable access to the lower-level driver from the `bxcan` crate. | 406 | /// Get mutable access to the lower-level driver from the `bxcan` crate. |
| 408 | pub fn as_mut(&mut self) -> &mut bxcan::Can<BxcanInstance<'d, T>> { | 407 | fn as_mut(&mut self) -> &mut bxcan::Can<BxcanInstance<'d, T>> { |
| 409 | &mut self.can | 408 | &mut self.can |
| 410 | } | 409 | } |
| 411 | } | 410 | } |
diff --git a/embassy-stm32/src/rtc/v2.rs b/embassy-stm32/src/rtc/v2.rs index 91f08fae4..1eda097a7 100644 --- a/embassy-stm32/src/rtc/v2.rs +++ b/embassy-stm32/src/rtc/v2.rs | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | use stm32_metapac::rtc::vals::{Init, Osel, Pol}; | 1 | use stm32_metapac::rtc::vals::{Osel, Pol}; |
| 2 | 2 | ||
| 3 | use super::sealed; | 3 | use super::sealed; |
| 4 | use crate::pac::rtc::Rtc; | 4 | use crate::pac::rtc::Rtc; |
| @@ -49,7 +49,7 @@ impl super::Rtc { | |||
| 49 | clock_drift = RTC_CALR_MAX_PPM; | 49 | clock_drift = RTC_CALR_MAX_PPM; |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | clock_drift = clock_drift / RTC_CALR_RESOLUTION_PPM; | 52 | clock_drift /= RTC_CALR_RESOLUTION_PPM; |
| 53 | 53 | ||
| 54 | self.write(false, |rtc| { | 54 | self.write(false, |rtc| { |
| 55 | rtc.calr().write(|w| { | 55 | rtc.calr().write(|w| { |
| @@ -107,7 +107,7 @@ impl super::Rtc { | |||
| 107 | // true if initf bit indicates RTC peripheral is in init mode | 107 | // true if initf bit indicates RTC peripheral is in init mode |
| 108 | if init_mode && !r.isr().read().initf() { | 108 | if init_mode && !r.isr().read().initf() { |
| 109 | // to update calendar date/time, time format, and prescaler configuration, RTC must be in init mode | 109 | // to update calendar date/time, time format, and prescaler configuration, RTC must be in init mode |
| 110 | r.isr().modify(|w| w.set_init(Init::INITMODE)); | 110 | r.isr().modify(|w| w.set_init(true)); |
| 111 | // wait till init state entered | 111 | // wait till init state entered |
| 112 | // ~2 RTCCLK cycles | 112 | // ~2 RTCCLK cycles |
| 113 | while !r.isr().read().initf() {} | 113 | while !r.isr().read().initf() {} |
| @@ -116,7 +116,7 @@ impl super::Rtc { | |||
| 116 | let result = f(&r); | 116 | let result = f(&r); |
| 117 | 117 | ||
| 118 | if init_mode { | 118 | if init_mode { |
| 119 | r.isr().modify(|w| w.set_init(Init::FREERUNNINGMODE)); // Exits init mode | 119 | r.isr().modify(|w| w.set_init(false)); // Exits init mode |
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | // Re-enable write protection. | 122 | // Re-enable write protection. |
diff --git a/embassy-stm32/src/rtc/v3.rs b/embassy-stm32/src/rtc/v3.rs index d2d0d9309..902776b0a 100644 --- a/embassy-stm32/src/rtc/v3.rs +++ b/embassy-stm32/src/rtc/v3.rs | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | use stm32_metapac::rtc::vals::{Calp, Calw16, Calw8, Fmt, Init, Key, Osel, Pol, TampalrmPu, TampalrmType}; | 1 | use stm32_metapac::rtc::vals::{Calp, Calw16, Calw8, Fmt, Key, Osel, Pol, TampalrmType}; |
| 2 | 2 | ||
| 3 | use super::{sealed, RtcCalibrationCyclePeriod}; | 3 | use super::{sealed, RtcCalibrationCyclePeriod}; |
| 4 | use crate::pac::rtc::Rtc; | 4 | use crate::pac::rtc::Rtc; |
| @@ -26,7 +26,7 @@ impl super::Rtc { | |||
| 26 | rtc.cr().modify(|w| { | 26 | rtc.cr().modify(|w| { |
| 27 | w.set_out2en(false); | 27 | w.set_out2en(false); |
| 28 | w.set_tampalrm_type(TampalrmType::PUSHPULL); | 28 | w.set_tampalrm_type(TampalrmType::PUSHPULL); |
| 29 | w.set_tampalrm_pu(TampalrmPu::NOPULLUP); | 29 | w.set_tampalrm_pu(false); |
| 30 | }); | 30 | }); |
| 31 | }); | 31 | }); |
| 32 | } | 32 | } |
| @@ -106,7 +106,7 @@ impl super::Rtc { | |||
| 106 | r.wpr().write(|w| w.set_key(Key::DEACTIVATE2)); | 106 | r.wpr().write(|w| w.set_key(Key::DEACTIVATE2)); |
| 107 | 107 | ||
| 108 | if init_mode && !r.icsr().read().initf() { | 108 | if init_mode && !r.icsr().read().initf() { |
| 109 | r.icsr().modify(|w| w.set_init(Init::INITMODE)); | 109 | r.icsr().modify(|w| w.set_init(true)); |
| 110 | // wait till init state entered | 110 | // wait till init state entered |
| 111 | // ~2 RTCCLK cycles | 111 | // ~2 RTCCLK cycles |
| 112 | while !r.icsr().read().initf() {} | 112 | while !r.icsr().read().initf() {} |
| @@ -115,7 +115,7 @@ impl super::Rtc { | |||
| 115 | let result = f(&r); | 115 | let result = f(&r); |
| 116 | 116 | ||
| 117 | if init_mode { | 117 | if init_mode { |
| 118 | r.icsr().modify(|w| w.set_init(Init::FREERUNNINGMODE)); // Exits init mode | 118 | r.icsr().modify(|w| w.set_init(false)); // Exits init mode |
| 119 | } | 119 | } |
| 120 | 120 | ||
| 121 | // Re-enable write protection. | 121 | // Re-enable write protection. |
diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs index 674a5d316..23f027e70 100644 --- a/embassy-stm32/src/spi/mod.rs +++ b/embassy-stm32/src/spi/mod.rs | |||
| @@ -311,7 +311,7 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> { | |||
| 311 | w.set_ssom(vals::Ssom::ASSERTED); | 311 | w.set_ssom(vals::Ssom::ASSERTED); |
| 312 | w.set_midi(0); | 312 | w.set_midi(0); |
| 313 | w.set_mssi(0); | 313 | w.set_mssi(0); |
| 314 | w.set_afcntr(vals::Afcntr::CONTROLLED); | 314 | w.set_afcntr(true); |
| 315 | w.set_ssiop(vals::Ssiop::ACTIVEHIGH); | 315 | w.set_ssiop(vals::Ssiop::ACTIVEHIGH); |
| 316 | }); | 316 | }); |
| 317 | T::REGS.cfg1().modify(|w| { | 317 | T::REGS.cfg1().modify(|w| { |
diff --git a/examples/stm32f4/src/bin/ws2812_pwm_dma.rs b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs index cdce36f2e..4458b643f 100644 --- a/examples/stm32f4/src/bin/ws2812_pwm_dma.rs +++ b/examples/stm32f4/src/bin/ws2812_pwm_dma.rs | |||
| @@ -21,7 +21,6 @@ | |||
| 21 | use embassy_executor::Spawner; | 21 | use embassy_executor::Spawner; |
| 22 | use embassy_stm32::gpio::OutputType; | 22 | use embassy_stm32::gpio::OutputType; |
| 23 | use embassy_stm32::pac; | 23 | use embassy_stm32::pac; |
| 24 | use embassy_stm32::pac::timer::vals::Ocpe; | ||
| 25 | use embassy_stm32::time::khz; | 24 | use embassy_stm32::time::khz; |
| 26 | use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm}; | 25 | use embassy_stm32::timer::simple_pwm::{PwmPin, SimplePwm}; |
| 27 | use embassy_stm32::timer::{Channel, CountingMode}; | 26 | use embassy_stm32::timer::{Channel, CountingMode}; |
| @@ -94,7 +93,7 @@ async fn main(_spawner: Spawner) { | |||
| 94 | // keep output waveform integrity | 93 | // keep output waveform integrity |
| 95 | pac::TIM3 | 94 | pac::TIM3 |
| 96 | .ccmr_output(pwm_channel.index()) | 95 | .ccmr_output(pwm_channel.index()) |
| 97 | .modify(|v| v.set_ocpe(0, Ocpe::ENABLED)); | 96 | .modify(|v| v.set_ocpe(0, true)); |
| 98 | 97 | ||
| 99 | // make sure PWM output keep low on first start | 98 | // make sure PWM output keep low on first start |
| 100 | ws2812_pwm.set_duty(pwm_channel, 0); | 99 | ws2812_pwm.set_duty(pwm_channel, 0); |
diff --git a/examples/stm32h7/src/bin/dac_dma.rs b/examples/stm32h7/src/bin/dac_dma.rs index 1481dd967..8e5c41a43 100644 --- a/examples/stm32h7/src/bin/dac_dma.rs +++ b/examples/stm32h7/src/bin/dac_dma.rs | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::dac::{DacCh1, DacCh2, ValueArray}; | 6 | use embassy_stm32::dac::{DacCh1, DacCh2, ValueArray}; |
| 7 | use embassy_stm32::pac::timer::vals::{Mms, Opm}; | 7 | use embassy_stm32::pac::timer::vals::Mms; |
| 8 | use embassy_stm32::peripherals::{DAC1, DMA1_CH3, DMA1_CH4, TIM6, TIM7}; | 8 | use embassy_stm32::peripherals::{DAC1, DMA1_CH3, DMA1_CH4, TIM6, TIM7}; |
| 9 | use embassy_stm32::rcc::low_level::RccPeripheral; | 9 | use embassy_stm32::rcc::low_level::RccPeripheral; |
| 10 | use embassy_stm32::time::Hertz; | 10 | use embassy_stm32::time::Hertz; |
| @@ -78,7 +78,7 @@ async fn dac_task1(mut dac: DacCh1<'static, DAC1, DMA1_CH3>) { | |||
| 78 | TIM6::regs().arr().modify(|w| w.set_arr(reload as u16 - 1)); | 78 | TIM6::regs().arr().modify(|w| w.set_arr(reload as u16 - 1)); |
| 79 | TIM6::regs().cr2().modify(|w| w.set_mms(Mms::UPDATE)); | 79 | TIM6::regs().cr2().modify(|w| w.set_mms(Mms::UPDATE)); |
| 80 | TIM6::regs().cr1().modify(|w| { | 80 | TIM6::regs().cr1().modify(|w| { |
| 81 | w.set_opm(Opm::DISABLED); | 81 | w.set_opm(false); |
| 82 | w.set_cen(true); | 82 | w.set_cen(true); |
| 83 | }); | 83 | }); |
| 84 | 84 | ||
| @@ -115,7 +115,7 @@ async fn dac_task2(mut dac: DacCh2<'static, DAC1, DMA1_CH4>) { | |||
| 115 | TIM7::regs().arr().modify(|w| w.set_arr(reload as u16 - 1)); | 115 | TIM7::regs().arr().modify(|w| w.set_arr(reload as u16 - 1)); |
| 116 | TIM7::regs().cr2().modify(|w| w.set_mms(Mms::UPDATE)); | 116 | TIM7::regs().cr2().modify(|w| w.set_mms(Mms::UPDATE)); |
| 117 | TIM7::regs().cr1().modify(|w| { | 117 | TIM7::regs().cr1().modify(|w| { |
| 118 | w.set_opm(Opm::DISABLED); | 118 | w.set_opm(false); |
| 119 | w.set_cen(true); | 119 | w.set_cen(true); |
| 120 | }); | 120 | }); |
| 121 | 121 | ||
diff --git a/examples/stm32l4/src/bin/dac_dma.rs b/examples/stm32l4/src/bin/dac_dma.rs index 64c541caa..8e5098557 100644 --- a/examples/stm32l4/src/bin/dac_dma.rs +++ b/examples/stm32l4/src/bin/dac_dma.rs | |||
| @@ -4,7 +4,7 @@ | |||
| 4 | use defmt::*; | 4 | use defmt::*; |
| 5 | use embassy_executor::Spawner; | 5 | use embassy_executor::Spawner; |
| 6 | use embassy_stm32::dac::{DacCh1, DacCh2, ValueArray}; | 6 | use embassy_stm32::dac::{DacCh1, DacCh2, ValueArray}; |
| 7 | use embassy_stm32::pac::timer::vals::{Mms, Opm}; | 7 | use embassy_stm32::pac::timer::vals::Mms; |
| 8 | use embassy_stm32::peripherals::{DAC1, DMA1_CH3, DMA1_CH4, TIM6, TIM7}; | 8 | use embassy_stm32::peripherals::{DAC1, DMA1_CH3, DMA1_CH4, TIM6, TIM7}; |
| 9 | use embassy_stm32::rcc::low_level::RccPeripheral; | 9 | use embassy_stm32::rcc::low_level::RccPeripheral; |
| 10 | use embassy_stm32::time::Hertz; | 10 | use embassy_stm32::time::Hertz; |
| @@ -49,7 +49,7 @@ async fn dac_task1(mut dac: DacCh1<'static, DAC1, DMA1_CH3>) { | |||
| 49 | TIM6::regs().arr().modify(|w| w.set_arr(reload as u16 - 1)); | 49 | TIM6::regs().arr().modify(|w| w.set_arr(reload as u16 - 1)); |
| 50 | TIM6::regs().cr2().modify(|w| w.set_mms(Mms::UPDATE)); | 50 | TIM6::regs().cr2().modify(|w| w.set_mms(Mms::UPDATE)); |
| 51 | TIM6::regs().cr1().modify(|w| { | 51 | TIM6::regs().cr1().modify(|w| { |
| 52 | w.set_opm(Opm::DISABLED); | 52 | w.set_opm(false); |
| 53 | w.set_cen(true); | 53 | w.set_cen(true); |
| 54 | }); | 54 | }); |
| 55 | 55 | ||
| @@ -86,7 +86,7 @@ async fn dac_task2(mut dac: DacCh2<'static, DAC1, DMA1_CH4>) { | |||
| 86 | TIM7::regs().arr().modify(|w| w.set_arr(reload as u16 - 1)); | 86 | TIM7::regs().arr().modify(|w| w.set_arr(reload as u16 - 1)); |
| 87 | TIM7::regs().cr2().modify(|w| w.set_mms(Mms::UPDATE)); | 87 | TIM7::regs().cr2().modify(|w| w.set_mms(Mms::UPDATE)); |
| 88 | TIM7::regs().cr1().modify(|w| { | 88 | TIM7::regs().cr1().modify(|w| { |
| 89 | w.set_opm(Opm::DISABLED); | 89 | w.set_opm(false); |
| 90 | w.set_cen(true); | 90 | w.set_cen(true); |
| 91 | }); | 91 | }); |
| 92 | 92 | ||
