Skip to content

Commit 40209a8

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 ce538b2 commit 40209a8

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
@@ -59,7 +59,7 @@ mod macros;
5959

6060
pub mod asm;
6161
pub mod interrupt;
62-
#[cfg(not(armv6m))]
62+
#[cfg(all(not(armv6m), not(armv8m_base)))]
6363
pub mod itm;
6464
pub mod peripheral;
6565
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
@@ -86,7 +86,7 @@ pub mod fpb;
8686
// NOTE(target_arch) is for documentation purposes
8787
#[cfg(any(has_fpu, target_arch = "x86_64"))]
8888
pub mod fpu;
89-
#[cfg(not(armv6m))]
89+
#[cfg(all(not(armv6m), not(armv8m_base)))]
9090
pub mod itm;
9191
pub mod mpu;
9292
pub mod nvic;
@@ -103,7 +103,9 @@ mod test;
103103
/// Core peripherals
104104
#[allow(non_snake_case)]
105105
pub struct Peripherals {
106-
/// Cache and branch predictor maintenance operations (not present on Cortex-M0 variants)
106+
/// Cache and branch predictor maintenance operations.
107+
/// Not available on Armv6-M.
108+
#[cfg(not(armv6m))]
107109
pub CBP: CBP,
108110

109111
/// CPUID
@@ -115,13 +117,19 @@ pub struct Peripherals {
115117
/// Data Watchpoint and Trace unit
116118
pub DWT: DWT,
117119

118-
/// Flash Patch and Breakpoint unit (not present on Cortex-M0 variants)
120+
/// Flash Patch and Breakpoint unit.
121+
/// Not available on Armv6-M.
122+
#[cfg(not(armv6m))]
119123
pub FPB: FPB,
120124

121-
/// Floating Point Unit (only present on `thumbv7em-none-eabihf`)
125+
/// Floating Point Unit.
126+
/// Available only on `hf` targets.
127+
#[cfg(any(has_fpu, target_arch = "x86_64"))]
122128
pub FPU: FPU,
123129

124-
/// Instrumentation Trace Macrocell (not present on Cortex-M0 variants)
130+
/// Instrumentation Trace Macrocell.
131+
/// Not available on Armv6-M and Armv8-M Baseline.
132+
#[cfg(all(not(armv6m), not(armv8m_base)))]
125133
pub ITM: ITM,
126134

127135
/// Memory Protection Unit
@@ -136,7 +144,9 @@ pub struct Peripherals {
136144
/// SysTick: System Timer
137145
pub SYST: SYST,
138146

139-
/// Trace Port Interface Unit (not present on Cortex-M0 variants)
147+
/// Trace Port Interface Unit.
148+
/// Not available on Armv6-M.
149+
#[cfg(not(armv6m))]
140150
pub TPIU: TPIU,
141151
}
142152

@@ -164,6 +174,7 @@ impl Peripherals {
164174
CORE_PERIPHERALS = true;
165175

166176
Peripherals {
177+
#[cfg(not(armv6m))]
167178
CBP: CBP {
168179
_marker: PhantomData,
169180
},
@@ -176,12 +187,15 @@ impl Peripherals {
176187
DWT: DWT {
177188
_marker: PhantomData,
178189
},
190+
#[cfg(not(armv6m))]
179191
FPB: FPB {
180192
_marker: PhantomData,
181193
},
194+
#[cfg(any(has_fpu, target_arch = "x86_64"))]
182195
FPU: FPU {
183196
_marker: PhantomData,
184197
},
198+
#[cfg(all(not(armv6m), not(armv8m_base)))]
185199
ITM: ITM {
186200
_marker: PhantomData,
187201
},
@@ -197,6 +211,7 @@ impl Peripherals {
197211
SYST: SYST {
198212
_marker: PhantomData,
199213
},
214+
#[cfg(not(armv6m))]
200215
TPIU: TPIU {
201216
_marker: PhantomData,
202217
},
@@ -205,10 +220,12 @@ impl Peripherals {
205220
}
206221

207222
/// Cache and branch predictor maintenance operations
223+
#[cfg(not(armv6m))]
208224
pub struct CBP {
209225
_marker: PhantomData<*const ()>,
210226
}
211227

228+
#[cfg(not(armv6m))]
212229
unsafe impl Send for CBP {}
213230

214231
#[cfg(not(armv6m))]
@@ -310,10 +327,12 @@ impl ops::Deref for DWT {
310327
}
311328

312329
/// Flash Patch and Breakpoint unit
330+
#[cfg(not(armv6m))]
313331
pub struct FPB {
314332
_marker: PhantomData<*const ()>,
315333
}
316334

335+
#[cfg(not(armv6m))]
317336
unsafe impl Send for FPB {}
318337

319338
#[cfg(not(armv6m))]
@@ -336,10 +355,12 @@ impl ops::Deref for FPB {
336355
}
337356

338357
/// Floating Point Unit
358+
#[cfg(any(has_fpu, target_arch = "x86_64"))]
339359
pub struct FPU {
340360
_marker: PhantomData<*const ()>,
341361
}
342362

363+
#[cfg(any(has_fpu, target_arch = "x86_64"))]
343364
unsafe impl Send for FPU {}
344365

345366
#[cfg(any(has_fpu, target_arch = "x86_64"))]
@@ -362,13 +383,15 @@ impl ops::Deref for FPU {
362383
}
363384

364385
/// Instrumentation Trace Macrocell
386+
#[cfg(all(not(armv6m), not(armv8m_base)))]
365387
pub struct ITM {
366388
_marker: PhantomData<*const ()>,
367389
}
368390

391+
#[cfg(all(not(armv6m), not(armv8m_base)))]
369392
unsafe impl Send for ITM {}
370393

371-
#[cfg(not(armv6m))]
394+
#[cfg(all(not(armv6m), not(armv8m_base)))]
372395
impl ITM {
373396
/// Returns a pointer to the register block
374397
#[inline(always)]
@@ -377,7 +400,7 @@ impl ITM {
377400
}
378401
}
379402

380-
#[cfg(not(armv6m))]
403+
#[cfg(all(not(armv6m), not(armv8m_base)))]
381404
impl ops::Deref for ITM {
382405
type Target = self::itm::RegisterBlock;
383406

@@ -387,7 +410,7 @@ impl ops::Deref for ITM {
387410
}
388411
}
389412

390-
#[cfg(not(armv6m))]
413+
#[cfg(all(not(armv6m), not(armv8m_base)))]
391414
impl ops::DerefMut for ITM {
392415
#[inline(always)]
393416
fn deref_mut(&mut self) -> &mut Self::Target {
@@ -492,10 +515,12 @@ impl ops::Deref for SYST {
492515
}
493516

494517
/// Trace Port Interface Unit
518+
#[cfg(not(armv6m))]
495519
pub struct TPIU {
496520
_marker: PhantomData<*const ()>,
497521
}
498522

523+
#[cfg(not(armv6m))]
499524
unsafe impl Send for TPIU {}
500525

501526
#[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)