diff options
| author | Ulf Lilleengen <[email protected]> | 2024-01-25 14:23:57 +0100 |
|---|---|---|
| committer | Ulf Lilleengen <[email protected]> | 2024-01-25 14:23:57 +0100 |
| commit | 7e6bc64331ad2fad71791ac4e0eb76667212f475 (patch) | |
| tree | a4c78a3fc542e36fd325bb15c54dcf58555a92ea /tests | |
| parent | 9418f0f9e53ceddfcaefe90a7fd3ad308f440758 (diff) | |
fix: add missing hil test project
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/nrf51822/.cargo/config.toml | 9 | ||||
| -rw-r--r-- | tests/nrf51822/Cargo.toml | 22 | ||||
| -rw-r--r-- | tests/nrf51822/build.rs | 17 | ||||
| -rw-r--r-- | tests/nrf51822/memory.x | 5 | ||||
| -rw-r--r-- | tests/nrf51822/src/bin/gpio.rs | 28 | ||||
| -rw-r--r-- | tests/nrf51822/src/bin/timer.rs | 25 |
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" | ||
| 3 | runner = "teleprobe client run" | ||
| 4 | |||
| 5 | [build] | ||
| 6 | target = "thumbv6m-none-eabi" | ||
| 7 | |||
| 8 | [env] | ||
| 9 | DEFMT_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] | ||
| 2 | edition = "2021" | ||
| 3 | name = "embassy-nrf51822-tests" | ||
| 4 | version = "0.1.0" | ||
| 5 | license = "MIT OR Apache-2.0" | ||
| 6 | |||
| 7 | [dependencies] | ||
| 8 | teleprobe-meta = "1" | ||
| 9 | |||
| 10 | embassy-sync = { version = "0.5.0", path = "../../embassy-sync", features = ["defmt", ] } | ||
| 11 | embassy-executor = { version = "0.5.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "defmt", "task-arena-size-8192", "integrated-timers"] } | ||
| 12 | embassy-time = { version = "0.3.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime"] } | ||
| 13 | embassy-nrf = { version = "0.1.0", path = "../../embassy-nrf", features = ["defmt", "nrf51", "time-driver-rtc1", "unstable-pac"] } | ||
| 14 | embedded-io-async = { version = "0.6.1", features = ["defmt-03"] } | ||
| 15 | embedded-hal-async = { version = "1.0" } | ||
| 16 | |||
| 17 | defmt = "0.3" | ||
| 18 | defmt-rtt = "0.4" | ||
| 19 | |||
| 20 | cortex-m = { version = "0.7.6", features = ["critical-section-single-core"] } | ||
| 21 | cortex-m-rt = "0.7.0" | ||
| 22 | panic-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 @@ | |||
| 1 | use std::error::Error; | ||
| 2 | use std::path::PathBuf; | ||
| 3 | use std::{env, fs}; | ||
| 4 | |||
| 5 | fn 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 @@ | |||
| 1 | MEMORY | ||
| 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] | ||
| 3 | teleprobe_meta::target!(b"nrf51-dk"); | ||
| 4 | |||
| 5 | use defmt::{assert, info}; | ||
| 6 | use embassy_executor::Spawner; | ||
| 7 | use embassy_nrf::gpio::{Input, Level, Output, OutputDrive, Pull}; | ||
| 8 | use embassy_time::Timer; | ||
| 9 | use {defmt_rtt as _, panic_probe as _}; | ||
| 10 | |||
| 11 | #[embassy_executor::main] | ||
| 12 | async 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] | ||
| 3 | teleprobe_meta::target!(b"nrf52840-dk"); | ||
| 4 | |||
| 5 | use defmt::{assert, info}; | ||
| 6 | use embassy_executor::Spawner; | ||
| 7 | use embassy_time::{Instant, Timer}; | ||
| 8 | use {defmt_rtt as _, panic_probe as _}; | ||
| 9 | |||
| 10 | #[embassy_executor::main] | ||
| 11 | async 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 | } | ||
