From dde6607aec758df431eafb5844a78888bc7231e7 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Tue, 7 Dec 2021 00:28:32 +0100 Subject: Add timer test, add g0, g4 tests. --- tests/stm32/.cargo/config.toml | 3 ++- tests/stm32/Cargo.toml | 9 ++++++--- tests/stm32/src/bin/gpio.rs | 7 +++++++ tests/stm32/src/bin/timer.rs | 27 +++++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 tests/stm32/src/bin/timer.rs (limited to 'tests') diff --git a/tests/stm32/.cargo/config.toml b/tests/stm32/.cargo/config.toml index 40a13ddd3..586a63875 100644 --- a/tests/stm32/.cargo/config.toml +++ b/tests/stm32/.cargo/config.toml @@ -4,7 +4,8 @@ build-std-features = ["panic_immediate_abort"] [target.'cfg(all(target_arch = "arm", target_os = "none"))'] # replace STM32F429ZITx with your chip as listed in `probe-run --list-chips` -runner = "probe-run --chip STM32F429ZITx" +#runner = "teleprobe run --chip STM32G071RBTx --elf" +runner = "./teleprobe.sh nucleo-stm32f429zi" rustflags = [ # Code-size optimizations. diff --git a/tests/stm32/Cargo.toml b/tests/stm32/Cargo.toml index f64043a86..e092caf8b 100644 --- a/tests/stm32/Cargo.toml +++ b/tests/stm32/Cargo.toml @@ -5,10 +5,15 @@ name = "embassy-stm32-tests" version = "0.1.0" resolver = "2" +[features] +stm32f429zi = ["embassy-stm32/stm32f429zi"] +stm32g071rb = ["embassy-stm32/stm32g071rb"] +stm32g491re = ["embassy-stm32/stm32g491re"] + [dependencies] embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] } embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] } -embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32f429zi", "unstable-pac", "memory-x", "time-driver-tim2"] } +embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "unstable-pac", "memory-x", "time-driver-tim2"] } defmt = "0.3.0" defmt-rtt = "0.3.0" @@ -19,10 +24,8 @@ embedded-hal = "0.2.6" panic-probe = { version = "0.3.0", features = ["print-defmt"] } [profile.dev] -codegen-units = 1 debug = 2 debug-assertions = true -incremental = false opt-level = 's' overflow-checks = true diff --git a/tests/stm32/src/bin/gpio.rs b/tests/stm32/src/bin/gpio.rs index 7f7fccbfd..7a9d38f2d 100644 --- a/tests/stm32/src/bin/gpio.rs +++ b/tests/stm32/src/bin/gpio.rs @@ -15,6 +15,13 @@ use example_common::*; async fn main(_spawner: Spawner, p: Peripherals) { info!("Hello World!"); + // Arduino pins D0 and D1 + // They're connected together with a 1K resistor. + #[cfg(feature = "stm32g491re")] + let (mut a, mut b) = (p.PC4, p.PC5); + #[cfg(feature = "stm32g071rb")] + let (mut a, mut b) = (p.PC4, p.PC5); + #[cfg(feature = "stm32f429zi")] let (mut a, mut b) = (p.PG14, p.PG9); // Test initial output diff --git a/tests/stm32/src/bin/timer.rs b/tests/stm32/src/bin/timer.rs new file mode 100644 index 000000000..de19a22e3 --- /dev/null +++ b/tests/stm32/src/bin/timer.rs @@ -0,0 +1,27 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +#[path = "../example_common.rs"] +mod example_common; +use defmt::assert; +use embassy::executor::Spawner; +use embassy::time::{Duration, Instant, Timer}; +use embassy_stm32::Peripherals; +use example_common::*; + +#[embassy::main] +async fn main(_spawner: Spawner, _p: Peripherals) { + info!("Hello World!"); + + let start = Instant::now(); + Timer::after(Duration::from_millis(100)).await; + let end = Instant::now(); + let ms = (end - start).as_millis(); + info!("slept for {} ms", ms); + assert!(ms >= 99); + assert!(ms < 110); + + info!("Test OK"); + cortex_m::asm::bkpt(); +} -- cgit