diff options
| author | pennae <[email protected]> | 2023-04-19 01:57:37 +0200 |
|---|---|---|
| committer | pennae <[email protected]> | 2023-04-19 23:04:47 +0200 |
| commit | fdd6e08ed6b5445a53c8cd0752f80f203c4860ac (patch) | |
| tree | 9b997c5db2d55c911a6fd4cfdce38141e372b762 /tests | |
| parent | a673b9aa294a55c441f3f61c48481484629b4347 (diff) | |
rp: hook up softfloat rom intrinsics
rp-hal has done this very well already, so we'll just copy their entire
impl again. only div.rs needed some massaging because our sio access
works a little differently, everything else worked as is.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/rp/.cargo/config.toml | 6 | ||||
| -rw-r--r-- | tests/rp/Cargo.toml | 2 | ||||
| -rw-r--r-- | tests/rp/src/bin/float.rs | 53 |
3 files changed, 58 insertions, 3 deletions
diff --git a/tests/rp/.cargo/config.toml b/tests/rp/.cargo/config.toml index 9611db3a0..e1744c703 100644 --- a/tests/rp/.cargo/config.toml +++ b/tests/rp/.cargo/config.toml | |||
| @@ -1,6 +1,8 @@ | |||
| 1 | [unstable] | 1 | [unstable] |
| 2 | build-std = ["core"] | 2 | # enabling these breaks the float tests during linking, with intrinsics |
| 3 | build-std-features = ["panic_immediate_abort"] | 3 | # duplicated between embassy-rp and compilter_builtins |
| 4 | #build-std = ["core"] | ||
| 5 | #build-std-features = ["panic_immediate_abort"] | ||
| 4 | 6 | ||
| 5 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] | 7 | [target.'cfg(all(target_arch = "arm", target_os = "none"))'] |
| 6 | #runner = "teleprobe client run --target rpi-pico --elf" | 8 | #runner = "teleprobe client run --target rpi-pico --elf" |
diff --git a/tests/rp/Cargo.toml b/tests/rp/Cargo.toml index 36ff735ec..6778f53d7 100644 --- a/tests/rp/Cargo.toml +++ b/tests/rp/Cargo.toml | |||
| @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0" | |||
| 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } | 8 | embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } |
| 9 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } | 9 | embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } |
| 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt"] } | 10 | embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt"] } |
| 11 | embassy-rp = { version = "0.1.0", path = "../../embassy-rp", features = ["nightly", "defmt", "unstable-pac", "unstable-traits", "time-driver", "critical-section-impl"] } | 11 | embassy-rp = { version = "0.1.0", path = "../../embassy-rp", features = ["nightly", "defmt", "unstable-pac", "unstable-traits", "time-driver", "critical-section-impl", "intrinsics", "rom-v2-intrinsics"] } |
| 12 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } | 12 | embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } |
| 13 | 13 | ||
| 14 | defmt = "0.3.0" | 14 | defmt = "0.3.0" |
diff --git a/tests/rp/src/bin/float.rs b/tests/rp/src/bin/float.rs new file mode 100644 index 000000000..6715271e6 --- /dev/null +++ b/tests/rp/src/bin/float.rs | |||
| @@ -0,0 +1,53 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | use defmt::*; | ||
| 6 | use embassy_executor::Spawner; | ||
| 7 | use embassy_rp::pac; | ||
| 8 | use embassy_time::{Duration, Timer}; | ||
| 9 | use {defmt_rtt as _, panic_probe as _}; | ||
| 10 | |||
| 11 | #[embassy_executor::main] | ||
| 12 | async fn main(_spawner: Spawner) { | ||
| 13 | embassy_rp::init(Default::default()); | ||
| 14 | info!("Hello World!"); | ||
| 15 | |||
| 16 | const PI_F: f32 = 3.1415926535f32; | ||
| 17 | const PI_D: f64 = 3.14159265358979323846f64; | ||
| 18 | |||
| 19 | unsafe { | ||
| 20 | pac::BUSCTRL | ||
| 21 | .perfsel(0) | ||
| 22 | .write(|r| r.set_perfsel(pac::busctrl::vals::Perfsel::ROM)); | ||
| 23 | } | ||
| 24 | |||
| 25 | for i in 0..=360 { | ||
| 26 | let rad_f = (i as f32) * PI_F / 180.0; | ||
| 27 | info!( | ||
| 28 | "{}° float: {=f32} / {=f32} / {=f32} / {=f32}", | ||
| 29 | i, | ||
| 30 | rad_f, | ||
| 31 | rad_f - PI_F, | ||
| 32 | rad_f + PI_F, | ||
| 33 | rad_f % PI_F | ||
| 34 | ); | ||
| 35 | let rad_d = (i as f64) * PI_D / 180.0; | ||
| 36 | info!( | ||
| 37 | "{}° double: {=f64} / {=f64} / {=f64} / {=f64}", | ||
| 38 | i, | ||
| 39 | rad_d, | ||
| 40 | rad_d - PI_D, | ||
| 41 | rad_d + PI_D, | ||
| 42 | rad_d % PI_D | ||
| 43 | ); | ||
| 44 | Timer::after(Duration::from_millis(10)).await; | ||
| 45 | } | ||
| 46 | |||
| 47 | let rom_accesses = unsafe { pac::BUSCTRL.perfctr(0).read().perfctr() }; | ||
| 48 | // every float operation used here uses at least 10 cycles | ||
| 49 | defmt::assert!(rom_accesses >= 360 * 12 * 10); | ||
| 50 | |||
| 51 | info!("Test OK"); | ||
| 52 | cortex_m::asm::bkpt(); | ||
| 53 | } | ||
