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; use embedded_hal::digital::v2::{InputPin, OutputPin}; use example_common::*; -#[embassy::main] +#[embassy::main(config = "config()")] async fn main(_spawner: Spawner, p: Peripherals) { info!("Hello World!"); @@ -34,12 +34,12 @@ async fn main(_spawner: Spawner, p: Peripherals) { { let _a = Output::new(&mut a, Level::Low, Speed::Low); - cortex_m::asm::delay(1000); + delay(); assert!(b.is_low().unwrap()); } { let _a = Output::new(&mut a, Level::High, Speed::Low); - cortex_m::asm::delay(1000); + delay(); assert!(b.is_high().unwrap()); } } @@ -50,41 +50,48 @@ async fn main(_spawner: Spawner, p: Peripherals) { // no pull, the status is undefined let mut a = Output::new(&mut a, Level::Low, Speed::Low); - cortex_m::asm::delay(1000); + delay(); assert!(b.is_low().unwrap()); a.set_high().unwrap(); - cortex_m::asm::delay(1000); + delay(); assert!(b.is_high().unwrap()); } // Test input pulldown { let b = Input::new(&mut b, Pull::Down); - cortex_m::asm::delay(1000); + delay(); assert!(b.is_low().unwrap()); let mut a = Output::new(&mut a, Level::Low, Speed::Low); - cortex_m::asm::delay(1000); + delay(); assert!(b.is_low().unwrap()); a.set_high().unwrap(); - cortex_m::asm::delay(1000); + delay(); assert!(b.is_high().unwrap()); } // Test input pullup { let b = Input::new(&mut b, Pull::Up); - cortex_m::asm::delay(1000); + delay(); assert!(b.is_high().unwrap()); let mut a = Output::new(&mut a, Level::Low, Speed::Low); - cortex_m::asm::delay(1000); + delay(); assert!(b.is_low().unwrap()); a.set_high().unwrap(); - cortex_m::asm::delay(1000); + delay(); assert!(b.is_high().unwrap()); } info!("Test OK"); cortex_m::asm::bkpt(); } + +fn delay() { + #[cfg(feature = "stm32h755zi")] + cortex_m::asm::delay(10000); + #[cfg(not(feature = "stm32h755zi"))] + cortex_m::asm::delay(1000); +} 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 @@ +#![no_std] +#![no_main] +#![feature(type_alias_impl_trait)] + +#[path = "../example_common.rs"] +mod example_common; +use defmt::assert_eq; +use embassy::executor::Spawner; +use embassy_stm32::dma::NoDma; +use embassy_stm32::spi::{self, Spi}; +use embassy_stm32::time::Hertz; +use embassy_stm32::Peripherals; +use embedded_hal::blocking::spi::Transfer; +use example_common::*; + +#[embassy::main(config = "config()")] +async fn main(_spawner: Spawner, p: Peripherals) { + info!("Hello World!"); + + #[cfg(not(feature = "stm32h755zi"))] + let (sck, mosi, miso) = (p.PA5, p.PA7, p.PA6); + #[cfg(feature = "stm32h755zi")] + let (sck, mosi, miso) = (p.PA5, p.PB5, p.PA6); + + let mut spi = Spi::new( + p.SPI1, + sck, // Arduino D13 + mosi, // Arduino D11 + miso, // Arduino D12 + NoDma, + NoDma, + Hertz(1_000_000), + spi::Config::default(), + ); + + let data: [u8; 9] = [0x00, 0xFF, 0xAA, 0x55, 0xC0, 0xFF, 0xEE, 0xC0, 0xDE]; + + // Arduino pins D11 and D12 (MOSI-MISO) are connected together with a 1K resistor. + // so we should get the data we sent back. + let mut buf = data; + spi.transfer(&mut buf).unwrap(); + assert_eq!(buf, data); + + info!("Test OK"); + cortex_m::asm::bkpt(); +} 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}; use embassy_stm32::Peripherals; use example_common::*; -#[embassy::main] +#[embassy::main(config = "config()")] async fn main(_spawner: Spawner, _p: Peripherals) { info!("Hello World!"); 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 @@ #![macro_use] -use defmt_rtt as _; // global logger +use defmt_rtt as _; +#[allow(unused)] +use embassy_stm32::time::Hertz; +use embassy_stm32::Config; use panic_probe as _; pub use defmt::*; @@ -15,3 +18,16 @@ defmt::timestamp! {"{=u64}", { n as u64 } } + +pub fn config() -> Config { + #[allow(unused_mut)] + let mut config = Config::default(); + + #[cfg(feature = "stm32h755zi")] + { + config.rcc.sys_ck = Some(Hertz(400_000_000)); + config.rcc.pll1.q_ck = Some(Hertz(100_000_000)); + } + + config +}