rtic/build.rs

26 lines
797 B
Rust
Raw Normal View History

2017-04-06 21:06:33 +02:00
use std::env;
fn main() {
2017-04-12 06:15:05 +02:00
let target = env::var("TARGET").unwrap();
if version_check::Channel::read().unwrap().is_nightly() {
2022-02-18 19:38:48 +01:00
println!("cargo:rustc-cfg=rustc_is_nightly");
}
Remove use of basepri register on thumbv8m.base The basepri register appears to be aviable on thumbv8m.main but not thumbv8m.base. At the very least, attempting to compile against a Cortex-M23 based Microchip ATSAML10E16A generates an error: ``` error[E0432]: unresolved import `cortex_m::register::basepri` --> /Users/dwatson/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-rtic-1.1.3/src/export.rs:25:5 | 25 | use cortex_m::register::basepri; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `basepri` in `register` ``` This is an attempt to account for the fact that thumbv8m.base (M23) MCUs don't have the BASEPRI register but have more than 32 interrupts. This moves away from the architecture specific config flags and switches to a more functional flag. Make the mask size depend on the max interrupt id Rather than assuming a fixed interrupt count of 32 this code uses an array of u32 bitmasks to calculate the priority mask. The size of this array is calculated at compile time based on the size of the largest interrupt id being used in the target code. For thumbv6m this should be equivalent to the previous version that used a single u32 mask. For thumbv8m.base it will be larger depending on the interrupts used. Don't write 0s to the ISER and ICER registers Writing 0s to these registers is a no-op. Since these masks should be calculated at compile time, this conditional should result in writes being optimized out of the code. Prevent panic on non-arm targets Panicking on unknown targets was breaking things like the doc build on linux. This change should only panic when building on unknown arm targets.
2022-07-03 18:24:11 +02:00
// These targets all have know support for the BASEPRI register.
2019-06-29 09:11:42 +02:00
if target.starts_with("thumbv7m")
| target.starts_with("thumbv7em")
Remove use of basepri register on thumbv8m.base The basepri register appears to be aviable on thumbv8m.main but not thumbv8m.base. At the very least, attempting to compile against a Cortex-M23 based Microchip ATSAML10E16A generates an error: ``` error[E0432]: unresolved import `cortex_m::register::basepri` --> /Users/dwatson/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-rtic-1.1.3/src/export.rs:25:5 | 25 | use cortex_m::register::basepri; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `basepri` in `register` ``` This is an attempt to account for the fact that thumbv8m.base (M23) MCUs don't have the BASEPRI register but have more than 32 interrupts. This moves away from the architecture specific config flags and switches to a more functional flag. Make the mask size depend on the max interrupt id Rather than assuming a fixed interrupt count of 32 this code uses an array of u32 bitmasks to calculate the priority mask. The size of this array is calculated at compile time based on the size of the largest interrupt id being used in the target code. For thumbv6m this should be equivalent to the previous version that used a single u32 mask. For thumbv8m.base it will be larger depending on the interrupts used. Don't write 0s to the ISER and ICER registers Writing 0s to these registers is a no-op. Since these masks should be calculated at compile time, this conditional should result in writes being optimized out of the code. Prevent panic on non-arm targets Panicking on unknown targets was breaking things like the doc build on linux. This change should only panic when building on unknown arm targets.
2022-07-03 18:24:11 +02:00
| target.starts_with("thumbv8m.main")
{
println!("cargo:rustc-cfg=have_basepri");
// These targets are all known to _not_ have the BASEPRI register.
} else if target.starts_with("thumb")
&& !(target.starts_with("thumbv6m") | target.starts_with("thumbv8m.base"))
2019-06-29 09:11:42 +02:00
{
2023-01-08 21:33:44 +01:00
panic!("Unknown target '{target}'. Need to update BASEPRI logic in build.rs.");
2017-04-06 21:06:33 +02:00
}
2017-04-10 05:42:17 +02:00
println!("cargo:rerun-if-changed=build.rs");
2017-04-06 21:06:33 +02:00
}