diff options
| author | Dario Nieuwenhuis <[email protected]> | 2024-05-31 21:02:40 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-05-31 21:02:40 +0000 |
| commit | e61136fa4ab0261ec9d9e262e1c3295d4549fa5f (patch) | |
| tree | b58ea1cf6116ce13988558c302c1b918e0355527 /tests/stm32/src | |
| parent | 7baa14371b3ee97b7008e2613489b07942d32582 (diff) | |
| parent | 8a1658ab0e946b1fb6e91a9b22e92a51b78704ec (diff) | |
Merge pull request #3028 from embassy-rs/check-cfg-fix
stm32/spi: restrict txonly_nosck to SPIv1, it hangs in other versions.
Diffstat (limited to 'tests/stm32/src')
| -rw-r--r-- | tests/stm32/src/bin/spi.rs | 52 | ||||
| -rw-r--r-- | tests/stm32/src/bin/spi_dma.rs | 68 |
2 files changed, 88 insertions, 32 deletions
diff --git a/tests/stm32/src/bin/spi.rs b/tests/stm32/src/bin/spi.rs index a0ca5284d..8be3b1a7c 100644 --- a/tests/stm32/src/bin/spi.rs +++ b/tests/stm32/src/bin/spi.rs | |||
| @@ -62,27 +62,51 @@ 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 | spi.blocking_read::<u8>(&mut []).unwrap(); | ||
| 80 | spi.blocking_read::<u8>(&mut []).unwrap(); | ||
| 81 | drop(mosi_out); | ||
| 82 | drop(spi); | ||
| 83 | |||
| 84 | // Test tx-only. Just check it doesn't hang, not much else we can do without using SPI slave. | ||
| 85 | let mut spi = Spi::new_blocking_txonly(&mut spi_peri, &mut sck, &mut mosi, spi_config); | ||
| 86 | spi.blocking_transfer(&mut buf, &data).unwrap(); | ||
| 87 | spi.blocking_transfer_in_place(&mut buf).unwrap(); | ||
| 88 | spi.blocking_write(&buf).unwrap(); | ||
| 89 | spi.blocking_read(&mut buf).unwrap(); | ||
| 90 | spi.blocking_transfer::<u8>(&mut [], &[]).unwrap(); | ||
| 91 | spi.blocking_transfer_in_place::<u8>(&mut []).unwrap(); | ||
| 92 | spi.blocking_read::<u8>(&mut []).unwrap(); | ||
| 93 | spi.blocking_write::<u8>(&[]).unwrap(); | ||
| 94 | drop(spi); | ||
| 95 | |||
| 96 | // Test tx-only nosck. | ||
| 97 | #[cfg(feature = "spi-v1")] | ||
| 98 | { | ||
| 99 | let mut spi = Spi::new_blocking_txonly_nosck(&mut spi_peri, &mut mosi, spi_config); | ||
| 100 | spi.blocking_transfer(&mut buf, &data).unwrap(); | ||
| 101 | spi.blocking_transfer_in_place(&mut buf).unwrap(); | ||
| 102 | spi.blocking_write(&buf).unwrap(); | ||
| 103 | spi.blocking_read(&mut buf).unwrap(); | ||
| 104 | spi.blocking_transfer::<u8>(&mut [], &[]).unwrap(); | ||
| 105 | spi.blocking_transfer_in_place::<u8>(&mut []).unwrap(); | ||
| 106 | spi.blocking_read::<u8>(&mut []).unwrap(); | ||
| 107 | spi.blocking_write::<u8>(&[]).unwrap(); | ||
| 108 | drop(spi); | ||
| 109 | } | ||
| 86 | 110 | ||
| 87 | info!("Test OK"); | 111 | info!("Test OK"); |
| 88 | cortex_m::asm::bkpt(); | 112 | cortex_m::asm::bkpt(); |
diff --git a/tests/stm32/src/bin/spi_dma.rs b/tests/stm32/src/bin/spi_dma.rs index 92f741af5..a8001a111 100644 --- a/tests/stm32/src/bin/spi_dma.rs +++ b/tests/stm32/src/bin/spi_dma.rs | |||
| @@ -63,8 +63,12 @@ async fn main(_spawner: Spawner) { | |||
| 63 | spi.transfer_in_place::<u8>(&mut []).await.unwrap(); | 63 | spi.transfer_in_place::<u8>(&mut []).await.unwrap(); |
| 64 | spi.read::<u8>(&mut []).await.unwrap(); | 64 | spi.read::<u8>(&mut []).await.unwrap(); |
| 65 | spi.write::<u8>(&[]).await.unwrap(); | 65 | spi.write::<u8>(&[]).await.unwrap(); |
| 66 | spi.blocking_transfer::<u8>(&mut [], &[]).unwrap(); | ||
| 67 | spi.blocking_transfer_in_place::<u8>(&mut []).unwrap(); | ||
| 68 | spi.blocking_read::<u8>(&mut []).unwrap(); | ||
| 69 | spi.blocking_write::<u8>(&[]).unwrap(); | ||
| 66 | 70 | ||
| 67 | // === Check mixing blocking with async. | 71 | // Check mixing blocking with async. |
| 68 | spi.blocking_transfer(&mut buf, &data).unwrap(); | 72 | spi.blocking_transfer(&mut buf, &data).unwrap(); |
| 69 | assert_eq!(buf, data); | 73 | assert_eq!(buf, data); |
| 70 | spi.transfer(&mut buf, &data).await.unwrap(); | 74 | spi.transfer(&mut buf, &data).await.unwrap(); |
| @@ -88,31 +92,59 @@ async fn main(_spawner: Spawner) { | |||
| 88 | &mut sck, | 92 | &mut sck, |
| 89 | &mut miso, | 93 | &mut miso, |
| 90 | // SPIv1/f1 requires txdma even if rxonly. | 94 | // SPIv1/f1 requires txdma even if rxonly. |
| 91 | #[cfg(not(any( | 95 | #[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, | 96 | &mut tx_dma, |
| 103 | &mut rx_dma, | 97 | &mut rx_dma, |
| 104 | spi_config, | 98 | spi_config, |
| 105 | ); | 99 | ); |
| 106 | 100 | let mut mosi_out = Output::new(&mut mosi, Level::Low, Speed::VeryHigh); | |
| 107 | let mut mosi = Output::new(&mut mosi, Level::Low, Speed::VeryHigh); | 101 | mosi_out.set_high(); |
| 108 | |||
| 109 | mosi.set_high(); | ||
| 110 | spi.read(&mut buf).await.unwrap(); | 102 | spi.read(&mut buf).await.unwrap(); |
| 111 | assert_eq!(buf, [0xff; 9]); | 103 | assert_eq!(buf, [0xff; 9]); |
| 112 | 104 | spi.blocking_read(&mut buf).unwrap(); | |
| 113 | mosi.set_low(); | 105 | assert_eq!(buf, [0xff; 9]); |
| 106 | spi.read(&mut buf).await.unwrap(); | ||
| 107 | assert_eq!(buf, [0xff; 9]); | ||
| 108 | spi.read(&mut buf).await.unwrap(); | ||
| 109 | assert_eq!(buf, [0xff; 9]); | ||
| 110 | spi.blocking_read(&mut buf).unwrap(); | ||
| 111 | assert_eq!(buf, [0xff; 9]); | ||
| 112 | spi.blocking_read(&mut buf).unwrap(); | ||
| 113 | assert_eq!(buf, [0xff; 9]); | ||
| 114 | mosi_out.set_low(); | ||
| 114 | spi.read(&mut buf).await.unwrap(); | 115 | spi.read(&mut buf).await.unwrap(); |
| 115 | assert_eq!(buf, [0x00; 9]); | 116 | assert_eq!(buf, [0x00; 9]); |
| 117 | spi.read::<u8>(&mut []).await.unwrap(); | ||
| 118 | spi.blocking_read::<u8>(&mut []).unwrap(); | ||
| 119 | drop(mosi_out); | ||
| 120 | drop(spi); | ||
| 121 | |||
| 122 | // Test tx-only. Just check it doesn't hang, not much else we can do without using SPI slave. | ||
| 123 | let mut spi = Spi::new_txonly(&mut spi_peri, &mut sck, &mut mosi, &mut tx_dma, spi_config); | ||
| 124 | spi.blocking_write(&buf).unwrap(); | ||
| 125 | spi.write(&buf).await.unwrap(); | ||
| 126 | spi.blocking_write(&buf).unwrap(); | ||
| 127 | spi.blocking_write(&buf).unwrap(); | ||
| 128 | spi.write(&buf).await.unwrap(); | ||
| 129 | spi.write(&buf).await.unwrap(); | ||
| 130 | spi.write::<u8>(&[]).await.unwrap(); | ||
| 131 | spi.blocking_write::<u8>(&[]).unwrap(); | ||
| 132 | drop(spi); | ||
| 133 | |||
| 134 | // Test tx-only nosck. | ||
| 135 | #[cfg(feature = "spi-v1")] | ||
| 136 | { | ||
| 137 | let mut spi = Spi::new_txonly_nosck(&mut spi_peri, &mut mosi, &mut tx_dma, spi_config); | ||
| 138 | spi.blocking_write(&buf).unwrap(); | ||
| 139 | spi.write(&buf).await.unwrap(); | ||
| 140 | spi.blocking_write(&buf).unwrap(); | ||
| 141 | spi.blocking_write(&buf).unwrap(); | ||
| 142 | spi.write(&buf).await.unwrap(); | ||
| 143 | spi.write(&buf).await.unwrap(); | ||
| 144 | spi.write::<u8>(&[]).await.unwrap(); | ||
| 145 | spi.blocking_write::<u8>(&[]).unwrap(); | ||
| 146 | drop(spi); | ||
| 147 | } | ||
| 116 | 148 | ||
| 117 | info!("Test OK"); | 149 | info!("Test OK"); |
| 118 | cortex_m::asm::bkpt(); | 150 | cortex_m::asm::bkpt(); |
