Skip to content

Commit e240fcc

Browse files
committed
Update safety text for per-peripheral steal()
1 parent be37b64 commit e240fcc

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

src/generate/peripheral.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,15 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
9696
///
9797
///# Safety
9898
///
99-
///Make sure that [`Peripherals::steal`] is already called
99+
/// Ensure that the new instance of the peripheral cannot be used in a way
100+
/// that may race with any existing instances, for example by only
101+
/// accessing read-only or write-only registers, or by consuming the
102+
/// original peripheral and using critical sections to coordinate
103+
/// access between multiple new instances.
104+
///
105+
/// Additionally, other software such as HALs may rely on only one
106+
/// peripheral instance existing to ensure memory safety; ensure
107+
/// no stolen instances are passed to such software.
100108
pub unsafe fn steal() -> Self {
101109
Self { _marker: PhantomData }
102110
}
@@ -161,10 +169,18 @@ pub fn render(p_original: &Peripheral, index: &Index, config: &Config) -> Result
161169
}
162170

163171
///Steal an instance of this peripheral
164-
///
165-
///# Safety
166-
///
167-
///Make sure that [`Peripherals::steal`] is already called
172+
///
173+
///# Safety
174+
///
175+
/// Ensure that the new instance of the peripheral cannot be used in a way
176+
/// that may race with any existing instances, for example by only
177+
/// accessing read-only or write-only registers, or by consuming the
178+
/// original peripheral and using critical sections to coordinate
179+
/// access between multiple new instances.
180+
///
181+
/// Additionally, other software such as HALs may rely on only one
182+
/// peripheral instance existing to ensure memory safety; ensure
183+
/// no stolen instances are passed to such software.
168184
pub unsafe fn steal() -> Self {
169185
Self { _marker: PhantomData }
170186
}

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@
186186
//! use the implementation provided by the target crate like `cortex-m`, `riscv` and `*-hal` crates.
187187
//! See more details in the [`critical-section`](https://crates.io/crates/critical-section) crate documentation.
188188
//!
189-
//! The singleton property can be *unsafely* bypassed using the `ptr` static method which is
190-
//! available on all the peripheral types. This method is useful for implementing safe higher
191-
//! level abstractions.
189+
//! The singleton property can be *unsafely* bypassed using the `ptr` or `steal` static methods
190+
//! which are available on all the peripheral types. This method is useful for implementing safe
191+
//! higher level abstractions.
192192
//!
193193
//! ```ignore
194194
//! struct PA0 { _0: () }

0 commit comments

Comments
 (0)