diff options
| -rw-r--r-- | embassy-stm32/src/qspi/mod.rs | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/embassy-stm32/src/qspi/mod.rs b/embassy-stm32/src/qspi/mod.rs index 308947e99..715c260e9 100644 --- a/embassy-stm32/src/qspi/mod.rs +++ b/embassy-stm32/src/qspi/mod.rs | |||
| @@ -353,6 +353,21 @@ impl<'d, T: Instance> Qspi<'d, T, Async> { | |||
| 353 | 353 | ||
| 354 | /// Blocking read data, using DMA. | 354 | /// Blocking read data, using DMA. |
| 355 | pub fn blocking_read_dma(&mut self, buf: &mut [u8], transaction: TransferConfig) { | 355 | pub fn blocking_read_dma(&mut self, buf: &mut [u8], transaction: TransferConfig) { |
| 356 | let transfer = self.start_read_transfer(transaction, buf); | ||
| 357 | transfer.blocking_wait(); | ||
| 358 | } | ||
| 359 | |||
| 360 | /// Blocking read data, using DMA. | ||
| 361 | pub async fn read_dma(&mut self, buf: &mut [u8], transaction: TransferConfig) { | ||
| 362 | let transfer = self.start_read_transfer(transaction, buf); | ||
| 363 | transfer.await; | ||
| 364 | } | ||
| 365 | |||
| 366 | fn start_read_transfer<'a>( | ||
| 367 | &'a mut self, | ||
| 368 | transaction: TransferConfig, | ||
| 369 | buf: &'a mut [u8], | ||
| 370 | ) -> crate::dma::Transfer<'a> { | ||
| 356 | self.setup_transaction(QspiMode::IndirectWrite, &transaction, Some(buf.len())); | 371 | self.setup_transaction(QspiMode::IndirectWrite, &transaction, Some(buf.len())); |
| 357 | 372 | ||
| 358 | T::REGS.ccr().modify(|v| { | 373 | T::REGS.ccr().modify(|v| { |
| @@ -373,12 +388,22 @@ impl<'d, T: Instance> Qspi<'d, T, Async> { | |||
| 373 | // STM32H7 does not have dmaen | 388 | // STM32H7 does not have dmaen |
| 374 | #[cfg(not(stm32h7))] | 389 | #[cfg(not(stm32h7))] |
| 375 | T::REGS.cr().modify(|v| v.set_dmaen(true)); | 390 | T::REGS.cr().modify(|v| v.set_dmaen(true)); |
| 376 | 391 | transfer | |
| 377 | transfer.blocking_wait(); | ||
| 378 | } | 392 | } |
| 379 | 393 | ||
| 380 | /// Blocking write data, using DMA. | 394 | /// Blocking write data, using DMA. |
| 381 | pub fn blocking_write_dma(&mut self, buf: &[u8], transaction: TransferConfig) { | 395 | pub fn blocking_write_dma(&mut self, buf: &[u8], transaction: TransferConfig) { |
| 396 | let transfer = self.start_write_transfer(transaction, buf); | ||
| 397 | transfer.blocking_wait(); | ||
| 398 | } | ||
| 399 | |||
| 400 | /// Async write data, using DMA. | ||
| 401 | pub async fn write_dma(&mut self, buf: &[u8], transaction: TransferConfig) { | ||
| 402 | let transfer = self.start_write_transfer(transaction, buf); | ||
| 403 | transfer.await; | ||
| 404 | } | ||
| 405 | |||
| 406 | fn start_write_transfer<'a>(&'a mut self, transaction: TransferConfig, buf: &'a [u8]) -> crate::dma::Transfer<'a> { | ||
| 382 | self.setup_transaction(QspiMode::IndirectWrite, &transaction, Some(buf.len())); | 407 | self.setup_transaction(QspiMode::IndirectWrite, &transaction, Some(buf.len())); |
| 383 | 408 | ||
| 384 | T::REGS.ccr().modify(|v| { | 409 | T::REGS.ccr().modify(|v| { |
| @@ -395,8 +420,7 @@ impl<'d, T: Instance> Qspi<'d, T, Async> { | |||
| 395 | // STM32H7 does not have dmaen | 420 | // STM32H7 does not have dmaen |
| 396 | #[cfg(not(stm32h7))] | 421 | #[cfg(not(stm32h7))] |
| 397 | T::REGS.cr().modify(|v| v.set_dmaen(true)); | 422 | T::REGS.cr().modify(|v| v.set_dmaen(true)); |
| 398 | 423 | transfer | |
| 399 | transfer.blocking_wait(); | ||
| 400 | } | 424 | } |
| 401 | } | 425 | } |
| 402 | 426 | ||
