Skip to content

Commit 92634bf

Browse files
authored
Merge pull request #224 from AfoHT/master
Simplistic check if FPU is defined in CPU-block
2 parents 2b3ccfb + 50dab32 commit 92634bf

File tree

1 file changed

+30
-9
lines changed

1 file changed

+30
-9
lines changed

src/generate/device.rs

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,33 @@ pub fn render(d: &Device, target: &Target, nightly: bool, device_x: &mut String)
9191
use core::marker::PhantomData;
9292
});
9393

94+
// Retaining the previous assumption
95+
let mut fpu_present = true;
96+
9497
if let Some(cpu) = d.cpu.as_ref() {
9598
let bits = util::unsuffixed(cpu.nvic_priority_bits as u64);
9699

97100
out.push(quote! {
98101
/// Number available in the NVIC for configuring priority
99102
pub const NVIC_PRIO_BITS: u8 = #bits;
100103
});
104+
105+
fpu_present = cpu.fpu_present;
101106
}
102107

103108
out.extend(interrupt::render(target, &d.peripherals, device_x)?);
104109

105-
const CORE_PERIPHERALS: &[&str] = &[
106-
"CBP", "CPUID", "DCB", "DWT", "FPB", "FPU", "ITM", "MPU", "NVIC", "SCB", "SYST", "TPIU"
107-
];
110+
let core_peripherals: &[&str];
111+
112+
if fpu_present {
113+
core_peripherals = &[
114+
"CBP", "CPUID", "DCB", "DWT", "FPB", "FPU", "ITM", "MPU", "NVIC", "SCB", "SYST", "TPIU"
115+
];
116+
} else {
117+
core_peripherals = &[
118+
"CBP", "CPUID", "DCB", "DWT", "FPB", "ITM", "MPU", "NVIC", "SCB", "SYST", "TPIU"
119+
];
120+
}
108121

109122
let mut fields = vec![];
110123
let mut exprs = vec![];
@@ -113,15 +126,23 @@ pub fn render(d: &Device, target: &Target, nightly: bool, device_x: &mut String)
113126
pub use cortex_m::peripheral::Peripherals as CorePeripherals;
114127
});
115128

116-
out.push(quote! {
117-
pub use cortex_m::peripheral::{
118-
CBP, CPUID, DCB, DWT, FPB, FPU, ITM, MPU, NVIC, SCB, SYST, TPIU,
119-
};
120-
});
129+
if fpu_present {
130+
out.push(quote! {
131+
pub use cortex_m::peripheral::{
132+
CBP, CPUID, DCB, DWT, FPB, FPU, ITM, MPU, NVIC, SCB, SYST, TPIU,
133+
};
134+
});
135+
} else {
136+
out.push(quote! {
137+
pub use cortex_m::peripheral::{
138+
CBP, CPUID, DCB, DWT, FPB, ITM, MPU, NVIC, SCB, SYST, TPIU,
139+
};
140+
});
141+
}
121142
}
122143

123144
for p in &d.peripherals {
124-
if *target == Target::CortexM && CORE_PERIPHERALS.contains(&&*p.name.to_uppercase()) {
145+
if *target == Target::CortexM && core_peripherals.contains(&&*p.name.to_uppercase()) {
125146
// Core peripherals are handled above
126147
continue;
127148
}

0 commit comments

Comments
 (0)