diff --git a/tests/stm32/src/bin/spi_dma.rs b/tests/stm32/src/bin/spi_dma.rs index 5d46726dd..30e679f2a 100644 --- a/tests/stm32/src/bin/spi_dma.rs +++ b/tests/stm32/src/bin/spi_dma.rs @@ -8,27 +8,33 @@ use defmt::assert_eq; use embassy_executor::Spawner; use embassy_stm32::spi::{self, Spi}; use embassy_stm32::time::Hertz; +use embassy_stm32::{into_ref, Peripheral as _}; #[embassy_executor::main] async fn main(_spawner: Spawner) { let p = embassy_stm32::init(config()); info!("Hello World!"); - let spi = peri!(p, SPI); + let spi_peri = peri!(p, SPI); let sck = peri!(p, SPI_SCK); let mosi = peri!(p, SPI_MOSI); let miso = peri!(p, SPI_MISO); let tx_dma = peri!(p, SPI_TX_DMA); let rx_dma = peri!(p, SPI_RX_DMA); + into_ref!(spi_peri, sck, mosi, miso, tx_dma, rx_dma); + let mut spi_config = spi::Config::default(); spi_config.frequency = Hertz(1_000_000); let mut spi = Spi::new( - spi, sck, // Arduino D13 - mosi, // Arduino D11 - miso, // Arduino D12 - tx_dma, rx_dma, spi_config, + spi_peri.reborrow(), + sck.reborrow(), // Arduino D13 + mosi.reborrow(), // Arduino D11 + miso.reborrow(), // Arduino D12 + tx_dma.reborrow(), + rx_dma.reborrow(), + spi_config, ); let data: [u8; 9] = [0x00, 0xFF, 0xAA, 0x55, 0xC0, 0xFF, 0xEE, 0xC0, 0xDE]; @@ -76,6 +82,55 @@ async fn main(_spawner: Spawner) { spi.blocking_read(&mut buf).unwrap(); spi.write(&buf).await.unwrap(); + core::mem::drop(spi); + + // test rx-only configuration + + // stm32f207zg - spi_v1 + // stm32f103c8 - spi_f1 + // stm32g491re - spi_v2 + // stm32h753zi - spi_v3 + // stm32h563zi - spi_v4 + // stm32wba52cg - spi_v5 + + #[cfg(any(stm32f207zg, stm32f103c8, stm32g491re, stm32h753zi, stm32h563zi, stm32wba52cg))] + { + let mut spi = { + #[cfg(stm32f207zg, stm32f103c8, stm32g491re)] + { + Spi::new_rxonly( + spi_peri.reborrow(), + sck.reborrow(), + miso.reborrow(), + tx_dma.reborrow(), + rx_dma.reborrow(), + spi_config, + ) + } + #[cfg(stm32h753zi, stm32h563zi, stm32wba52cg)] + { + Spi::new_rxonly( + spi_peri.reborrow(), + sck.reborrow(), + miso.reborrow(), + rx_dma.reborrow(), + spi_config, + ) + } + }; + + use embassy_stm32::gpio; + let mut mosi = gpio::Output::new(mosi.reborrow(), gpio::Level::Low, gpio::Speed::Low); + + mosi.set_high(); + spi.read(&mut buf).await.unwrap(); + assert_eq!(buf, [0xff; 9]); + + mosi.set_low(); + spi.read(&mut buf).await.unwrap(); + assert_eq!(buf, [0x00; 9]); + }; + info!("Test OK"); cortex_m::asm::bkpt(); }