From 224eaaf79792a04a25bf7d5e768da41b2a030f7a Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Fri, 14 Apr 2023 22:49:56 +0200 Subject: [PATCH] stm32/sdmmc: switch to AFIT. --- embassy-stm32/Cargo.toml | 2 +- embassy-stm32/src/sdmmc/mod.rs | 56 +++++++++++++--------------------- examples/stm32f4/Cargo.toml | 2 +- 3 files changed, 23 insertions(+), 37 deletions(-) diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml index 969dc3b70..18b1d4d0e 100644 --- a/embassy-stm32/Cargo.toml +++ b/embassy-stm32/Cargo.toml @@ -55,7 +55,7 @@ cortex-m = "0.7.6" futures = { version = "0.3.17", default-features = false, features = ["async-await"] } rand_core = "0.6.3" sdio-host = "0.5.0" -embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "46d1b1c2ff13e31e282ec1e352421721694f126a", optional = true } +embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "a4f293d3a6f72158385f79c98634cb8a14d0d2fc", optional = true } critical-section = "1.1" atomic-polyfill = "1.0.1" stm32-metapac = "6" diff --git a/embassy-stm32/src/sdmmc/mod.rs b/embassy-stm32/src/sdmmc/mod.rs index 03d24dcb1..ac00b5176 100644 --- a/embassy-stm32/src/sdmmc/mod.rs +++ b/embassy-stm32/src/sdmmc/mod.rs @@ -1651,8 +1651,6 @@ foreach_peripheral!( #[cfg(feature = "embedded-sdmmc")] mod sdmmc_rs { - use core::future::Future; - use embedded_sdmmc::{Block, BlockCount, BlockDevice, BlockIdx}; use super::*; @@ -1660,49 +1658,37 @@ mod sdmmc_rs { impl<'d, T: Instance, Dma: SdmmcDma> BlockDevice for Sdmmc<'d, T, Dma> { type Error = Error; - type ReadFuture<'a> = impl Future> + 'a - where - Self: 'a; - - type WriteFuture<'a> = impl Future> + 'a - where - Self: 'a; - - fn read<'a>( - &'a mut self, - blocks: &'a mut [Block], + async fn read( + &mut self, + blocks: &mut [Block], start_block_idx: BlockIdx, _reason: &str, - ) -> Self::ReadFuture<'a> { - async move { - let mut address = start_block_idx.0; + ) -> Result<(), Self::Error> { + let mut address = start_block_idx.0; - for block in blocks.iter_mut() { - let block: &mut [u8; 512] = &mut block.contents; + for block in blocks.iter_mut() { + let block: &mut [u8; 512] = &mut block.contents; - // NOTE(unsafe) Block uses align(4) - let block = unsafe { &mut *(block as *mut _ as *mut DataBlock) }; - self.read_block(address, block).await?; - address += 1; - } - Ok(()) + // NOTE(unsafe) Block uses align(4) + let block = unsafe { &mut *(block as *mut _ as *mut DataBlock) }; + self.read_block(address, block).await?; + address += 1; } + Ok(()) } - fn write<'a>(&'a mut self, blocks: &'a [Block], start_block_idx: BlockIdx) -> Self::WriteFuture<'a> { - async move { - let mut address = start_block_idx.0; + async fn write(&mut self, blocks: &[Block], start_block_idx: BlockIdx) -> Result<(), Self::Error> { + let mut address = start_block_idx.0; - for block in blocks.iter() { - let block: &[u8; 512] = &block.contents; + for block in blocks.iter() { + let block: &[u8; 512] = &block.contents; - // NOTE(unsafe) DataBlock uses align 4 - let block = unsafe { &*(block as *const _ as *const DataBlock) }; - self.write_block(address, block).await?; - address += 1; - } - Ok(()) + // NOTE(unsafe) DataBlock uses align 4 + let block = unsafe { &*(block as *const _ as *const DataBlock) }; + self.write_block(address, block).await?; + address += 1; } + Ok(()) } fn num_blocks(&self) -> Result { diff --git a/examples/stm32f4/Cargo.toml b/examples/stm32f4/Cargo.toml index 4b2f3d21c..1736769ef 100644 --- a/examples/stm32f4/Cargo.toml +++ b/examples/stm32f4/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0" embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } embassy-executor = { version = "0.1.0", path = "../../embassy-executor", features = ["arch-cortex-m", "executor-thread", "executor-interrupt", "defmt", "integrated-timers", "arch-cortex-m", "executor-thread", "executor-interrupt"] } embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] } -embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "unstable-traits", "defmt", "stm32f429zi", "unstable-pac", "memory-x", "time-driver-any", "exti"] } +embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "unstable-traits", "defmt", "stm32f429zi", "unstable-pac", "memory-x", "time-driver-any", "exti", "embedded-sdmmc"] } embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "nightly"] }