stm32: remove atomic-polyfill.
This commit is contained in:
parent
32b89eeba1
commit
70a91945fc
@ -58,7 +58,6 @@ rand_core = "0.6.3"
|
|||||||
sdio-host = "0.5.0"
|
sdio-host = "0.5.0"
|
||||||
embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "a4f293d3a6f72158385f79c98634cb8a14d0d2fc", optional = true }
|
embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "a4f293d3a6f72158385f79c98634cb8a14d0d2fc", optional = true }
|
||||||
critical-section = "1.1"
|
critical-section = "1.1"
|
||||||
atomic-polyfill = "1.0.1"
|
|
||||||
stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-6bfa5a0dcec6a9bd42cea94ba11eeae1a17a7f2c" }
|
stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-6bfa5a0dcec6a9bd42cea94ba11eeae1a17a7f2c" }
|
||||||
vcell = "0.1.3"
|
vcell = "0.1.3"
|
||||||
bxcan = "0.7.0"
|
bxcan = "0.7.0"
|
||||||
|
@ -8,6 +8,32 @@ use quote::{format_ident, quote};
|
|||||||
use stm32_metapac::metadata::{MemoryRegionKind, METADATA};
|
use stm32_metapac::metadata::{MemoryRegionKind, METADATA};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
let target = env::var("TARGET").unwrap();
|
||||||
|
|
||||||
|
if target.starts_with("thumbv6m-") {
|
||||||
|
println!("cargo:rustc-cfg=cortex_m");
|
||||||
|
println!("cargo:rustc-cfg=armv6m");
|
||||||
|
} else if target.starts_with("thumbv7m-") {
|
||||||
|
println!("cargo:rustc-cfg=cortex_m");
|
||||||
|
println!("cargo:rustc-cfg=armv7m");
|
||||||
|
} else if target.starts_with("thumbv7em-") {
|
||||||
|
println!("cargo:rustc-cfg=cortex_m");
|
||||||
|
println!("cargo:rustc-cfg=armv7m");
|
||||||
|
println!("cargo:rustc-cfg=armv7em"); // (not currently used)
|
||||||
|
} else if target.starts_with("thumbv8m.base") {
|
||||||
|
println!("cargo:rustc-cfg=cortex_m");
|
||||||
|
println!("cargo:rustc-cfg=armv8m");
|
||||||
|
println!("cargo:rustc-cfg=armv8m_base");
|
||||||
|
} else if target.starts_with("thumbv8m.main") {
|
||||||
|
println!("cargo:rustc-cfg=cortex_m");
|
||||||
|
println!("cargo:rustc-cfg=armv8m");
|
||||||
|
println!("cargo:rustc-cfg=armv8m_main");
|
||||||
|
}
|
||||||
|
|
||||||
|
if target.ends_with("-eabihf") {
|
||||||
|
println!("cargo:rustc-cfg=has_fpu");
|
||||||
|
}
|
||||||
|
|
||||||
let chip_name = match env::vars()
|
let chip_name = match env::vars()
|
||||||
.map(|(a, _)| a)
|
.map(|(a, _)| a)
|
||||||
.filter(|x| x.starts_with("CARGO_FEATURE_STM32"))
|
.filter(|x| x.starts_with("CARGO_FEATURE_STM32"))
|
||||||
@ -434,20 +460,20 @@ fn main() {
|
|||||||
unsafe { crate::rcc::get_freqs().#clk }
|
unsafe { crate::rcc::get_freqs().#clk }
|
||||||
}
|
}
|
||||||
fn enable() {
|
fn enable() {
|
||||||
critical_section::with(|_| {
|
critical_section::with(|_cs| {
|
||||||
#before_enable
|
#before_enable
|
||||||
#[cfg(feature = "low-power")]
|
#[cfg(feature = "low-power")]
|
||||||
crate::rcc::clock_refcount_add();
|
crate::rcc::clock_refcount_add(_cs);
|
||||||
crate::pac::RCC.#en_reg().modify(|w| w.#set_en_field(true));
|
crate::pac::RCC.#en_reg().modify(|w| w.#set_en_field(true));
|
||||||
#after_enable
|
#after_enable
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
fn disable() {
|
fn disable() {
|
||||||
critical_section::with(|_| {
|
critical_section::with(|_cs| {
|
||||||
#before_disable
|
#before_disable
|
||||||
crate::pac::RCC.#en_reg().modify(|w| w.#set_en_field(false));
|
crate::pac::RCC.#en_reg().modify(|w| w.#set_en_field(false));
|
||||||
#[cfg(feature = "low-power")]
|
#[cfg(feature = "low-power")]
|
||||||
crate::rcc::clock_refcount_sub();
|
crate::rcc::clock_refcount_sub(_cs);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
fn reset() {
|
fn reset() {
|
||||||
|
@ -2,10 +2,9 @@
|
|||||||
|
|
||||||
use core::future::Future;
|
use core::future::Future;
|
||||||
use core::pin::Pin;
|
use core::pin::Pin;
|
||||||
use core::sync::atomic::{fence, Ordering};
|
use core::sync::atomic::{fence, AtomicUsize, Ordering};
|
||||||
use core::task::{Context, Poll, Waker};
|
use core::task::{Context, Poll, Waker};
|
||||||
|
|
||||||
use atomic_polyfill::AtomicUsize;
|
|
||||||
use embassy_hal_internal::{into_ref, Peripheral, PeripheralRef};
|
use embassy_hal_internal::{into_ref, Peripheral, PeripheralRef};
|
||||||
use embassy_sync::waitqueue::AtomicWaker;
|
use embassy_sync::waitqueue::AtomicWaker;
|
||||||
|
|
||||||
@ -127,7 +126,13 @@ pub(crate) unsafe fn on_irq_inner(dma: pac::bdma::Dma, channel_num: usize, index
|
|||||||
} else if isr.tcif(channel_num) && cr.read().tcie() {
|
} else if isr.tcif(channel_num) && cr.read().tcie() {
|
||||||
// Acknowledge transfer complete interrupt
|
// Acknowledge transfer complete interrupt
|
||||||
dma.ifcr().write(|w| w.set_tcif(channel_num, true));
|
dma.ifcr().write(|w| w.set_tcif(channel_num, true));
|
||||||
|
#[cfg(not(armv6m))]
|
||||||
STATE.complete_count[index].fetch_add(1, Ordering::Release);
|
STATE.complete_count[index].fetch_add(1, Ordering::Release);
|
||||||
|
#[cfg(armv6m)]
|
||||||
|
critical_section::with(|_| {
|
||||||
|
let x = STATE.complete_count[index].load(Ordering::Relaxed);
|
||||||
|
STATE.complete_count[index].store(x + 1, Ordering::Release);
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -391,7 +396,14 @@ impl<'a, C: Channel> DmaCtrl for DmaCtrlImpl<'a, C> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn reset_complete_count(&mut self) -> usize {
|
fn reset_complete_count(&mut self) -> usize {
|
||||||
STATE.complete_count[self.0.index()].swap(0, Ordering::AcqRel)
|
#[cfg(not(armv6m))]
|
||||||
|
return STATE.complete_count[self.0.index()].swap(0, Ordering::AcqRel);
|
||||||
|
#[cfg(armv6m)]
|
||||||
|
return critical_section::with(|_| {
|
||||||
|
let x = STATE.complete_count[self.0.index()].load(Ordering::Acquire);
|
||||||
|
STATE.complete_count[self.0.index()].store(0, Ordering::Release);
|
||||||
|
x
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_waker(&mut self, waker: &Waker) {
|
fn set_waker(&mut self, waker: &Waker) {
|
||||||
|
@ -225,7 +225,9 @@ pub fn init(config: Config) -> Peripherals {
|
|||||||
|
|
||||||
#[cfg(feature = "low-power")]
|
#[cfg(feature = "low-power")]
|
||||||
while !crate::rcc::low_power_ready() {
|
while !crate::rcc::low_power_ready() {
|
||||||
crate::rcc::clock_refcount_sub();
|
critical_section::with(|cs| {
|
||||||
|
crate::rcc::clock_refcount_sub(cs);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use core::arch::asm;
|
use core::arch::asm;
|
||||||
use core::marker::PhantomData;
|
use core::marker::PhantomData;
|
||||||
|
use core::sync::atomic::{compiler_fence, Ordering};
|
||||||
|
|
||||||
use atomic_polyfill::{compiler_fence, Ordering};
|
|
||||||
use cortex_m::peripheral::SCB;
|
use cortex_m::peripheral::SCB;
|
||||||
use embassy_executor::*;
|
use embassy_executor::*;
|
||||||
|
|
||||||
|
@ -27,9 +27,10 @@ pub use mco::*;
|
|||||||
#[cfg_attr(rcc_wba, path = "wba.rs")]
|
#[cfg_attr(rcc_wba, path = "wba.rs")]
|
||||||
#[cfg_attr(any(rcc_wl5, rcc_wle), path = "wl.rs")]
|
#[cfg_attr(any(rcc_wl5, rcc_wle), path = "wl.rs")]
|
||||||
mod _version;
|
mod _version;
|
||||||
pub use _version::*;
|
|
||||||
#[cfg(feature = "low-power")]
|
#[cfg(feature = "low-power")]
|
||||||
use atomic_polyfill::{AtomicU32, Ordering};
|
use core::sync::atomic::{AtomicU32, Ordering};
|
||||||
|
|
||||||
|
pub use _version::*;
|
||||||
|
|
||||||
// Model Clock Configuration
|
// Model Clock Configuration
|
||||||
//
|
//
|
||||||
@ -145,14 +146,17 @@ pub fn low_power_ready() -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "low-power")]
|
#[cfg(feature = "low-power")]
|
||||||
pub(crate) fn clock_refcount_add() {
|
pub(crate) fn clock_refcount_add(_cs: critical_section::CriticalSection) {
|
||||||
// We don't check for overflow because constructing more than u32 peripherals is unlikely
|
// We don't check for overflow because constructing more than u32 peripherals is unlikely
|
||||||
CLOCK_REFCOUNT.fetch_add(1, Ordering::Relaxed);
|
let n = CLOCK_REFCOUNT.load(Ordering::Relaxed);
|
||||||
|
CLOCK_REFCOUNT.store(n + 1, Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "low-power")]
|
#[cfg(feature = "low-power")]
|
||||||
pub(crate) fn clock_refcount_sub() {
|
pub(crate) fn clock_refcount_sub(_cs: critical_section::CriticalSection) {
|
||||||
assert!(CLOCK_REFCOUNT.fetch_sub(1, Ordering::Relaxed) != 0);
|
let n = CLOCK_REFCOUNT.load(Ordering::Relaxed);
|
||||||
|
assert!(n != 0);
|
||||||
|
CLOCK_REFCOUNT.store(n - 1, Ordering::Relaxed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Frozen clock frequencies
|
/// Frozen clock frequencies
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
use core::cell::Cell;
|
use core::cell::Cell;
|
||||||
use core::convert::TryInto;
|
use core::convert::TryInto;
|
||||||
use core::sync::atomic::{compiler_fence, Ordering};
|
use core::sync::atomic::{compiler_fence, AtomicU32, AtomicU8, Ordering};
|
||||||
use core::{mem, ptr};
|
use core::{mem, ptr};
|
||||||
|
|
||||||
use atomic_polyfill::{AtomicU32, AtomicU8};
|
|
||||||
use critical_section::CriticalSection;
|
use critical_section::CriticalSection;
|
||||||
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex;
|
||||||
use embassy_sync::blocking_mutex::Mutex;
|
use embassy_sync::blocking_mutex::Mutex;
|
||||||
@ -229,7 +228,9 @@ impl RtcDriver {
|
|||||||
fn next_period(&self) {
|
fn next_period(&self) {
|
||||||
let r = T::regs_gp16();
|
let r = T::regs_gp16();
|
||||||
|
|
||||||
let period = self.period.fetch_add(1, Ordering::Relaxed) + 1;
|
// We only modify the period from the timer interrupt, so we know this can't race.
|
||||||
|
let period = self.period.load(Ordering::Relaxed) + 1;
|
||||||
|
self.period.store(period, Ordering::Relaxed);
|
||||||
let t = (period as u64) << 15;
|
let t = (period as u64) << 15;
|
||||||
|
|
||||||
critical_section::with(move |cs| {
|
critical_section::with(move |cs| {
|
||||||
@ -403,18 +404,15 @@ impl Driver for RtcDriver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn allocate_alarm(&self) -> Option<AlarmHandle> {
|
unsafe fn allocate_alarm(&self) -> Option<AlarmHandle> {
|
||||||
let id = self.alarm_count.fetch_update(Ordering::AcqRel, Ordering::Acquire, |x| {
|
critical_section::with(|_| {
|
||||||
if x < ALARM_COUNT as u8 {
|
let id = self.alarm_count.load(Ordering::Relaxed);
|
||||||
Some(x + 1)
|
if id < ALARM_COUNT as u8 {
|
||||||
|
self.alarm_count.store(id + 1, Ordering::Relaxed);
|
||||||
|
Some(AlarmHandle::new(id))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
});
|
})
|
||||||
|
|
||||||
match id {
|
|
||||||
Ok(id) => Some(AlarmHandle::new(id)),
|
|
||||||
Err(_) => None,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_alarm_callback(&self, alarm: AlarmHandle, callback: fn(*mut ()), ctx: *mut ()) {
|
fn set_alarm_callback(&self, alarm: AlarmHandle, callback: fn(*mut ()), ctx: *mut ()) {
|
||||||
|
@ -218,7 +218,6 @@ embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-rc.1", optional =
|
|||||||
embedded-hal-async = { version = "=1.0.0-rc.1", optional = true}
|
embedded-hal-async = { version = "=1.0.0-rc.1", optional = true}
|
||||||
|
|
||||||
futures-util = { version = "0.3.17", default-features = false }
|
futures-util = { version = "0.3.17", default-features = false }
|
||||||
atomic-polyfill = "1.0.1"
|
|
||||||
critical-section = "1.1"
|
critical-section = "1.1"
|
||||||
cfg-if = "1.0.0"
|
cfg-if = "1.0.0"
|
||||||
heapless = "0.7"
|
heapless = "0.7"
|
||||||
|
Loading…
Reference in New Issue
Block a user