Skip to content

Commit 423b9ef

Browse files
committed
Add cfg to Peripheral fields
The cfg conditional compilation attribute was only set on impl blocks of peripherals. This commit also sets it on the fields themselves to be more consistent. Signed-off-by: Hugues de Valon <[email protected]>
1 parent 72befe4 commit 423b9ef

File tree

7 files changed

+41
-15
lines changed

7 files changed

+41
-15
lines changed

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ mod macros;
5858

5959
pub mod asm;
6060
pub mod interrupt;
61-
#[cfg(not(armv6m))]
61+
#[cfg(all(not(armv6m), not(armv8m_base)))]
6262
pub mod itm;
6363
pub mod peripheral;
6464
pub mod register;

src/peripheral/cbp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Cache and branch predictor maintenance operations
22
//!
3-
//! *NOTE* Available only on ARMv7-M (`thumbv7*m-none-eabi*`)
3+
//! *NOTE* Not available on Armv6-M.
44
55
use volatile_register::WO;
66

src/peripheral/fpb.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Flash Patch and Breakpoint unit
22
//!
3-
//! *NOTE* Available only on ARMv7-M (`thumbv7*m-none-eabi*`)
3+
//! *NOTE* Not available on Armv6-M.
44
55
use volatile_register::{RO, RW, WO};
66

src/peripheral/fpu.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! Floating Point Unit
22
//!
3-
//! *NOTE* Available only on ARMv7E-M (`thumbv7em-none-eabihf`)
3+
//! *NOTE* Available only on targets with a Floating Point Unit (FPU) extension. Those are the
4+
//! targets ending with `hf`.
45
56
use volatile_register::{RO, RW};
67

src/peripheral/itm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Instrumentation Trace Macrocell
22
//!
3-
//! *NOTE* Available only on ARMv7-M (`thumbv7*m-none-eabi*`)
3+
//! *NOTE* Not available on Armv6-M and Armv8-M Baseline.
44
55
use core::cell::UnsafeCell;
66
use core::ptr;

src/peripheral/mod.rs

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ pub mod fpb;
7373
// NOTE(target_arch) is for documentation purposes
7474
#[cfg(any(has_fpu, target_arch = "x86_64"))]
7575
pub mod fpu;
76-
#[cfg(not(armv6m))]
76+
#[cfg(all(not(armv6m), not(armv8m_base)))]
7777
pub mod itm;
7878
pub mod mpu;
7979
pub mod nvic;
@@ -90,7 +90,9 @@ mod test;
9090
/// Core peripherals
9191
#[allow(non_snake_case)]
9292
pub struct Peripherals {
93-
/// Cache and branch predictor maintenance operations (not present on Cortex-M0 variants)
93+
/// Cache and branch predictor maintenance operations.
94+
/// Not available on Armv6-M.
95+
#[cfg(not(armv6m))]
9496
pub CBP: CBP,
9597

9698
/// CPUID
@@ -102,13 +104,19 @@ pub struct Peripherals {
102104
/// Data Watchpoint and Trace unit
103105
pub DWT: DWT,
104106

105-
/// Flash Patch and Breakpoint unit (not present on Cortex-M0 variants)
107+
/// Flash Patch and Breakpoint unit.
108+
/// Not available on Armv6-M.
109+
#[cfg(not(armv6m))]
106110
pub FPB: FPB,
107111

108-
/// Floating Point Unit (only present on `thumbv7em-none-eabihf`)
112+
/// Floating Point Unit.
113+
/// Available only on `hf` targets.
114+
#[cfg(any(has_fpu, target_arch = "x86_64"))]
109115
pub FPU: FPU,
110116

111-
/// Instrumentation Trace Macrocell (not present on Cortex-M0 variants)
117+
/// Instrumentation Trace Macrocell.
118+
/// Not available on Armv6-M and Armv8-M Baseline.
119+
#[cfg(all(not(armv6m), not(armv8m_base)))]
112120
pub ITM: ITM,
113121

114122
/// Memory Protection Unit
@@ -123,7 +131,9 @@ pub struct Peripherals {
123131
/// SysTick: System Timer
124132
pub SYST: SYST,
125133

126-
/// Trace Port Interface Unit (not present on Cortex-M0 variants)
134+
/// Trace Port Interface Unit.
135+
/// Not available on Armv6-M.
136+
#[cfg(not(armv6m))]
127137
pub TPIU: TPIU,
128138

129139
// Private field making `Peripherals` non-exhaustive. We don't use `#[non_exhaustive]` so we
@@ -155,6 +165,7 @@ impl Peripherals {
155165
CORE_PERIPHERALS = true;
156166

157167
Peripherals {
168+
#[cfg(not(armv6m))]
158169
CBP: CBP {
159170
_marker: PhantomData,
160171
},
@@ -167,12 +178,15 @@ impl Peripherals {
167178
DWT: DWT {
168179
_marker: PhantomData,
169180
},
181+
#[cfg(not(armv6m))]
170182
FPB: FPB {
171183
_marker: PhantomData,
172184
},
185+
#[cfg(any(has_fpu, target_arch = "x86_64"))]
173186
FPU: FPU {
174187
_marker: PhantomData,
175188
},
189+
#[cfg(all(not(armv6m), not(armv8m_base)))]
176190
ITM: ITM {
177191
_marker: PhantomData,
178192
},
@@ -188,6 +202,7 @@ impl Peripherals {
188202
SYST: SYST {
189203
_marker: PhantomData,
190204
},
205+
#[cfg(not(armv6m))]
191206
TPIU: TPIU {
192207
_marker: PhantomData,
193208
},
@@ -197,10 +212,12 @@ impl Peripherals {
197212
}
198213

199214
/// Cache and branch predictor maintenance operations
215+
#[cfg(not(armv6m))]
200216
pub struct CBP {
201217
_marker: PhantomData<*const ()>,
202218
}
203219

220+
#[cfg(not(armv6m))]
204221
unsafe impl Send for CBP {}
205222

206223
#[cfg(not(armv6m))]
@@ -302,10 +319,12 @@ impl ops::Deref for DWT {
302319
}
303320

304321
/// Flash Patch and Breakpoint unit
322+
#[cfg(not(armv6m))]
305323
pub struct FPB {
306324
_marker: PhantomData<*const ()>,
307325
}
308326

327+
#[cfg(not(armv6m))]
309328
unsafe impl Send for FPB {}
310329

311330
#[cfg(not(armv6m))]
@@ -328,10 +347,12 @@ impl ops::Deref for FPB {
328347
}
329348

330349
/// Floating Point Unit
350+
#[cfg(any(has_fpu, target_arch = "x86_64"))]
331351
pub struct FPU {
332352
_marker: PhantomData<*const ()>,
333353
}
334354

355+
#[cfg(any(has_fpu, target_arch = "x86_64"))]
335356
unsafe impl Send for FPU {}
336357

337358
#[cfg(any(has_fpu, target_arch = "x86_64"))]
@@ -354,13 +375,15 @@ impl ops::Deref for FPU {
354375
}
355376

356377
/// Instrumentation Trace Macrocell
378+
#[cfg(all(not(armv6m), not(armv8m_base)))]
357379
pub struct ITM {
358380
_marker: PhantomData<*const ()>,
359381
}
360382

383+
#[cfg(all(not(armv6m), not(armv8m_base)))]
361384
unsafe impl Send for ITM {}
362385

363-
#[cfg(not(armv6m))]
386+
#[cfg(all(not(armv6m), not(armv8m_base)))]
364387
impl ITM {
365388
/// Returns a pointer to the register block
366389
#[inline(always)]
@@ -369,7 +392,7 @@ impl ITM {
369392
}
370393
}
371394

372-
#[cfg(not(armv6m))]
395+
#[cfg(all(not(armv6m), not(armv8m_base)))]
373396
impl ops::Deref for ITM {
374397
type Target = self::itm::RegisterBlock;
375398

@@ -379,7 +402,7 @@ impl ops::Deref for ITM {
379402
}
380403
}
381404

382-
#[cfg(not(armv6m))]
405+
#[cfg(all(not(armv6m), not(armv8m_base)))]
383406
impl ops::DerefMut for ITM {
384407
#[inline(always)]
385408
fn deref_mut(&mut self) -> &mut Self::Target {
@@ -484,10 +507,12 @@ impl ops::Deref for SYST {
484507
}
485508

486509
/// Trace Port Interface Unit
510+
#[cfg(not(armv6m))]
487511
pub struct TPIU {
488512
_marker: PhantomData<*const ()>,
489513
}
490514

515+
#[cfg(not(armv6m))]
491516
unsafe impl Send for TPIU {}
492517

493518
#[cfg(not(armv6m))]

src/peripheral/tpiu.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Trace Port Interface Unit;
22
//!
3-
//! *NOTE* Available only on ARMv7-M (`thumbv7*m-none-eabi*`)
3+
//! *NOTE* Not available on Armv6-M.
44
55
use volatile_register::{RO, RW, WO};
66

0 commit comments

Comments
 (0)