diff options
| author | Dario Nieuwenhuis <[email protected]> | 2023-10-12 01:16:42 +0200 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2023-10-12 02:07:26 +0200 |
| commit | 70a91945fca97229518f4f8f011233650448771d (patch) | |
| tree | 87535352950f8353972037c441902066dd19d710 | |
| parent | 32b89eeba18d2d0a9c3705212768d4ade3f4948d (diff) | |
stm32: remove atomic-polyfill.
| -rw-r--r-- | embassy-stm32/Cargo.toml | 1 | ||||
| -rw-r--r-- | embassy-stm32/build.rs | 34 | ||||
| -rw-r--r-- | embassy-stm32/src/dma/bdma.rs | 18 | ||||
| -rw-r--r-- | embassy-stm32/src/lib.rs | 4 | ||||
| -rw-r--r-- | embassy-stm32/src/low_power.rs | 2 | ||||
| -rw-r--r-- | embassy-stm32/src/rcc/mod.rs | 16 | ||||
| -rw-r--r-- | embassy-stm32/src/time_driver.rs | 22 | ||||
| -rw-r--r-- | embassy-time/Cargo.toml | 1 |
8 files changed, 69 insertions, 29 deletions
diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml index 33583d22b..a2c5da2bc 100644 --- a/embassy-stm32/Cargo.toml +++ b/embassy-stm32/Cargo.toml | |||
| @@ -58,7 +58,6 @@ rand_core = "0.6.3" | |||
| 58 | sdio-host = "0.5.0" | 58 | sdio-host = "0.5.0" |
| 59 | embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "a4f293d3a6f72158385f79c98634cb8a14d0d2fc", optional = true } | 59 | embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "a4f293d3a6f72158385f79c98634cb8a14d0d2fc", optional = true } |
| 60 | critical-section = "1.1" | 60 | critical-section = "1.1" |
| 61 | atomic-polyfill = "1.0.1" | ||
| 62 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-6bfa5a0dcec6a9bd42cea94ba11eeae1a17a7f2c" } | 61 | stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-6bfa5a0dcec6a9bd42cea94ba11eeae1a17a7f2c" } |
| 63 | vcell = "0.1.3" | 62 | vcell = "0.1.3" |
| 64 | bxcan = "0.7.0" | 63 | bxcan = "0.7.0" |
diff --git a/embassy-stm32/build.rs b/embassy-stm32/build.rs index 810da37e9..fa10b7f77 100644 --- a/embassy-stm32/build.rs +++ b/embassy-stm32/build.rs | |||
| @@ -8,6 +8,32 @@ use quote::{format_ident, quote}; | |||
| 8 | use stm32_metapac::metadata::{MemoryRegionKind, METADATA}; | 8 | use stm32_metapac::metadata::{MemoryRegionKind, METADATA}; |
| 9 | 9 | ||
| 10 | fn main() { | 10 | fn main() { |
| 11 | let target = env::var("TARGET").unwrap(); | ||
| 12 | |||
| 13 | if target.starts_with("thumbv6m-") { | ||
| 14 | println!("cargo:rustc-cfg=cortex_m"); | ||
| 15 | println!("cargo:rustc-cfg=armv6m"); | ||
| 16 | } else if target.starts_with("thumbv7m-") { | ||
| 17 | println!("cargo:rustc-cfg=cortex_m"); | ||
| 18 | println!("cargo:rustc-cfg=armv7m"); | ||
| 19 | } else if target.starts_with("thumbv7em-") { | ||
| 20 | println!("cargo:rustc-cfg=cortex_m"); | ||
| 21 | println!("cargo:rustc-cfg=armv7m"); | ||
| 22 | println!("cargo:rustc-cfg=armv7em"); // (not currently used) | ||
| 23 | } else if target.starts_with("thumbv8m.base") { | ||
| 24 | println!("cargo:rustc-cfg=cortex_m"); | ||
| 25 | println!("cargo:rustc-cfg=armv8m"); | ||
| 26 | println!("cargo:rustc-cfg=armv8m_base"); | ||
| 27 | } else if target.starts_with("thumbv8m.main") { | ||
| 28 | println!("cargo:rustc-cfg=cortex_m"); | ||
| 29 | println!("cargo:rustc-cfg=armv8m"); | ||
| 30 | println!("cargo:rustc-cfg=armv8m_main"); | ||
| 31 | } | ||
| 32 | |||
| 33 | if target.ends_with("-eabihf") { | ||
| 34 | println!("cargo:rustc-cfg=has_fpu"); | ||
| 35 | } | ||
| 36 | |||
| 11 | let chip_name = match env::vars() | 37 | let chip_name = match env::vars() |
| 12 | .map(|(a, _)| a) | 38 | .map(|(a, _)| a) |
| 13 | .filter(|x| x.starts_with("CARGO_FEATURE_STM32")) | 39 | .filter(|x| x.starts_with("CARGO_FEATURE_STM32")) |
| @@ -434,20 +460,20 @@ fn main() { | |||
| 434 | unsafe { crate::rcc::get_freqs().#clk } | 460 | unsafe { crate::rcc::get_freqs().#clk } |
| 435 | } | 461 | } |
| 436 | fn enable() { | 462 | fn enable() { |
| 437 | critical_section::with(|_| { | 463 | critical_section::with(|_cs| { |
| 438 | #before_enable | 464 | #before_enable |
| 439 | #[cfg(feature = "low-power")] | 465 | #[cfg(feature = "low-power")] |
| 440 | crate::rcc::clock_refcount_add(); | 466 | crate::rcc::clock_refcount_add(_cs); |
| 441 | crate::pac::RCC.#en_reg().modify(|w| w.#set_en_field(true)); | 467 | crate::pac::RCC.#en_reg().modify(|w| w.#set_en_field(true)); |
| 442 | #after_enable | 468 | #after_enable |
| 443 | }) | 469 | }) |
| 444 | } | 470 | } |
| 445 | fn disable() { | 471 | fn disable() { |
| 446 | critical_section::with(|_| { | 472 | critical_section::with(|_cs| { |
| 447 | #before_disable | 473 | #before_disable |
| 448 | crate::pac::RCC.#en_reg().modify(|w| w.#set_en_field(false)); | 474 | crate::pac::RCC.#en_reg().modify(|w| w.#set_en_field(false)); |
| 449 | #[cfg(feature = "low-power")] | 475 | #[cfg(feature = "low-power")] |
| 450 | crate::rcc::clock_refcount_sub(); | 476 | crate::rcc::clock_refcount_sub(_cs); |
| 451 | }) | 477 | }) |
| 452 | } | 478 | } |
| 453 | fn reset() { | 479 | fn reset() { |
diff --git a/embassy-stm32/src/dma/bdma.rs b/embassy-stm32/src/dma/bdma.rs index 20ff29bef..62eb65b1c 100644 --- a/embassy-stm32/src/dma/bdma.rs +++ b/embassy-stm32/src/dma/bdma.rs | |||
| @@ -2,10 +2,9 @@ | |||
| 2 | 2 | ||
| 3 | use core::future::Future; | 3 | use core::future::Future; |
| 4 | use core::pin::Pin; | 4 | use core::pin::Pin; |
| 5 | use core::sync::atomic::{fence, Ordering}; | 5 | use core::sync::atomic::{fence, AtomicUsize, Ordering}; |
| 6 | use core::task::{Context, Poll, Waker}; | 6 | use core::task::{Context, Poll, Waker}; |
| 7 | 7 | ||
| 8 | use atomic_polyfill::AtomicUsize; | ||
| 9 | use embassy_hal_internal::{into_ref, Peripheral, PeripheralRef}; | 8 | use embassy_hal_internal::{into_ref, Peripheral, PeripheralRef}; |
| 10 | use embassy_sync::waitqueue::AtomicWaker; | 9 | use embassy_sync::waitqueue::AtomicWaker; |
| 11 | 10 | ||
| @@ -127,7 +126,13 @@ pub(crate) unsafe fn on_irq_inner(dma: pac::bdma::Dma, channel_num: usize, index | |||
| 127 | } else if isr.tcif(channel_num) && cr.read().tcie() { | 126 | } else if isr.tcif(channel_num) && cr.read().tcie() { |
| 128 | // Acknowledge transfer complete interrupt | 127 | // Acknowledge transfer complete interrupt |
| 129 | dma.ifcr().write(|w| w.set_tcif(channel_num, true)); | 128 | dma.ifcr().write(|w| w.set_tcif(channel_num, true)); |
| 129 | #[cfg(not(armv6m))] | ||
| 130 | STATE.complete_count[index].fetch_add(1, Ordering::Release); | 130 | STATE.complete_count[index].fetch_add(1, Ordering::Release); |
| 131 | #[cfg(armv6m)] | ||
| 132 | critical_section::with(|_| { | ||
| 133 | let x = STATE.complete_count[index].load(Ordering::Relaxed); | ||
| 134 | STATE.complete_count[index].store(x + 1, Ordering::Release); | ||
| 135 | }) | ||
| 131 | } else { | 136 | } else { |
| 132 | return; | 137 | return; |
| 133 | } | 138 | } |
| @@ -391,7 +396,14 @@ impl<'a, C: Channel> DmaCtrl for DmaCtrlImpl<'a, C> { | |||
| 391 | } | 396 | } |
| 392 | 397 | ||
| 393 | fn reset_complete_count(&mut self) -> usize { | 398 | fn reset_complete_count(&mut self) -> usize { |
| 394 | STATE.complete_count[self.0.index()].swap(0, Ordering::AcqRel) | 399 | #[cfg(not(armv6m))] |
| 400 | return STATE.complete_count[self.0.index()].swap(0, Ordering::AcqRel); | ||
| 401 | #[cfg(armv6m)] | ||
| 402 | return critical_section::with(|_| { | ||
| 403 | let x = STATE.complete_count[self.0.index()].load(Ordering::Acquire); | ||
| 404 | STATE.complete_count[self.0.index()].store(0, Ordering::Release); | ||
| 405 | x | ||
| 406 | }); | ||
| 395 | } | 407 | } |
| 396 | 408 | ||
| 397 | fn set_waker(&mut self, waker: &Waker) { | 409 | fn set_waker(&mut self, waker: &Waker) { |
diff --git a/embassy-stm32/src/lib.rs b/embassy-stm32/src/lib.rs index e883678b5..37c94f827 100644 --- a/embassy-stm32/src/lib.rs +++ b/embassy-stm32/src/lib.rs | |||
| @@ -225,7 +225,9 @@ pub fn init(config: Config) -> Peripherals { | |||
| 225 | 225 | ||
| 226 | #[cfg(feature = "low-power")] | 226 | #[cfg(feature = "low-power")] |
| 227 | while !crate::rcc::low_power_ready() { | 227 | while !crate::rcc::low_power_ready() { |
| 228 | crate::rcc::clock_refcount_sub(); | 228 | critical_section::with(|cs| { |
| 229 | crate::rcc::clock_refcount_sub(cs); | ||
| 230 | }); | ||
| 229 | } | 231 | } |
| 230 | } | 232 | } |
| 231 | 233 | ||
diff --git a/embassy-stm32/src/low_power.rs b/embassy-stm32/src/low_power.rs index bb714b8ca..861a59d7b 100644 --- a/embassy-stm32/src/low_power.rs +++ b/embassy-stm32/src/low_power.rs | |||
| @@ -1,7 +1,7 @@ | |||
| 1 | use core::arch::asm; | 1 | use core::arch::asm; |
| 2 | use core::marker::PhantomData; | 2 | use core::marker::PhantomData; |
| 3 | use core::sync::atomic::{compiler_fence, Ordering}; | ||
| 3 | 4 | ||
| 4 | use atomic_polyfill::{compiler_fence, Ordering}; | ||
| 5 | use cortex_m::peripheral::SCB; | 5 | use cortex_m::peripheral::SCB; |
| 6 | use embassy_executor::*; | 6 | use embassy_executor::*; |
| 7 | 7 | ||
diff --git a/embassy-stm32/src/rcc/mod.rs b/embassy-stm32/src/rcc/mod.rs index a9e53d424..abb53fd10 100644 --- a/embassy-stm32/src/rcc/mod.rs +++ b/embassy-stm32/src/rcc/mod.rs | |||
| @@ -27,9 +27,10 @@ pub use mco::*; | |||
| 27 | #[cfg_attr(rcc_wba, path = "wba.rs")] | 27 | #[cfg_attr(rcc_wba, path = "wba.rs")] |
| 28 | #[cfg_attr(any(rcc_wl5, rcc_wle), path = "wl.rs")] | 28 | #[cfg_attr(any(rcc_wl5, rcc_wle), path = "wl.rs")] |
| 29 | mod _version; | 29 | mod _version; |
| 30 | pub use _version::*; | ||
| 31 | #[cfg(feature = "low-power")] | 30 | #[cfg(feature = "low-power")] |
| 32 | use atomic_polyfill::{AtomicU32, Ordering}; | 31 | use core::sync::atomic::{AtomicU32, Ordering}; |
| 32 | |||
| 33 | pub use _version::*; | ||
| 33 | 34 | ||
| 34 | // Model Clock Configuration | 35 | // Model Clock Configuration |
| 35 | // | 36 | // |
| @@ -145,14 +146,17 @@ pub fn low_power_ready() -> bool { | |||
| 145 | } | 146 | } |
| 146 | 147 | ||
| 147 | #[cfg(feature = "low-power")] | 148 | #[cfg(feature = "low-power")] |
| 148 | pub(crate) fn clock_refcount_add() { | 149 | pub(crate) fn clock_refcount_add(_cs: critical_section::CriticalSection) { |
| 149 | // We don't check for overflow because constructing more than u32 peripherals is unlikely | 150 | // We don't check for overflow because constructing more than u32 peripherals is unlikely |
| 150 | CLOCK_REFCOUNT.fetch_add(1, Ordering::Relaxed); | 151 | let n = CLOCK_REFCOUNT.load(Ordering::Relaxed); |
| 152 | CLOCK_REFCOUNT.store(n + 1, Ordering::Relaxed); | ||
| 151 | } | 153 | } |
| 152 | 154 | ||
| 153 | #[cfg(feature = "low-power")] | 155 | #[cfg(feature = "low-power")] |
| 154 | pub(crate) fn clock_refcount_sub() { | 156 | pub(crate) fn clock_refcount_sub(_cs: critical_section::CriticalSection) { |
| 155 | assert!(CLOCK_REFCOUNT.fetch_sub(1, Ordering::Relaxed) != 0); | 157 | let n = CLOCK_REFCOUNT.load(Ordering::Relaxed); |
| 158 | assert!(n != 0); | ||
| 159 | CLOCK_REFCOUNT.store(n - 1, Ordering::Relaxed); | ||
| 156 | } | 160 | } |
| 157 | 161 | ||
| 158 | /// Frozen clock frequencies | 162 | /// Frozen clock frequencies |
diff --git a/embassy-stm32/src/time_driver.rs b/embassy-stm32/src/time_driver.rs index 917502412..e88198e6f 100644 --- a/embassy-stm32/src/time_driver.rs +++ b/embassy-stm32/src/time_driver.rs | |||
| @@ -1,9 +1,8 @@ | |||
| 1 | use core::cell::Cell; | 1 | use core::cell::Cell; |
| 2 | use core::convert::TryInto; | 2 | use core::convert::TryInto; |
| 3 | use core::sync::atomic::{compiler_fence, Ordering}; | 3 | use core::sync::atomic::{compiler_fence, AtomicU32, AtomicU8, Ordering}; |
| 4 | use core::{mem, ptr}; | 4 | use core::{mem, ptr}; |
| 5 | 5 | ||
| 6 | use atomic_polyfill::{AtomicU32, AtomicU8}; | ||
| 7 | use critical_section::CriticalSection; | 6 | use critical_section::CriticalSection; |
| 8 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; | 7 | use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; |
| 9 | use embassy_sync::blocking_mutex::Mutex; | 8 | use embassy_sync::blocking_mutex::Mutex; |
| @@ -229,7 +228,9 @@ impl RtcDriver { | |||
| 229 | fn next_period(&self) { | 228 | fn next_period(&self) { |
| 230 | let r = T::regs_gp16(); | 229 | let r = T::regs_gp16(); |
| 231 | 230 | ||
| 232 | let period = self.period.fetch_add(1, Ordering::Relaxed) + 1; | 231 | // We only modify the period from the timer interrupt, so we know this can't race. |
| 232 | let period = self.period.load(Ordering::Relaxed) + 1; | ||
| 233 | self.period.store(period, Ordering::Relaxed); | ||
| 233 | let t = (period as u64) << 15; | 234 | let t = (period as u64) << 15; |
| 234 | 235 | ||
| 235 | critical_section::with(move |cs| { | 236 | critical_section::with(move |cs| { |
| @@ -403,18 +404,15 @@ impl Driver for RtcDriver { | |||
| 403 | } | 404 | } |
| 404 | 405 | ||
| 405 | unsafe fn allocate_alarm(&self) -> Option<AlarmHandle> { | 406 | unsafe fn allocate_alarm(&self) -> Option<AlarmHandle> { |
| 406 | let id = self.alarm_count.fetch_update(Ordering::AcqRel, Ordering::Acquire, |x| { | 407 | critical_section::with(|_| { |
| 407 | if x < ALARM_COUNT as u8 { | 408 | let id = self.alarm_count.load(Ordering::Relaxed); |
| 408 | Some(x + 1) | 409 | if id < ALARM_COUNT as u8 { |
| 410 | self.alarm_count.store(id + 1, Ordering::Relaxed); | ||
| 411 | Some(AlarmHandle::new(id)) | ||
| 409 | } else { | 412 | } else { |
| 410 | None | 413 | None |
| 411 | } | 414 | } |
| 412 | }); | 415 | }) |
| 413 | |||
| 414 | match id { | ||
| 415 | Ok(id) => Some(AlarmHandle::new(id)), | ||
| 416 | Err(_) => None, | ||
| 417 | } | ||
| 418 | } | 416 | } |
| 419 | 417 | ||
| 420 | fn set_alarm_callback(&self, alarm: AlarmHandle, callback: fn(*mut ()), ctx: *mut ()) { | 418 | fn set_alarm_callback(&self, alarm: AlarmHandle, callback: fn(*mut ()), ctx: *mut ()) { |
diff --git a/embassy-time/Cargo.toml b/embassy-time/Cargo.toml index 8f034a9de..e4b88d784 100644 --- a/embassy-time/Cargo.toml +++ b/embassy-time/Cargo.toml | |||
| @@ -218,7 +218,6 @@ embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1", optional = | |||
| 218 | embedded-hal-async = { version = "=1.0.0-rc.1", optional = true} | 218 | embedded-hal-async = { version = "=1.0.0-rc.1", optional = true} |
| 219 | 219 | ||
| 220 | futures-util = { version = "0.3.17", default-features = false } | 220 | futures-util = { version = "0.3.17", default-features = false } |
| 221 | atomic-polyfill = "1.0.1" | ||
| 222 | critical-section = "1.1" | 221 | critical-section = "1.1" |
| 223 | cfg-if = "1.0.0" | 222 | cfg-if = "1.0.0" |
| 224 | heapless = "0.7" | 223 | heapless = "0.7" |
