aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/rp/src/bin/spi_async.rs44
1 files changed, 40 insertions, 4 deletions
diff --git a/tests/rp/src/bin/spi_async.rs b/tests/rp/src/bin/spi_async.rs
index 6c85ef60a..e3fe6e84c 100644
--- a/tests/rp/src/bin/spi_async.rs
+++ b/tests/rp/src/bin/spi_async.rs
@@ -1,3 +1,6 @@
1//! Make sure to connect GPIO pins 3 (`PIN_3`) and 4 (`PIN_4`) together
2//! to run this test.
3//!
1#![no_std] 4#![no_std]
2#![no_main] 5#![no_main]
3#![feature(type_alias_impl_trait)] 6#![feature(type_alias_impl_trait)]
@@ -18,10 +21,43 @@ async fn main(_spawner: Spawner) {
18 21
19 let mut spi = Spi::new(p.SPI0, clk, mosi, miso, p.DMA_CH0, p.DMA_CH1, Config::default()); 22 let mut spi = Spi::new(p.SPI0, clk, mosi, miso, p.DMA_CH0, p.DMA_CH1, Config::default());
20 23
21 let tx_buf = [1_u8, 2, 3, 4, 5, 6]; 24 // equal rx & tx buffers
22 let mut rx_buf = [0_u8; 6]; 25 {
23 spi.transfer(&mut rx_buf, &tx_buf).await.unwrap(); 26 let tx_buf = [1_u8, 2, 3, 4, 5, 6];
24 assert_eq!(rx_buf, tx_buf); 27 let mut rx_buf = [0_u8; 6];
28 spi.transfer(&mut rx_buf, &tx_buf).await.unwrap();
29 assert_eq!(rx_buf, tx_buf);
30 }
31
32 // tx > rx buffer
33 {
34 let tx_buf = [7_u8, 8, 9, 10, 11, 12];
35
36 let mut rx_buf = [0_u8, 3];
37 spi.transfer(&mut rx_buf, &tx_buf).await.unwrap();
38 assert_eq!(rx_buf, tx_buf[..3]);
39 }
40
41 // we make sure to that clearing FIFO works after the uneven buffers
42
43 // equal rx & tx buffers
44 {
45 let tx_buf = [13_u8, 14, 15, 16, 17, 18];
46 let mut rx_buf = [0_u8; 6];
47 spi.transfer(&mut rx_buf, &tx_buf).await.unwrap();
48
49 assert_eq!(rx_buf, tx_buf);
50 }
51
52 // rx > tx buffer
53 {
54 let tx_buf = [19_u8, 20, 21];
55 let mut rx_buf = [0_u8; 6];
56 spi.transfer(&mut rx_buf, &tx_buf).await.unwrap();
57
58 assert_eq!(rx_buf[..3], tx_buf, "only the first 3 TX bytes should have been received in the RX buffer");
59 assert_eq!(rx_buf[3..], [0, 0, 0], "the rest of the RX bytes should be empty");
60 }
25 61
26 info!("Test OK"); 62 info!("Test OK");
27 cortex_m::asm::bkpt(); 63 cortex_m::asm::bkpt();