aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorUlf Lilleengen <[email protected]>2024-01-25 14:23:57 +0100
committerUlf Lilleengen <[email protected]>2024-01-25 14:23:57 +0100
commit7e6bc64331ad2fad71791ac4e0eb76667212f475 (patch)
treea4c78a3fc542e36fd325bb15c54dcf58555a92ea /tests
parent9418f0f9e53ceddfcaefe90a7fd3ad308f440758 (diff)
fix: add missing hil test project
Diffstat (limited to 'tests')
-rw-r--r--tests/nrf51822/.cargo/config.toml9
-rw-r--r--tests/nrf51822/Cargo.toml22
-rw-r--r--tests/nrf51822/build.rs17
-rw-r--r--tests/nrf51822/memory.x5
-rw-r--r--tests/nrf51822/src/bin/gpio.rs28
-rw-r--r--tests/nrf51822/src/bin/timer.rs25
6 files changed, 106 insertions, 0 deletions
diff --git a/tests/nrf51822/.cargo/config.toml b/tests/nrf51822/.cargo/config.toml
new file mode 100644
index 000000000..3d0c71092
--- /dev/null
+++ b/tests/nrf51822/.cargo/config.toml
@@ -0,0 +1,9 @@
1[target.'cfg(all(target_arch = "arm", target_os = "none"))']
2#runner = "teleprobe local run --chip nRF51822_xxAA --elf"
3runner = "teleprobe client run"
4
5[build]
6target = "thumbv6m-none-eabi"
7
8[env]
9DEFMT_LOG = "trace,embassy_hal_internal=debug"
diff --git a/tests/nrf51822/Cargo.toml b/tests/nrf51822/Cargo.toml
new file mode 100644
index 000000000..468fa03fa
--- /dev/null
+++ b/tests/nrf51822/Cargo.toml
@@ -0,0 +1,22 @@
1[package]
2edition = "2021"
3name = "embassy-nrf51822-tests"
4version = "0.1.0"
5license = "MIT OR Apache-2.0"
6
7[dependencies]
8teleprobe-meta = "1"
9
10embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt", ] }
11embassy-executor = { version = "0.5.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "task-arena-size-8192", "integrated-timers"] }
12embassy-time = { version = "0.3.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] }
13embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf51", "time-driver-rtc1", "unstable-pac"] }
14embedded-io-async = { version = "0.6.1", features = ["defmt-03"] }
15embedded-hal-async = { version = "1.0" }
16
17defmt = "0.3"
18defmt-rtt = "0.4"
19
20cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] }
21cortex-m-rt = "0.7.0"
22panic-probe = { version = "0.3", features = ["print-defmt"] }
diff --git a/tests/nrf51822/build.rs b/tests/nrf51822/build.rs
new file mode 100644
index 000000000..71c82a70f
--- /dev/null
+++ b/tests/nrf51822/build.rs
@@ -0,0 +1,17 @@
1use std::error::Error;
2use std::path::PathBuf;
3use std::{env, fs};
4
5fn main() -> Result<(), Box<dyn Error>> {
6 let out = PathBuf::from(env::var("OUT_DIR").unwrap());
7 fs::write(out.join("link_ram.x"), include_bytes!("../link_ram_cortex_m.x")).unwrap();
8 println!("cargo:rustc-link-search={}", out.display());
9 println!("cargo:rerun-if-changed=link_ram.x");
10
11 println!("cargo:rustc-link-arg-bins=--nmagic");
12 println!("cargo:rustc-link-arg-bins=-Tlink_ram.x");
13 println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
14 println!("cargo:rustc-link-arg-bins=-Tteleprobe.x");
15
16 Ok(())
17}
diff --git a/tests/nrf51822/memory.x b/tests/nrf51822/memory.x
new file mode 100644
index 000000000..c140005ce
--- /dev/null
+++ b/tests/nrf51822/memory.x
@@ -0,0 +1,5 @@
1MEMORY
2{
3 FLASH : ORIGIN = 0x00000000, LENGTH = 256K
4 RAM : ORIGIN = 0x20000000, LENGTH = 32K
5}
diff --git a/tests/nrf51822/src/bin/gpio.rs b/tests/nrf51822/src/bin/gpio.rs
new file mode 100644
index 000000000..6c6bc0839
--- /dev/null
+++ b/tests/nrf51822/src/bin/gpio.rs
@@ -0,0 +1,28 @@
1#![no_std]
2#![no_main]
3teleprobe_meta::target!(b"nrf51-dk");
4
5use defmt::{assert, info};
6use embassy_executor::Spawner;
7use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull};
8use embassy_time::Timer;
9use {defmt_rtt as _, panic_probe as _};
10
11#[embassy_executor::main]
12async fn main(_spawner: Spawner) {
13 let p = embassy_nrf::init(Default::default());
14
15 let input = Input::new(p.P0_13, Pull::None);
16 let mut output = Output::new(p.P0_14, Level::Low, OutputDrive::Standard);
17
18 output.set_low();
19 Timer::after_millis(1).await;
20 assert!(input.is_low());
21
22 output.set_high();
23 Timer::after_millis(1).await;
24 assert!(input.is_high());
25
26 info!("Test OK");
27 cortex_m::asm::bkpt();
28}
diff --git a/tests/nrf51822/src/bin/timer.rs b/tests/nrf51822/src/bin/timer.rs
new file mode 100644
index 000000000..2a147e7ba
--- /dev/null
+++ b/tests/nrf51822/src/bin/timer.rs
@@ -0,0 +1,25 @@
1#![no_std]
2#![no_main]
3teleprobe_meta::target!(b"nrf52840-dk");
4
5use defmt::{assert, info};
6use embassy_executor::Spawner;
7use embassy_time::{Instant, Timer};
8use {defmt_rtt as _, panic_probe as _};
9
10#[embassy_executor::main]
11async fn main(_spawner: Spawner) {
12 let _p = embassy_nrf::init(Default::default());
13 info!("Hello World!");
14
15 let start = Instant::now();
16 Timer::after_millis(100).await;
17 let end = Instant::now();
18 let ms = (end - start).as_millis();
19 info!("slept for {} ms", ms);
20 assert!(ms >= 99);
21 assert!(ms < 110);
22
23 info!("Test OK");
24 cortex_m::asm::bkpt();
25}