aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2023-04-14 22:49:56 +0200
committerDario Nieuwenhuis <[email protected]>2023-04-15 00:58:58 +0200
commit224eaaf79792a04a25bf7d5e768da41b2a030f7a (patch)
tree3645e8afb44a5903af7d4d2a55e527868efbf068
parentf681b9d4e5fc142ee0bb847e0e00260c932a1401 (diff)
stm32/sdmmc: switch to AFIT.
-rw-r--r--embassy-stm32/Cargo.toml2
-rw-r--r--embassy-stm32/src/sdmmc/mod.rs56
-rw-r--r--examples/stm32f4/Cargo.toml2
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"
55futures = { version = "0.3.17", default-features = false, features = ["async-await"] } 55futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
56rand_core = "0.6.3" 56rand_core = "0.6.3"
57sdio-host = "0.5.0" 57sdio-host = "0.5.0"
58embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "46d1b1c2ff13e31e282ec1e352421721694f126a", optional = true } 58embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "a4f293d3a6f72158385f79c98634cb8a14d0d2fc", optional = true }
59critical-section = "1.1" 59critical-section = "1.1"
60atomic-polyfill = "1.0.1" 60atomic-polyfill = "1.0.1"
61stm32-metapac = "6" 61stm32-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!(
1651 1651
1652#[cfg(feature = "embedded-sdmmc")] 1652#[cfg(feature = "embedded-sdmmc")]
1653mod sdmmc_rs { 1653mod sdmmc_rs {
1654 use core::future::Future;
1655
1656 use embedded_sdmmc::{Block, BlockCount, BlockDevice, BlockIdx}; 1654 use embedded_sdmmc::{Block, BlockCount, BlockDevice, BlockIdx};
1657 1655
1658 use super::*; 1656 use super::*;
@@ -1660,49 +1658,37 @@ mod sdmmc_rs {
1660 impl<'d, T: Instance, Dma: SdmmcDma<T>> BlockDevice for Sdmmc<'d, T, Dma> { 1658 impl<'d, T: Instance, Dma: SdmmcDma<T>> BlockDevice for Sdmmc<'d, T, Dma> {
1661 type Error = Error; 1659 type Error = Error;
1662 1660
1663 type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a 1661 async fn read(
1664 where 1662 &mut self,
1665 Self: 'a; 1663 blocks: &mut [Block],
1666
1667 type WriteFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a
1668 where
1669 Self: 'a;
1670
1671 fn read<'a>(
1672 &'a mut self,
1673 blocks: &'a mut [Block],
1674 start_block_idx: BlockIdx, 1664 start_block_idx: BlockIdx,
1675 _reason: &str, 1665 _reason: &str,
1676 ) -> Self::ReadFuture<'a> { 1666 ) -> Result<(), Self::Error> {
1677 async move { 1667 let mut address = start_block_idx.0;
1678 let mut address = start_block_idx.0;
1679 1668
1680 for block in blocks.iter_mut() { 1669 for block in blocks.iter_mut() {
1681 let block: &mut [u8; 512] = &mut block.contents; 1670 let block: &mut [u8; 512] = &mut block.contents;
1682 1671
1683 // NOTE(unsafe) Block uses align(4) 1672 // NOTE(unsafe) Block uses align(4)
1684 let block = unsafe { &mut *(block as *mut _ as *mut DataBlock) }; 1673 let block = unsafe { &mut *(block as *mut _ as *mut DataBlock) };
1685 self.read_block(address, block).await?; 1674 self.read_block(address, block).await?;
1686 address += 1; 1675 address += 1;
1687 }
1688 Ok(())
1689 } 1676 }
1677 Ok(())
1690 } 1678 }
1691 1679
1692 fn write<'a>(&'a mut self, blocks: &'a [Block], start_block_idx: BlockIdx) -> Self::WriteFuture<'a> { 1680 async fn write(&mut self, blocks: &[Block], start_block_idx: BlockIdx) -> Result<(), Self::Error> {
1693 async move { 1681 let mut address = start_block_idx.0;
1694 let mut address = start_block_idx.0;
1695 1682
1696 for block in blocks.iter() { 1683 for block in blocks.iter() {
1697 let block: &[u8; 512] = &block.contents; 1684 let block: &[u8; 512] = &block.contents;
1698 1685
1699 // NOTE(unsafe) DataBlock uses align 4 1686 // NOTE(unsafe) DataBlock uses align 4
1700 let block = unsafe { &*(block as *const _ as *const DataBlock) }; 1687 let block = unsafe { &*(block as *const _ as *const DataBlock) };
1701 self.write_block(address, block).await?; 1688 self.write_block(address, block).await?;
1702 address += 1; 1689 address += 1;
1703 }
1704 Ok(())
1705 } 1690 }
1691 Ok(())
1706 } 1692 }
1707 1693
1708 fn num_blocks(&self) -> Result<BlockCount, Self::Error> { 1694 fn num_blocks(&self) -> Result<BlockCount, Self::Error> {
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"
8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] } 8embassy-sync = { version = "0.2.0", path = "../../embassy-sync", features = ["defmt"] }
9embassy-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"] } 9embassy-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"] }
10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] } 10embassy-time = { version = "0.1.0", path = "../../embassy-time", features = ["defmt", "defmt-timestamp-uptime", "unstable-traits", "tick-hz-32_768"] }
11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "unstable-traits", "defmt", "stm32f429zi", "unstable-pac", "memory-x", "time-driver-any", "exti"] } 11embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["nightly", "unstable-traits", "defmt", "stm32f429zi", "unstable-pac", "memory-x", "time-driver-any", "exti", "embedded-sdmmc"] }
12embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] } 12embassy-usb = { version = "0.1.0", path = "../../embassy-usb", features = ["defmt"] }
13embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "nightly"] } 13embassy-net = { version = "0.1.0", path = "../../embassy-net", features = ["defmt", "tcp", "dhcpv4", "medium-ethernet", "nightly"] }
14 14