diff options
| -rw-r--r-- | tests/stm32/src/bin/gpio.rs | 29 | ||||
| -rw-r--r-- | tests/stm32/src/bin/spi.rs | 46 | ||||
| -rw-r--r-- | tests/stm32/src/bin/timer.rs | 2 | ||||
| -rw-r--r-- | tests/stm32/src/example_common.rs | 18 |
4 files changed, 82 insertions, 13 deletions
diff --git a/tests/stm32/src/bin/gpio.rs b/tests/stm32/src/bin/gpio.rs index f276ce7f4..51ede6cea 100644 --- a/tests/stm32/src/bin/gpio.rs +++ b/tests/stm32/src/bin/gpio.rs | |||
| @@ -11,7 +11,7 @@ use embassy_stm32::Peripherals; | |||
| 11 | use embedded_hal::digital::v2::{InputPin, OutputPin}; | 11 | use embedded_hal::digital::v2::{InputPin, OutputPin}; |
| 12 | use example_common::*; | 12 | use example_common::*; |
| 13 | 13 | ||
| 14 | #[embassy::main] | 14 | #[embassy::main(config = "config()")] |
| 15 | async fn main(_spawner: Spawner, p: Peripherals) { | 15 | async fn main(_spawner: Spawner, p: Peripherals) { |
| 16 | info!("Hello World!"); | 16 | info!("Hello World!"); |
| 17 | 17 | ||
| @@ -34,12 +34,12 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 34 | 34 | ||
| 35 | { | 35 | { |
| 36 | let _a = Output::new(&mut a, Level::Low, Speed::Low); | 36 | let _a = Output::new(&mut a, Level::Low, Speed::Low); |
| 37 | cortex_m::asm::delay(1000); | 37 | delay(); |
| 38 | assert!(b.is_low().unwrap()); | 38 | assert!(b.is_low().unwrap()); |
| 39 | } | 39 | } |
| 40 | { | 40 | { |
| 41 | let _a = Output::new(&mut a, Level::High, Speed::Low); | 41 | let _a = Output::new(&mut a, Level::High, Speed::Low); |
| 42 | cortex_m::asm::delay(1000); | 42 | delay(); |
| 43 | assert!(b.is_high().unwrap()); | 43 | assert!(b.is_high().unwrap()); |
| 44 | } | 44 | } |
| 45 | } | 45 | } |
| @@ -50,41 +50,48 @@ async fn main(_spawner: Spawner, p: Peripherals) { | |||
| 50 | // no pull, the status is undefined | 50 | // no pull, the status is undefined |
| 51 | 51 | ||
| 52 | let mut a = Output::new(&mut a, Level::Low, Speed::Low); | 52 | let mut a = Output::new(&mut a, Level::Low, Speed::Low); |
| 53 | cortex_m::asm::delay(1000); | 53 | delay(); |
| 54 | assert!(b.is_low().unwrap()); | 54 | assert!(b.is_low().unwrap()); |
| 55 | a.set_high().unwrap(); | 55 | a.set_high().unwrap(); |
| 56 | cortex_m::asm::delay(1000); | 56 | delay(); |
| 57 | assert!(b.is_high().unwrap()); | 57 | assert!(b.is_high().unwrap()); |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | // Test input pulldown | 60 | // Test input pulldown |
| 61 | { | 61 | { |
| 62 | let b = Input::new(&mut b, Pull::Down); | 62 | let b = Input::new(&mut b, Pull::Down); |
| 63 | cortex_m::asm::delay(1000); | 63 | delay(); |
| 64 | assert!(b.is_low().unwrap()); | 64 | assert!(b.is_low().unwrap()); |
| 65 | 65 | ||
| 66 | let mut a = Output::new(&mut a, Level::Low, Speed::Low); | 66 | let mut a = Output::new(&mut a, Level::Low, Speed::Low); |
| 67 | cortex_m::asm::delay(1000); | 67 | delay(); |
| 68 | assert!(b.is_low().unwrap()); | 68 | assert!(b.is_low().unwrap()); |
| 69 | a.set_high().unwrap(); | 69 | a.set_high().unwrap(); |
| 70 | cortex_m::asm::delay(1000); | 70 | delay(); |
| 71 | assert!(b.is_high().unwrap()); | 71 | assert!(b.is_high().unwrap()); |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | // Test input pullup | 74 | // Test input pullup |
| 75 | { | 75 | { |
| 76 | let b = Input::new(&mut b, Pull::Up); | 76 | let b = Input::new(&mut b, Pull::Up); |
| 77 | cortex_m::asm::delay(1000); | 77 | delay(); |
| 78 | assert!(b.is_high().unwrap()); | 78 | assert!(b.is_high().unwrap()); |
| 79 | 79 | ||
| 80 | let mut a = Output::new(&mut a, Level::Low, Speed::Low); | 80 | let mut a = Output::new(&mut a, Level::Low, Speed::Low); |
| 81 | cortex_m::asm::delay(1000); | 81 | delay(); |
| 82 | assert!(b.is_low().unwrap()); | 82 | assert!(b.is_low().unwrap()); |
| 83 | a.set_high().unwrap(); | 83 | a.set_high().unwrap(); |
| 84 | cortex_m::asm::delay(1000); | 84 | delay(); |
| 85 | assert!(b.is_high().unwrap()); | 85 | assert!(b.is_high().unwrap()); |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | info!("Test OK"); | 88 | info!("Test OK"); |
| 89 | cortex_m::asm::bkpt(); | 89 | cortex_m::asm::bkpt(); |
| 90 | } | 90 | } |
| 91 | |||
| 92 | fn delay() { | ||
| 93 | #[cfg(feature = "stm32h755zi")] | ||
| 94 | cortex_m::asm::delay(10000); | ||
| 95 | #[cfg(not(feature = "stm32h755zi"))] | ||
| 96 | cortex_m::asm::delay(1000); | ||
| 97 | } | ||
diff --git a/tests/stm32/src/bin/spi.rs b/tests/stm32/src/bin/spi.rs new file mode 100644 index 000000000..043505c7b --- /dev/null +++ b/tests/stm32/src/bin/spi.rs | |||
| @@ -0,0 +1,46 @@ | |||
| 1 | #![no_std] | ||
| 2 | #![no_main] | ||
| 3 | #![feature(type_alias_impl_trait)] | ||
| 4 | |||
| 5 | #[path = "../example_common.rs"] | ||
| 6 | mod example_common; | ||
| 7 | use defmt::assert_eq; | ||
| 8 | use embassy::executor::Spawner; | ||
| 9 | use embassy_stm32::dma::NoDma; | ||
| 10 | use embassy_stm32::spi::{self, Spi}; | ||
| 11 | use embassy_stm32::time::Hertz; | ||
| 12 | use embassy_stm32::Peripherals; | ||
| 13 | use embedded_hal::blocking::spi::Transfer; | ||
| 14 | use example_common::*; | ||
| 15 | |||
| 16 | #[embassy::main(config = "config()")] | ||
| 17 | async fn main(_spawner: Spawner, p: Peripherals) { | ||
| 18 | info!("Hello World!"); | ||
| 19 | |||
| 20 | #[cfg(not(feature = "stm32h755zi"))] | ||
| 21 | let (sck, mosi, miso) = (p.PA5, p.PA7, p.PA6); | ||
| 22 | #[cfg(feature = "stm32h755zi")] | ||
| 23 | let (sck, mosi, miso) = (p.PA5, p.PB5, p.PA6); | ||
| 24 | |||
| 25 | let mut spi = Spi::new( | ||
| 26 | p.SPI1, | ||
| 27 | sck, // Arduino D13 | ||
| 28 | mosi, // Arduino D11 | ||
| 29 | miso, // Arduino D12 | ||
| 30 | NoDma, | ||
| 31 | NoDma, | ||
| 32 | Hertz(1_000_000), | ||
| 33 | spi::Config::default(), | ||
| 34 | ); | ||
| 35 | |||
| 36 | let data: [u8; 9] = [0x00, 0xFF, 0xAA, 0x55, 0xC0, 0xFF, 0xEE, 0xC0, 0xDE]; | ||
| 37 | |||
| 38 | // Arduino pins D11 and D12 (MOSI-MISO) are connected together with a 1K resistor. | ||
| 39 | // so we should get the data we sent back. | ||
| 40 | let mut buf = data; | ||
| 41 | spi.transfer(&mut buf).unwrap(); | ||
| 42 | assert_eq!(buf, data); | ||
| 43 | |||
| 44 | info!("Test OK"); | ||
| 45 | cortex_m::asm::bkpt(); | ||
| 46 | } | ||
diff --git a/tests/stm32/src/bin/timer.rs b/tests/stm32/src/bin/timer.rs index de19a22e3..002a8a4d3 100644 --- a/tests/stm32/src/bin/timer.rs +++ b/tests/stm32/src/bin/timer.rs | |||
| @@ -10,7 +10,7 @@ use embassy::time::{Duration, Instant, Timer}; | |||
| 10 | use embassy_stm32::Peripherals; | 10 | use embassy_stm32::Peripherals; |
| 11 | use example_common::*; | 11 | use example_common::*; |
| 12 | 12 | ||
| 13 | #[embassy::main] | 13 | #[embassy::main(config = "config()")] |
| 14 | async fn main(_spawner: Spawner, _p: Peripherals) { | 14 | async fn main(_spawner: Spawner, _p: Peripherals) { |
| 15 | info!("Hello World!"); | 15 | info!("Hello World!"); |
| 16 | 16 | ||
diff --git a/tests/stm32/src/example_common.rs b/tests/stm32/src/example_common.rs index 54d633837..11b11d685 100644 --- a/tests/stm32/src/example_common.rs +++ b/tests/stm32/src/example_common.rs | |||
| @@ -1,6 +1,9 @@ | |||
| 1 | #![macro_use] | 1 | #![macro_use] |
| 2 | 2 | ||
| 3 | use defmt_rtt as _; // global logger | 3 | use defmt_rtt as _; |
| 4 | #[allow(unused)] | ||
| 5 | use embassy_stm32::time::Hertz; | ||
| 6 | use embassy_stm32::Config; | ||
| 4 | use panic_probe as _; | 7 | use panic_probe as _; |
| 5 | 8 | ||
| 6 | pub use defmt::*; | 9 | pub use defmt::*; |
| @@ -15,3 +18,16 @@ defmt::timestamp! {"{=u64}", { | |||
| 15 | n as u64 | 18 | n as u64 |
| 16 | } | 19 | } |
| 17 | } | 20 | } |
| 21 | |||
| 22 | pub fn config() -> Config { | ||
| 23 | #[allow(unused_mut)] | ||
| 24 | let mut config = Config::default(); | ||
| 25 | |||
| 26 | #[cfg(feature = "stm32h755zi")] | ||
| 27 | { | ||
| 28 | config.rcc.sys_ck = Some(Hertz(400_000_000)); | ||
| 29 | config.rcc.pll1.q_ck = Some(Hertz(100_000_000)); | ||
| 30 | } | ||
| 31 | |||
| 32 | config | ||
| 33 | } | ||
