aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/rp/.cargo/config.toml6
-rw-r--r--tests/rp/Cargo.toml2
-rw-r--r--tests/rp/src/bin/float.rs53
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]
2build-std = ["core"] 2# enabling these breaks the float tests during linking, with intrinsics
3build-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"
8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } 8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
9embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] } 9embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "integrated-timers"] }
10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt"] } 10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt"] }
11embassy-rp = { version = "0.1.0", path = "../../embassy-rp", features = ["nightly", "defmt", "unstable-pac", "unstable-traits", "time-driver", "critical-section-impl"] } 11embassy-rp = { version = "0.1.0", path = "../../embassy-rp", features = ["nightly", "defmt", "unstable-pac", "unstable-traits", "time-driver", "critical-section-impl", "intrinsics", "rom-v2-intrinsics"] }
12embassy-futures = { version = "0.1.0", path = "../../embassy-futures" } 12embassy-futures = { version = "0.1.0", path = "../../embassy-futures" }
13 13
14defmt = "0.3.0" 14defmt = "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
5use defmt::*;
6use embassy_executor::Spawner;
7use embassy_rp::pac;
8use embassy_time::{Duration, Timer};
9use {defmt_rtt as _, panic_probe as _};
10
11#[embassy_executor::main]
12async 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}