diff --git a/tests/stm32/src/bin/spi.rs b/tests/stm32/src/bin/spi.rs index c1576bfeb..a0ca5284d 100644 --- a/tests/stm32/src/bin/spi.rs +++ b/tests/stm32/src/bin/spi.rs @@ -6,6 +6,7 @@ mod common; use common::*; use defmt::assert_eq; use embassy_executor::Spawner; +use embassy_stm32::gpio::{Level, Output, Speed}; use embassy_stm32::spi::{self, Spi}; use embassy_stm32::time::Hertz; @@ -14,18 +15,19 @@ async fn main(_spawner: Spawner) { let p = embassy_stm32::init(config()); info!("Hello World!"); - let spi = peri!(p, SPI); - let sck = peri!(p, SPI_SCK); - let mosi = peri!(p, SPI_MOSI); - let miso = peri!(p, SPI_MISO); + let mut spi_peri = peri!(p, SPI); + let mut sck = peri!(p, SPI_SCK); + let mut mosi = peri!(p, SPI_MOSI); + let mut miso = peri!(p, SPI_MISO); let mut spi_config = spi::Config::default(); spi_config.frequency = Hertz(1_000_000); let mut spi = Spi::new_blocking( - spi, sck, // Arduino D13 - mosi, // Arduino D11 - miso, // Arduino D12 + &mut spi_peri, + &mut sck, // Arduino D13 + &mut mosi, // Arduino D11 + &mut miso, // Arduino D12 spi_config, ); @@ -66,6 +68,22 @@ async fn main(_spawner: Spawner) { defmt::assert!(!embassy_stm32::pac::RCC.apb2enr().read().spi1en()); } + #[cfg(not(feature = "stm32f429zi"))] + core::mem::drop(spi); + + // test rx-only configuration + let mut spi = Spi::new_blocking_rxonly(&mut spi_peri, &mut sck, &mut miso, spi_config); + + let mut mosi = Output::new(&mut mosi, Level::Low, Speed::VeryHigh); + + mosi.set_high(); + spi.blocking_read(&mut buf).unwrap(); + assert_eq!(buf, [0xff; 9]); + + mosi.set_low(); + spi.blocking_read(&mut buf).unwrap(); + assert_eq!(buf, [0x00; 9]); + info!("Test OK"); cortex_m::asm::bkpt(); }