aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2024-05-31 22:16:30 +0200
committerDario Nieuwenhuis <[email protected]>2024-05-31 22:58:53 +0200
commit339dd859686caee4ed55ed1f3cba0320e085db39 (patch)
treec72e264154acf6ff4e80b92080e8eab7f8309e18
parent7baa14371b3ee97b7008e2613489b07942d32582 (diff)
stm32/spi: restrict txonly_nosck to SPIv1, it hangs in other versions.
-rw-r--r--embassy-stm32/src/spi/mod.rs2
-rw-r--r--examples/stm32g0/src/bin/spi_neopixel.rs2
-rw-r--r--tests/stm32/Cargo.toml30
-rw-r--r--tests/stm32/src/bin/spi.rs50
-rw-r--r--tests/stm32/src/bin/spi_dma.rs56
5 files changed, 94 insertions, 46 deletions
diff --git a/embassy-stm32/src/spi/mod.rs b/embassy-stm32/src/spi/mod.rs
index 3729ed8de..5d6277c33 100644
--- a/embassy-stm32/src/spi/mod.rs
+++ b/embassy-stm32/src/spi/mod.rs
@@ -465,6 +465,7 @@ impl<'d> Spi<'d, Blocking> {
465 /// Create a new SPI driver, in TX-only mode, without SCK pin. 465 /// Create a new SPI driver, in TX-only mode, without SCK pin.
466 /// 466 ///
467 /// This can be useful for bit-banging non-SPI protocols. 467 /// This can be useful for bit-banging non-SPI protocols.
468 #[cfg(any(spi_v1, spi_f1))] // no SCK pin causes it to hang on spiv2+ for unknown reasons.
468 pub fn new_blocking_txonly_nosck<T: Instance>( 469 pub fn new_blocking_txonly_nosck<T: Instance>(
469 peri: impl Peripheral<P = T> + 'd, 470 peri: impl Peripheral<P = T> + 'd,
470 mosi: impl Peripheral<P = impl MosiPin<T>> + 'd, 471 mosi: impl Peripheral<P = impl MosiPin<T>> + 'd,
@@ -549,6 +550,7 @@ impl<'d> Spi<'d, Async> {
549 /// Create a new SPI driver, in TX-only mode, without SCK pin. 550 /// Create a new SPI driver, in TX-only mode, without SCK pin.
550 /// 551 ///
551 /// This can be useful for bit-banging non-SPI protocols. 552 /// This can be useful for bit-banging non-SPI protocols.
553 #[cfg(any(spi_v1, spi_f1))] // no SCK pin causes it to hang on spiv2+ for unknown reasons.
552 pub fn new_txonly_nosck<T: Instance>( 554 pub fn new_txonly_nosck<T: Instance>(
553 peri: impl Peripheral<P = T> + 'd, 555 peri: impl Peripheral<P = T> + 'd,
554 mosi: impl Peripheral<P = impl MosiPin<T>> + 'd, 556 mosi: impl Peripheral<P = impl MosiPin<T>> + 'd,
diff --git a/examples/stm32g0/src/bin/spi_neopixel.rs b/examples/stm32g0/src/bin/spi_neopixel.rs
index 2deee271d..edcae74f7 100644
--- a/examples/stm32g0/src/bin/spi_neopixel.rs
+++ b/examples/stm32g0/src/bin/spi_neopixel.rs
@@ -76,7 +76,7 @@ async fn main(_spawner: Spawner) {
76 76
77 let mut config = Config::default(); 77 let mut config = Config::default();
78 config.frequency = Hertz(4_000_000); 78 config.frequency = Hertz(4_000_000);
79 let mut spi = Spi::new_txonly_nosck(p.SPI1, p.PB5, p.DMA1_CH3, config); 79 let mut spi = Spi::new_txonly(p.SPI1, p.PB3, p.PB5, p.DMA1_CH3, config); // SCK is unused.
80 80
81 let mut neopixels = Ws2812::new(); 81 let mut neopixels = Ws2812::new();
82 82
diff --git a/tests/stm32/Cargo.toml b/tests/stm32/Cargo.toml
index f6d1d98eb..de390ee38 100644
--- a/tests/stm32/Cargo.toml
+++ b/tests/stm32/Cargo.toml
@@ -7,34 +7,36 @@ autobins = false
7 7
8[features] 8[features]
9stm32c031c6 = ["embassy-stm32/stm32c031c6", "cm0", "not-gpdma"] 9stm32c031c6 = ["embassy-stm32/stm32c031c6", "cm0", "not-gpdma"]
10stm32f103c8 = ["embassy-stm32/stm32f103c8", "not-gpdma"] 10stm32f103c8 = ["embassy-stm32/stm32f103c8", "spi-v1", "not-gpdma"]
11stm32f207zg = ["embassy-stm32/stm32f207zg", "chrono", "not-gpdma", "eth", "rng"] 11stm32f207zg = ["embassy-stm32/stm32f207zg", "spi-v1", "chrono", "not-gpdma", "eth", "rng"]
12stm32f303ze = ["embassy-stm32/stm32f303ze", "chrono", "not-gpdma"] 12stm32f303ze = ["embassy-stm32/stm32f303ze", "chrono", "not-gpdma"]
13stm32f429zi = ["embassy-stm32/stm32f429zi", "chrono", "eth", "stop", "can", "not-gpdma", "dac", "rng"] 13stm32f429zi = ["embassy-stm32/stm32f429zi", "spi-v1", "chrono", "eth", "stop", "can", "not-gpdma", "dac", "rng"]
14stm32f446re = ["embassy-stm32/stm32f446re", "chrono", "stop", "can", "not-gpdma", "dac", "sdmmc"] 14stm32f446re = ["embassy-stm32/stm32f446re", "spi-v1", "chrono", "stop", "can", "not-gpdma", "dac", "sdmmc"]
15stm32f767zi = ["embassy-stm32/stm32f767zi", "chrono", "not-gpdma", "eth", "rng"] 15stm32f767zi = ["embassy-stm32/stm32f767zi", "chrono", "not-gpdma", "eth", "rng"]
16stm32g071rb = ["embassy-stm32/stm32g071rb", "cm0", "not-gpdma", "dac", "ucpd"] 16stm32g071rb = ["embassy-stm32/stm32g071rb", "cm0", "not-gpdma", "dac", "ucpd"]
17stm32g491re = ["embassy-stm32/stm32g491re", "chrono", "stop", "not-gpdma", "rng", "fdcan", "cordic"] 17stm32g491re = ["embassy-stm32/stm32g491re", "chrono", "stop", "not-gpdma", "rng", "fdcan", "cordic"]
18stm32h563zi = ["embassy-stm32/stm32h563zi", "chrono", "eth", "rng", "fdcan", "hash", "cordic", "stop"] 18stm32h563zi = ["embassy-stm32/stm32h563zi", "spi-v345", "chrono", "eth", "rng", "fdcan", "hash", "cordic", "stop"]
19stm32h753zi = ["embassy-stm32/stm32h753zi", "chrono", "not-gpdma", "eth", "rng", "fdcan", "hash", "cryp"] 19stm32h753zi = ["embassy-stm32/stm32h753zi", "spi-v345", "chrono", "not-gpdma", "eth", "rng", "fdcan", "hash", "cryp"]
20stm32h755zi = ["embassy-stm32/stm32h755zi-cm7", "chrono", "not-gpdma", "eth", "dac", "rng", "fdcan", "hash", "cryp"] 20stm32h755zi = ["embassy-stm32/stm32h755zi-cm7", "spi-v345", "chrono", "not-gpdma", "eth", "dac", "rng", "fdcan", "hash", "cryp"]
21stm32h7a3zi = ["embassy-stm32/stm32h7a3zi", "not-gpdma", "rng", "fdcan"] 21stm32h7a3zi = ["embassy-stm32/stm32h7a3zi", "spi-v345", "not-gpdma", "rng", "fdcan"]
22stm32l073rz = ["embassy-stm32/stm32l073rz", "cm0", "not-gpdma", "rng"] 22stm32l073rz = ["embassy-stm32/stm32l073rz", "cm0", "not-gpdma", "rng"]
23stm32l152re = ["embassy-stm32/stm32l152re", "chrono", "not-gpdma"] 23stm32l152re = ["embassy-stm32/stm32l152re", "spi-v1", "chrono", "not-gpdma"]
24stm32l496zg = ["embassy-stm32/stm32l496zg", "not-gpdma", "rng"] 24stm32l496zg = ["embassy-stm32/stm32l496zg", "not-gpdma", "rng"]
25stm32l4a6zg = ["embassy-stm32/stm32l4a6zg", "chrono", "not-gpdma", "rng", "hash"] 25stm32l4a6zg = ["embassy-stm32/stm32l4a6zg", "chrono", "not-gpdma", "rng", "hash"]
26stm32l4r5zi = ["embassy-stm32/stm32l4r5zi", "chrono", "not-gpdma", "rng"] 26stm32l4r5zi = ["embassy-stm32/stm32l4r5zi", "chrono", "not-gpdma", "rng"]
27stm32l552ze = ["embassy-stm32/stm32l552ze", "not-gpdma", "rng", "hash"] 27stm32l552ze = ["embassy-stm32/stm32l552ze", "not-gpdma", "rng", "hash"]
28stm32u585ai = ["embassy-stm32/stm32u585ai", "chrono", "rng", "hash", "cordic"] 28stm32u585ai = ["embassy-stm32/stm32u585ai", "spi-v345", "chrono", "rng", "hash", "cordic"]
29stm32u5a5zj = ["embassy-stm32/stm32u5a5zj", "chrono", "rng", "hash"] # FIXME: cordic test cause it crash 29stm32u5a5zj = ["embassy-stm32/stm32u5a5zj", "spi-v345", "chrono", "rng", "hash"] # FIXME: cordic test cause it crash
30stm32wb55rg = ["embassy-stm32/stm32wb55rg", "chrono", "not-gpdma", "ble", "mac" , "rng"] 30stm32wb55rg = ["embassy-stm32/stm32wb55rg", "chrono", "not-gpdma", "ble", "mac" , "rng"]
31stm32wba52cg = ["embassy-stm32/stm32wba52cg", "chrono", "rng", "hash"] 31stm32wba52cg = ["embassy-stm32/stm32wba52cg", "spi-v345", "chrono", "rng", "hash"]
32stm32wl55jc = ["embassy-stm32/stm32wl55jc-cm4", "not-gpdma", "rng", "chrono"] 32stm32wl55jc = ["embassy-stm32/stm32wl55jc-cm4", "not-gpdma", "rng", "chrono"]
33stm32f091rc = ["embassy-stm32/stm32f091rc", "cm0", "not-gpdma", "chrono"] 33stm32f091rc = ["embassy-stm32/stm32f091rc", "cm0", "not-gpdma", "chrono"]
34stm32h503rb = ["embassy-stm32/stm32h503rb", "rng", "stop"] 34stm32h503rb = ["embassy-stm32/stm32h503rb", "spi-v345", "rng", "stop"]
35stm32h7s3l8 = ["embassy-stm32/stm32h7s3l8", "rng", "cordic", "hash"] # TODO: fdcan crashes, cryp dma hangs. 35stm32h7s3l8 = ["embassy-stm32/stm32h7s3l8", "spi-v345", "rng", "cordic", "hash"] # TODO: fdcan crashes, cryp dma hangs.
36stm32u083rc = ["embassy-stm32/stm32u083rc", "cm0", "rng", "chrono"] 36stm32u083rc = ["embassy-stm32/stm32u083rc", "cm0", "rng", "chrono"]
37 37
38spi-v1 = []
39spi-v345 = []
38cryp = [] 40cryp = []
39hash = [] 41hash = []
40eth = ["embassy-executor/task-arena-size-16384"] 42eth = ["embassy-executor/task-arena-size-16384"]
diff --git a/tests/stm32/src/bin/spi.rs b/tests/stm32/src/bin/spi.rs
index a0ca5284d..0d670b7c1 100644
--- a/tests/stm32/src/bin/spi.rs
+++ b/tests/stm32/src/bin/spi.rs
@@ -62,27 +62,49 @@ async fn main(_spawner: Spawner) {
62 62
63 // Assert the RCC bit gets disabled on drop. 63 // Assert the RCC bit gets disabled on drop.
64 #[cfg(feature = "stm32f429zi")] 64 #[cfg(feature = "stm32f429zi")]
65 { 65 defmt::assert!(embassy_stm32::pac::RCC.apb2enr().read().spi1en());
66 defmt::assert!(embassy_stm32::pac::RCC.apb2enr().read().spi1en()); 66 drop(spi);
67 drop(spi); 67 #[cfg(feature = "stm32f429zi")]
68 defmt::assert!(!embassy_stm32::pac::RCC.apb2enr().read().spi1en()); 68 defmt::assert!(!embassy_stm32::pac::RCC.apb2enr().read().spi1en());
69 }
70
71 #[cfg(not(feature = "stm32f429zi"))]
72 core::mem::drop(spi);
73 69
74 // test rx-only configuration 70 // test rx-only configuration
75 let mut spi = Spi::new_blocking_rxonly(&mut spi_peri, &mut sck, &mut miso, spi_config); 71 let mut spi = Spi::new_blocking_rxonly(&mut spi_peri, &mut sck, &mut miso, spi_config);
76 72 let mut mosi_out = Output::new(&mut mosi, Level::Low, Speed::VeryHigh);
77 let mut mosi = Output::new(&mut mosi, Level::Low, Speed::VeryHigh); 73 mosi_out.set_high();
78
79 mosi.set_high();
80 spi.blocking_read(&mut buf).unwrap(); 74 spi.blocking_read(&mut buf).unwrap();
81 assert_eq!(buf, [0xff; 9]); 75 assert_eq!(buf, [0xff; 9]);
82 76 mosi_out.set_low();
83 mosi.set_low();
84 spi.blocking_read(&mut buf).unwrap(); 77 spi.blocking_read(&mut buf).unwrap();
85 assert_eq!(buf, [0x00; 9]); 78 assert_eq!(buf, [0x00; 9]);
79 drop(mosi_out);
80 drop(spi);
81
82 // Test tx-only. Just check it doesn't hang, not much else we can do without using SPI slave.
83 let mut spi = Spi::new_blocking_txonly(&mut spi_peri, &mut sck, &mut mosi, spi_config);
84 spi.blocking_transfer(&mut buf, &data).unwrap();
85 spi.blocking_transfer_in_place(&mut buf).unwrap();
86 spi.blocking_write(&buf).unwrap();
87 spi.blocking_read(&mut buf).unwrap();
88 spi.blocking_transfer::<u8>(&mut [], &[]).unwrap();
89 spi.blocking_transfer_in_place::<u8>(&mut []).unwrap();
90 spi.blocking_read::<u8>(&mut []).unwrap();
91 spi.blocking_write::<u8>(&[]).unwrap();
92 drop(spi);
93
94 // Test tx-only nosck.
95 #[cfg(feature = "spi-v1")]
96 {
97 let mut spi = Spi::new_blocking_txonly_nosck(&mut spi_peri, &mut mosi, spi_config);
98 spi.blocking_transfer(&mut buf, &data).unwrap();
99 spi.blocking_transfer_in_place(&mut buf).unwrap();
100 spi.blocking_write(&buf).unwrap();
101 spi.blocking_read(&mut buf).unwrap();
102 spi.blocking_transfer::<u8>(&mut [], &[]).unwrap();
103 spi.blocking_transfer_in_place::<u8>(&mut []).unwrap();
104 spi.blocking_read::<u8>(&mut []).unwrap();
105 spi.blocking_write::<u8>(&[]).unwrap();
106 drop(spi);
107 }
86 108
87 info!("Test OK"); 109 info!("Test OK");
88 cortex_m::asm::bkpt(); 110 cortex_m::asm::bkpt();
diff --git a/tests/stm32/src/bin/spi_dma.rs b/tests/stm32/src/bin/spi_dma.rs
index 92f741af5..0cd3690ec 100644
--- a/tests/stm32/src/bin/spi_dma.rs
+++ b/tests/stm32/src/bin/spi_dma.rs
@@ -88,31 +88,53 @@ async fn main(_spawner: Spawner) {
88 &mut sck, 88 &mut sck,
89 &mut miso, 89 &mut miso,
90 // SPIv1/f1 requires txdma even if rxonly. 90 // SPIv1/f1 requires txdma even if rxonly.
91 #[cfg(not(any( 91 #[cfg(not(feature = "spi-v345"))]
92 feature = "stm32h503rb",
93 feature = "stm32h563zi",
94 feature = "stm32h753zi",
95 feature = "stm32h755zi",
96 feature = "stm32h7a3zi",
97 feature = "stm32h7s3l8",
98 feature = "stm32u585ai",
99 feature = "stm32u5a5zj",
100 feature = "stm32wba52cg",
101 )))]
102 &mut tx_dma, 92 &mut tx_dma,
103 &mut rx_dma, 93 &mut rx_dma,
104 spi_config, 94 spi_config,
105 ); 95 );
106 96 let mut mosi_out = Output::new(&mut mosi, Level::Low, Speed::VeryHigh);
107 let mut mosi = Output::new(&mut mosi, Level::Low, Speed::VeryHigh); 97 mosi_out.set_high();
108
109 mosi.set_high();
110 spi.read(&mut buf).await.unwrap(); 98 spi.read(&mut buf).await.unwrap();
111 assert_eq!(buf, [0xff; 9]); 99 assert_eq!(buf, [0xff; 9]);
112 100 spi.blocking_read(&mut buf).unwrap();
113 mosi.set_low(); 101 assert_eq!(buf, [0xff; 9]);
102 spi.read(&mut buf).await.unwrap();
103 assert_eq!(buf, [0xff; 9]);
104 spi.read(&mut buf).await.unwrap();
105 assert_eq!(buf, [0xff; 9]);
106 spi.blocking_read(&mut buf).unwrap();
107 assert_eq!(buf, [0xff; 9]);
108 spi.blocking_read(&mut buf).unwrap();
109 assert_eq!(buf, [0xff; 9]);
110 mosi_out.set_low();
114 spi.read(&mut buf).await.unwrap(); 111 spi.read(&mut buf).await.unwrap();
115 assert_eq!(buf, [0x00; 9]); 112 assert_eq!(buf, [0x00; 9]);
113 drop(mosi_out);
114 drop(spi);
115
116 // Test tx-only. Just check it doesn't hang, not much else we can do without using SPI slave.
117 let mut spi = Spi::new_txonly(&mut spi_peri, &mut sck, &mut mosi, &mut tx_dma, spi_config);
118 spi.blocking_write(&buf).unwrap();
119 spi.write(&buf).await.unwrap();
120 spi.blocking_write(&buf).unwrap();
121 spi.blocking_write(&buf).unwrap();
122 spi.write(&buf).await.unwrap();
123 spi.write(&buf).await.unwrap();
124 drop(spi);
125
126 // Test tx-only nosck.
127 #[cfg(feature = "spi-v1")]
128 {
129 let mut spi = Spi::new_txonly_nosck(&mut spi_peri, &mut mosi, &mut tx_dma, spi_config);
130 spi.blocking_write(&buf).unwrap();
131 spi.write(&buf).await.unwrap();
132 spi.blocking_write(&buf).unwrap();
133 spi.blocking_write(&buf).unwrap();
134 spi.write(&buf).await.unwrap();
135 spi.write(&buf).await.unwrap();
136 drop(spi);
137 }
116 138
117 info!("Test OK"); 139 info!("Test OK");
118 cortex_m::asm::bkpt(); 140 cortex_m::asm::bkpt();