aboutsummaryrefslogtreecommitdiff
path: root/tests/stm32/src
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2021-11-24 03:18:30 +0100
committerDario Nieuwenhuis <[email protected]>2021-12-06 22:05:41 +0100
commitdd32358d6bb24895c833bc4c34fd96e7632e43a9 (patch)
tree57a3647217dce831e713e4709835ec2388050682 /tests/stm32/src
parent00a87b9a41f55efdf831a2579de5f271222e6577 (diff)
stm32: add gpio HIL test
Diffstat (limited to 'tests/stm32/src')
-rw-r--r--tests/stm32/src/bin/gpio.rs79
-rw-r--r--tests/stm32/src/example_common.rs17
2 files changed, 96 insertions, 0 deletions
diff --git a/tests/stm32/src/bin/gpio.rs b/tests/stm32/src/bin/gpio.rs
new file mode 100644
index 000000000..7f7fccbfd
--- /dev/null
+++ b/tests/stm32/src/bin/gpio.rs
@@ -0,0 +1,79 @@
1#![no_std]
2#![no_main]
3#![feature(type_alias_impl_trait)]
4
5#[path = "../example_common.rs"]
6mod example_common;
7use defmt::assert;
8use embassy::executor::Spawner;
9use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
10use embassy_stm32::Peripherals;
11use embedded_hal::digital::v2::{InputPin, OutputPin};
12use example_common::*;
13
14#[embassy::main]
15async fn main(_spawner: Spawner, p: Peripherals) {
16 info!("Hello World!");
17
18 let (mut a, mut b) = (p.PG14, p.PG9);
19
20 // Test initial output
21 {
22 let b = Input::new(&mut b, Pull::None);
23
24 {
25 let _a = Output::new(&mut a, Level::Low, Speed::Low);
26 cortex_m::asm::delay(1000);
27 assert!(b.is_low().unwrap());
28 }
29 {
30 let _a = Output::new(&mut a, Level::High, Speed::Low);
31 cortex_m::asm::delay(1000);
32 assert!(b.is_high().unwrap());
33 }
34 }
35
36 // Test input no pull
37 {
38 let b = Input::new(&mut b, Pull::None);
39 // no pull, the status is undefined
40
41 let mut a = Output::new(&mut a, Level::Low, Speed::Low);
42 cortex_m::asm::delay(1000);
43 assert!(b.is_low().unwrap());
44 a.set_high().unwrap();
45 cortex_m::asm::delay(1000);
46 assert!(b.is_high().unwrap());
47 }
48
49 // Test input pulldown
50 {
51 let b = Input::new(&mut b, Pull::Down);
52 cortex_m::asm::delay(1000);
53 assert!(b.is_low().unwrap());
54
55 let mut a = Output::new(&mut a, Level::Low, Speed::Low);
56 cortex_m::asm::delay(1000);
57 assert!(b.is_low().unwrap());
58 a.set_high().unwrap();
59 cortex_m::asm::delay(1000);
60 assert!(b.is_high().unwrap());
61 }
62
63 // Test input pullup
64 {
65 let b = Input::new(&mut b, Pull::Up);
66 cortex_m::asm::delay(1000);
67 assert!(b.is_high().unwrap());
68
69 let mut a = Output::new(&mut a, Level::Low, Speed::Low);
70 cortex_m::asm::delay(1000);
71 assert!(b.is_low().unwrap());
72 a.set_high().unwrap();
73 cortex_m::asm::delay(1000);
74 assert!(b.is_high().unwrap());
75 }
76
77 info!("Test OK");
78 cortex_m::asm::bkpt();
79}
diff --git a/tests/stm32/src/example_common.rs b/tests/stm32/src/example_common.rs
new file mode 100644
index 000000000..54d633837
--- /dev/null
+++ b/tests/stm32/src/example_common.rs
@@ -0,0 +1,17 @@
1#![macro_use]
2
3use defmt_rtt as _; // global logger
4use panic_probe as _;
5
6pub use defmt::*;
7
8use core::sync::atomic::{AtomicUsize, Ordering};
9
10defmt::timestamp! {"{=u64}", {
11 static COUNT: AtomicUsize = AtomicUsize::new(0);
12 // NOTE(no-CAS) `timestamps` runs with interrupts disabled
13 let n = COUNT.load(Ordering::Relaxed);
14 COUNT.store(n + 1, Ordering::Relaxed);
15 n as u64
16 }
17}