diff options
| author | Dario Nieuwenhuis <[email protected]> | 2024-10-30 09:57:09 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-10-30 09:57:09 +0000 |
| commit | 04bd2bac767752604862ea98d3a190b3e213ed9d (patch) | |
| tree | 6212e6ca33886cee8331635075e2df1518e28b91 | |
| parent | 10c9fbcc99b564d8ece88b32835dbc78a4269b34 (diff) | |
| parent | a3bbb3b43abd61ce86d6cd7b949a115f243e5dba (diff) | |
Merge pull request #3475 from diondokter/qspi-async
STM32 Qspi async
| -rw-r--r-- | embassy-stm32/src/qspi/mod.rs | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/embassy-stm32/src/qspi/mod.rs b/embassy-stm32/src/qspi/mod.rs index 1dfd0e918..49836aa57 100644 --- a/embassy-stm32/src/qspi/mod.rs +++ b/embassy-stm32/src/qspi/mod.rs | |||
| @@ -202,6 +202,21 @@ impl<'d, T: Instance, M: PeriMode> Qspi<'d, T, M> { | |||
| 202 | } | 202 | } |
| 203 | 203 | ||
| 204 | fn setup_transaction(&mut self, fmode: QspiMode, transaction: &TransferConfig, data_len: Option<usize>) { | 204 | fn setup_transaction(&mut self, fmode: QspiMode, transaction: &TransferConfig, data_len: Option<usize>) { |
| 205 | match (transaction.address, transaction.awidth) { | ||
| 206 | (Some(_), QspiWidth::NONE) => panic!("QSPI address can't be sent with an address width of NONE"), | ||
| 207 | (Some(_), _) => {} | ||
| 208 | (None, QspiWidth::NONE) => {} | ||
| 209 | (None, _) => panic!("QSPI address is not set, so the address width should be NONE"), | ||
| 210 | } | ||
| 211 | |||
| 212 | match (data_len, transaction.dwidth) { | ||
| 213 | (Some(0), _) => panic!("QSPI data must be at least one byte"), | ||
| 214 | (Some(_), QspiWidth::NONE) => panic!("QSPI data can't be sent with a data width of NONE"), | ||
| 215 | (Some(_), _) => {} | ||
| 216 | (None, QspiWidth::NONE) => {} | ||
| 217 | (None, _) => panic!("QSPI data is empty, so the data width should be NONE"), | ||
| 218 | } | ||
| 219 | |||
| 205 | T::REGS.fcr().modify(|v| { | 220 | T::REGS.fcr().modify(|v| { |
| 206 | v.set_csmf(true); | 221 | v.set_csmf(true); |
| 207 | v.set_ctcf(true); | 222 | v.set_ctcf(true); |
| @@ -353,6 +368,21 @@ impl<'d, T: Instance> Qspi<'d, T, Async> { | |||
| 353 | 368 | ||
| 354 | /// Blocking read data, using DMA. | 369 | /// Blocking read data, using DMA. |
| 355 | pub fn blocking_read_dma(&mut self, buf: &mut [u8], transaction: TransferConfig) { | 370 | pub fn blocking_read_dma(&mut self, buf: &mut [u8], transaction: TransferConfig) { |
| 371 | let transfer = self.start_read_transfer(transaction, buf); | ||
| 372 | transfer.blocking_wait(); | ||
| 373 | } | ||
| 374 | |||
| 375 | /// Async read data, using DMA. | ||
| 376 | pub async fn read_dma(&mut self, buf: &mut [u8], transaction: TransferConfig) { | ||
| 377 | let transfer = self.start_read_transfer(transaction, buf); | ||
| 378 | transfer.await; | ||
| 379 | } | ||
| 380 | |||
| 381 | fn start_read_transfer<'a>( | ||
| 382 | &'a mut self, | ||
| 383 | transaction: TransferConfig, | ||
| 384 | buf: &'a mut [u8], | ||
| 385 | ) -> crate::dma::Transfer<'a> { | ||
| 356 | self.setup_transaction(QspiMode::IndirectWrite, &transaction, Some(buf.len())); | 386 | self.setup_transaction(QspiMode::IndirectWrite, &transaction, Some(buf.len())); |
| 357 | 387 | ||
| 358 | T::REGS.ccr().modify(|v| { | 388 | T::REGS.ccr().modify(|v| { |
| @@ -373,12 +403,22 @@ impl<'d, T: Instance> Qspi<'d, T, Async> { | |||
| 373 | // STM32H7 does not have dmaen | 403 | // STM32H7 does not have dmaen |
| 374 | #[cfg(not(stm32h7))] | 404 | #[cfg(not(stm32h7))] |
| 375 | T::REGS.cr().modify(|v| v.set_dmaen(true)); | 405 | T::REGS.cr().modify(|v| v.set_dmaen(true)); |
| 376 | 406 | transfer | |
| 377 | transfer.blocking_wait(); | ||
| 378 | } | 407 | } |
| 379 | 408 | ||
| 380 | /// Blocking write data, using DMA. | 409 | /// Blocking write data, using DMA. |
| 381 | pub fn blocking_write_dma(&mut self, buf: &[u8], transaction: TransferConfig) { | 410 | pub fn blocking_write_dma(&mut self, buf: &[u8], transaction: TransferConfig) { |
| 411 | let transfer = self.start_write_transfer(transaction, buf); | ||
| 412 | transfer.blocking_wait(); | ||
| 413 | } | ||
| 414 | |||
| 415 | /// Async write data, using DMA. | ||
| 416 | pub async fn write_dma(&mut self, buf: &[u8], transaction: TransferConfig) { | ||
| 417 | let transfer = self.start_write_transfer(transaction, buf); | ||
| 418 | transfer.await; | ||
| 419 | } | ||
| 420 | |||
| 421 | 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())); | 422 | self.setup_transaction(QspiMode::IndirectWrite, &transaction, Some(buf.len())); |
| 383 | 423 | ||
| 384 | T::REGS.ccr().modify(|v| { | 424 | T::REGS.ccr().modify(|v| { |
| @@ -395,8 +435,7 @@ impl<'d, T: Instance> Qspi<'d, T, Async> { | |||
| 395 | // STM32H7 does not have dmaen | 435 | // STM32H7 does not have dmaen |
| 396 | #[cfg(not(stm32h7))] | 436 | #[cfg(not(stm32h7))] |
| 397 | T::REGS.cr().modify(|v| v.set_dmaen(true)); | 437 | T::REGS.cr().modify(|v| v.set_dmaen(true)); |
| 398 | 438 | transfer | |
| 399 | transfer.blocking_wait(); | ||
| 400 | } | 439 | } |
| 401 | } | 440 | } |
| 402 | 441 | ||
