Skip to content

Commit 8a8dfe2

Browse files
authored
Merge pull request #740 from rust-embedded/fix-atomics
fix atomics feature
2 parents 062d0b9 + 753a393 commit 8a8dfe2

File tree

4 files changed

+63
-61
lines changed

4 files changed

+63
-61
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ jobs:
7575
- { rust: stable, vendor: Spansion, options: "--atomics" }
7676
- { rust: stable, vendor: STMicro, options: "" }
7777
- { rust: stable, vendor: STMicro, options: "--atomics" }
78-
- { rust: stable, vendor: STM32-patched, options: "--strict --const_generic --pascal_enum_values --max_cluster_size --atomics" }
78+
- { rust: stable, vendor: STM32-patched, options: "--strict --const_generic --pascal_enum_values --max_cluster_size --atomics --atomics_feature atomics" }
7979
- { rust: stable, vendor: Toshiba, options: all }
8080
- { rust: stable, vendor: Toshiba, options: "" }
8181
# Test MSRV

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
77

88
## [Unreleased]
99

10+
- Fix when `atomics` features is generated but not enabled
1011
- removed register writer & reader wrappers, generic `REG` in field writers (#731)
1112
- Updated syn to version 2 (#732)
1213
- Let readable field fetch doc from svd description (#734)

ci/script.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ main() {
4040

4141
# test crate
4242
cargo init --name foo $td
43-
echo 'cortex-m = "0.7.4"' >> $td/Cargo.toml
44-
echo 'cortex-m-rt = "0.7.1"' >> $td/Cargo.toml
43+
echo 'cortex-m = "0.7.7"' >> $td/Cargo.toml
44+
echo 'cortex-m-rt = "0.7.3"' >> $td/Cargo.toml
4545
echo 'vcell = "0.1.3"' >> $td/Cargo.toml
4646
if [[ "$options" == *"--atomics"* ]]; then
47-
echo 'portable-atomic = { version = "0.3.16", default-features = false }' >> $td/Cargo.toml
47+
echo 'portable-atomic = { version = "1.4", default-features = false }' >> $td/Cargo.toml
4848
fi
4949
echo '[profile.dev]' >> $td/Cargo.toml
5050
echo 'incremental = false' >> $td/Cargo.toml
@@ -566,6 +566,7 @@ main() {
566566
test_patched_stm32 stm32mp157
567567
test_patched_stm32 stm32wb55
568568
test_patched_stm32 stm32wle5
569+
test_patched_stm32 stm32c011
569570
;;
570571

571572
Toshiba)

src/generate/generic_atomic.rs

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
mod atomic {
2+
use super::*;
23
use portable_atomic::Ordering;
34

45
pub trait AtomicOperations {
@@ -35,67 +36,66 @@ mod atomic {
3536
// Enable 64-bit atomics for 64-bit RISCV
3637
#[cfg(any(target_pointer_width = "64", target_has_atomic = "64"))]
3738
impl_atomics!(u64, portable_atomic::AtomicU64);
38-
}
39-
use atomic::AtomicOperations;
4039

41-
impl<REG: Readable + Writable> Reg<REG>
42-
where
43-
REG::Ux: AtomicOperations + Default + core::ops::Not<Output = REG::Ux>,
44-
{
45-
/// Set high every bit in the register that was set in the write proxy. Leave other bits
46-
/// untouched. The write is done in a single atomic instruction.
47-
///
48-
/// # Safety
49-
///
50-
/// The resultant bit pattern may not be valid for the register.
51-
#[inline(always)]
52-
pub unsafe fn set_bits<F>(&self, f: F)
40+
impl<REG: Readable + Writable> Reg<REG>
5341
where
54-
F: FnOnce(&mut W<REG>) -> &mut W<REG>,
42+
REG::Ux: AtomicOperations + Default + core::ops::Not<Output = REG::Ux>,
5543
{
56-
let bits = f(&mut W {
57-
bits: Default::default(),
58-
_reg: marker::PhantomData,
59-
})
60-
.bits;
61-
REG::Ux::atomic_or(self.register.as_ptr(), bits);
62-
}
44+
/// Set high every bit in the register that was set in the write proxy. Leave other bits
45+
/// untouched. The write is done in a single atomic instruction.
46+
///
47+
/// # Safety
48+
///
49+
/// The resultant bit pattern may not be valid for the register.
50+
#[inline(always)]
51+
pub unsafe fn set_bits<F>(&self, f: F)
52+
where
53+
F: FnOnce(&mut W<REG>) -> &mut W<REG>,
54+
{
55+
let bits = f(&mut W {
56+
bits: Default::default(),
57+
_reg: marker::PhantomData,
58+
})
59+
.bits;
60+
REG::Ux::atomic_or(self.register.as_ptr(), bits);
61+
}
6362

64-
/// Clear every bit in the register that was cleared in the write proxy. Leave other bits
65-
/// untouched. The write is done in a single atomic instruction.
66-
///
67-
/// # Safety
68-
///
69-
/// The resultant bit pattern may not be valid for the register.
70-
#[inline(always)]
71-
pub unsafe fn clear_bits<F>(&self, f: F)
72-
where
73-
F: FnOnce(&mut W<REG>) -> &mut W<REG>,
74-
{
75-
let bits = f(&mut W {
76-
bits: !REG::Ux::default(),
77-
_reg: marker::PhantomData,
78-
})
79-
.bits;
80-
REG::Ux::atomic_and(self.register.as_ptr(), bits);
81-
}
63+
/// Clear every bit in the register that was cleared in the write proxy. Leave other bits
64+
/// untouched. The write is done in a single atomic instruction.
65+
///
66+
/// # Safety
67+
///
68+
/// The resultant bit pattern may not be valid for the register.
69+
#[inline(always)]
70+
pub unsafe fn clear_bits<F>(&self, f: F)
71+
where
72+
F: FnOnce(&mut W<REG>) -> &mut W<REG>,
73+
{
74+
let bits = f(&mut W {
75+
bits: !REG::Ux::default(),
76+
_reg: marker::PhantomData,
77+
})
78+
.bits;
79+
REG::Ux::atomic_and(self.register.as_ptr(), bits);
80+
}
8281

83-
/// Toggle every bit in the register that was set in the write proxy. Leave other bits
84-
/// untouched. The write is done in a single atomic instruction.
85-
///
86-
/// # Safety
87-
///
88-
/// The resultant bit pattern may not be valid for the register.
89-
#[inline(always)]
90-
pub unsafe fn toggle_bits<F>(&self, f: F)
91-
where
92-
F: FnOnce(&mut W<REG>) -> &mut W<REG>,
93-
{
94-
let bits = f(&mut W {
95-
bits: Default::default(),
96-
_reg: marker::PhantomData,
97-
})
98-
.bits;
99-
REG::Ux::atomic_xor(self.register.as_ptr(), bits);
82+
/// Toggle every bit in the register that was set in the write proxy. Leave other bits
83+
/// untouched. The write is done in a single atomic instruction.
84+
///
85+
/// # Safety
86+
///
87+
/// The resultant bit pattern may not be valid for the register.
88+
#[inline(always)]
89+
pub unsafe fn toggle_bits<F>(&self, f: F)
90+
where
91+
F: FnOnce(&mut W<REG>) -> &mut W<REG>,
92+
{
93+
let bits = f(&mut W {
94+
bits: Default::default(),
95+
_reg: marker::PhantomData,
96+
})
97+
.bits;
98+
REG::Ux::atomic_xor(self.register.as_ptr(), bits);
99+
}
100100
}
101101
}

0 commit comments

Comments
 (0)