Skip to content

Commit 01f1f41

Browse files
committed
spi: update spi-dma demo to use latest APIs
1 parent 65176cd commit 01f1f41

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

examples/spi-dma.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//!
33
//! For more docs, see https://docs.rs/stm32h7xx-hal/latest/stm32h5xx_hal/spi/index.html
44
//!
5-
#![deny(warnings)]
5+
// #![deny(warnings)]
66
#![no_main]
77
#![no_std]
88

@@ -12,10 +12,13 @@ use core::mem::MaybeUninit;
1212

1313
use cortex_m_rt::entry;
1414
use cortex_m_semihosting::debug;
15+
use embedded_hal::delay::DelayNs;
1516
use stm32h5xx_hal::{
17+
delay::Delay,
1618
pac,
1719
prelude::*,
1820
spi::{self, Config as SpiConfig},
21+
time::MilliSeconds,
1922
};
2023

2124
static mut SOURCE_BYTES: MaybeUninit<[u8; 40]> = MaybeUninit::uninit();
@@ -47,6 +50,7 @@ fn u8_buf_pair() -> (&'static [u8; 40], &'static mut [u8; 40]) {
4750
fn main() -> ! {
4851
utilities::logger::init();
4952

53+
let cp = cortex_m::Peripherals::take().unwrap();
5054
let dp = pac::Peripherals::take().unwrap();
5155

5256
// Select highest power mode for max possible clock frequency
@@ -90,14 +94,20 @@ fn main() -> ! {
9094

9195
let mut spi = spi.use_dma_duplex(tx_ch, rx_ch);
9296

93-
let (tx, rx) = spi.start_dma_duplex_transfer(dest_buf, source_buf).unwrap();
94-
tx.wait_for_transfer_complete().unwrap();
95-
rx.wait_for_transfer_complete().unwrap();
97+
let mut delay = Delay::new(cp.SYST, &ccdr.clocks);
98+
let duration = MilliSeconds::secs(1).to_millis();
9699

97-
assert_eq!(source_buf, dest_buf);
98-
99-
log::info!("Success!");
100100
loop {
101-
debug::exit(debug::EXIT_SUCCESS)
101+
let (tx, rx) =
102+
spi.start_dma_duplex_transfer(dest_buf, source_buf).unwrap();
103+
104+
tx.wait_for_transfer_complete().unwrap();
105+
rx.wait_for_transfer_complete().unwrap();
106+
107+
spi.finish_transfer(Ok(())).unwrap();
108+
assert_eq!(source_buf, dest_buf);
109+
110+
log::info!("Success!");
111+
delay.delay_ms(duration);
102112
}
103113
}

0 commit comments

Comments
 (0)