Skip to content

Commit 05bbc3b

Browse files
committed
always list all the peripherals in Peripherals
when targeting a sub-architecture where the peripheral is actually not available then the field will be unusable: its type won't provide an API to use. This makes svd2rust and cortex-m-rtfm easier to implement
1 parent 550f949 commit 05bbc3b

File tree

1 file changed

+17
-36
lines changed

1 file changed

+17
-36
lines changed

src/peripheral/mod.rs

+17-36
Original file line numberDiff line numberDiff line change
@@ -111,34 +111,40 @@ mod test;
111111
/// Core peripherals
112112
#[allow(non_snake_case)]
113113
pub struct Peripherals {
114-
/// Cache and branch predictor maintenance operations
115-
#[cfg(not(armv6m))]
114+
/// Cache and branch predictor maintenance operations (not present on Cortex-M0 variants)
116115
pub CBP: CBP,
116+
117117
/// CPUID
118118
pub CPUID: CPUID,
119+
119120
/// Debug Control Block
120121
pub DCB: DCB,
122+
121123
/// Data Watchpoint and Trace unit
122124
pub DWT: DWT,
123-
/// Flash Patch and Breakpoint unit
124-
#[cfg(not(armv6m))]
125+
126+
/// Flash Patch and Breakpoint unit (not present on Cortex-M0 variants)
125127
pub FPB: FPB,
126-
/// Floating Point Unit
127-
#[cfg(any(has_fpu, target_arch = "x86_64"))]
128+
129+
/// Floating Point Unit (only present on `thumbv7em-none-eabihf`)
128130
pub FPU: FPU,
129-
/// Instrumentation Trace Macrocell
130-
#[cfg(not(armv6m))]
131+
132+
/// Instrumentation Trace Macrocell (not present on Cortex-M0 variants)
131133
pub ITM: ITM,
134+
132135
/// Memory Protection Unit
133136
pub MPU: MPU,
137+
134138
/// Nested Vector Interrupt Controller
135139
pub NVIC: NVIC,
140+
136141
/// System Control Block
137142
pub SCB: SCB,
143+
138144
/// SysTick: System Timer
139145
pub SYST: SYST,
140-
/// Trace Port Interface Unit;
141-
#[cfg(not(armv6m))]
146+
147+
/// Trace Port Interface Unit (not present on Cortex-M0 variants)
142148
pub TPIU: TPIU,
143149
}
144150

@@ -167,7 +173,6 @@ impl Peripherals {
167173
CORE_PERIPHERALS = true;
168174

169175
Peripherals {
170-
#[cfg(not(armv6m))]
171176
CBP: CBP {
172177
_marker: PhantomData,
173178
},
@@ -180,15 +185,12 @@ impl Peripherals {
180185
DWT: DWT {
181186
_marker: PhantomData,
182187
},
183-
#[cfg(not(armv6m))]
184188
FPB: FPB {
185189
_marker: PhantomData,
186190
},
187-
#[cfg(any(has_fpu, target_arch = "x86_64"))]
188191
FPU: FPU {
189192
_marker: PhantomData,
190193
},
191-
#[cfg(not(armv6m))]
192194
ITM: ITM {
193195
_marker: PhantomData,
194196
},
@@ -204,7 +206,6 @@ impl Peripherals {
204206
SYST: SYST {
205207
_marker: PhantomData,
206208
},
207-
#[cfg(not(armv6m))]
208209
TPIU: TPIU {
209210
_marker: PhantomData,
210211
},
@@ -213,14 +214,10 @@ impl Peripherals {
213214
}
214215

215216
/// Cache and branch predictor maintenance operations
216-
///
217-
/// *NOTE* Available only on ARMv7-M (`thumbv7*m-none-eabi*`)
218-
#[cfg(not(armv6m))]
219217
pub struct CBP {
220218
_marker: PhantomData<*const ()>,
221219
}
222220

223-
#[cfg(not(armv6m))]
224221
unsafe impl Send for CBP {}
225222

226223
#[cfg(not(armv6m))]
@@ -313,14 +310,10 @@ impl ops::Deref for DWT {
313310
}
314311

315312
/// Flash Patch and Breakpoint unit
316-
///
317-
/// *NOTE* Available only on ARMv7-M (`thumbv7*m-none-eabi*`)
318-
#[cfg(not(armv6m))]
319313
pub struct FPB {
320314
_marker: PhantomData<*const ()>,
321315
}
322316

323-
#[cfg(not(armv6m))]
324317
unsafe impl Send for FPB {}
325318

326319
#[cfg(not(armv6m))]
@@ -341,14 +334,10 @@ impl ops::Deref for FPB {
341334
}
342335

343336
/// Floating Point Unit
344-
///
345-
/// *NOTE* Available only on ARMv7E-M (`thumbv7em-none-eabihf`)
346-
#[cfg(any(has_fpu, target_arch = "x86_64"))]
347337
pub struct FPU {
348338
_marker: PhantomData<*const ()>,
349339
}
350340

351-
#[cfg(any(has_fpu, target_arch = "x86_64"))]
352341
unsafe impl Send for FPU {}
353342

354343
#[cfg(any(has_fpu, target_arch = "x86_64"))]
@@ -369,14 +358,10 @@ impl ops::Deref for FPU {
369358
}
370359

371360
/// Instrumentation Trace Macrocell
372-
///
373-
/// *NOTE* Available only on ARMv7-M (`thumbv7*m-none-eabi*`)
374-
#[cfg(not(armv6m))]
375361
pub struct ITM {
376362
_marker: PhantomData<*const ()>,
377363
}
378364

379-
#[cfg(not(armv6m))]
380365
unsafe impl Send for ITM {}
381366

382367
#[cfg(not(armv6m))]
@@ -491,15 +476,11 @@ impl ops::Deref for SYST {
491476
}
492477
}
493478

494-
/// Trace Port Interface Unit;
495-
///
496-
/// *NOTE* Available only on ARMv7-M (`thumbv7*m-none-eabi*`)
497-
#[cfg(not(armv6m))]
479+
/// Trace Port Interface Unit
498480
pub struct TPIU {
499481
_marker: PhantomData<*const ()>,
500482
}
501483

502-
#[cfg(not(armv6m))]
503484
unsafe impl Send for TPIU {}
504485

505486
#[cfg(not(armv6m))]

0 commit comments

Comments
 (0)