aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2023-01-21 01:22:17 +0100
committerGitHub <[email protected]>2023-01-21 01:22:17 +0100
commit6ad2bcf97a980997e4f18866c99046422aa75b95 (patch)
treed3b1a7c23547cd6100dfd5577c5419ed834ff740
parent825b67101b1fca80f57025e01f3a7fc386b4af5e (diff)
parent0412d1922c6cca1200da0af54db3a5dbf60c035c (diff)
Merge pull request #1166 from embassy-rs/sdmmc-fix
fix embedded-sdmmc integration.
-rwxr-xr-xci.sh2
-rw-r--r--embassy-stm32/Cargo.toml3
-rw-r--r--embassy-stm32/src/sdmmc/mod.rs22
3 files changed, 8 insertions, 19 deletions
diff --git a/ci.sh b/ci.sh
index 323e752d2..b325e3764 100755
--- a/ci.sh
+++ b/ci.sh
@@ -63,7 +63,7 @@ cargo batch \
63 --- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features nightly,intrinsics \ 63 --- build --release --manifest-path embassy-rp/Cargo.toml --target thumbv6m-none-eabi --features nightly,intrinsics \
64 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f410tb,defmt,exti,time-driver-any,unstable-traits \ 64 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f410tb,defmt,exti,time-driver-any,unstable-traits \
65 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f411ce,defmt,exti,time-driver-any,unstable-traits \ 65 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f411ce,defmt,exti,time-driver-any,unstable-traits \
66 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f429zi,log,exti,time-driver-any,unstable-traits \ 66 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32f429zi,log,exti,time-driver-any,unstable-traits,embedded-sdmmc \
67 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32h755zi-cm7,defmt,exti,time-driver-any,unstable-traits \ 67 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32h755zi-cm7,defmt,exti,time-driver-any,unstable-traits \
68 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32h7b3ai,defmt,exti,time-driver-any,unstable-traits \ 68 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32h7b3ai,defmt,exti,time-driver-any,unstable-traits \
69 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32l476vg,defmt,exti,time-driver-any,unstable-traits \ 69 --- build --release --manifest-path embassy-stm32/Cargo.toml --target thumbv7em-none-eabi --features nightly,stm32l476vg,defmt,exti,time-driver-any,unstable-traits \
diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml
index d9c1f6dcf..10e5e48c0 100644
--- a/embassy-stm32/Cargo.toml
+++ b/embassy-stm32/Cargo.toml
@@ -58,7 +58,7 @@ cortex-m = "0.7.6"
58futures = { version = "0.3.17", default-features = false, features = ["async-await"] } 58futures = { version = "0.3.17", default-features = false, features = ["async-await"] }
59rand_core = "0.6.3" 59rand_core = "0.6.3"
60sdio-host = "0.5.0" 60sdio-host = "0.5.0"
61embedded-sdmmc = { git = "https://github.com/thalesfragoso/embedded-sdmmc-rs", branch = "async", optional = true } 61embedded-sdmmc = { git = "https://github.com/embassy-rs/embedded-sdmmc-rs", rev = "46d1b1c2ff13e31e282ec1e352421721694f126a", optional = true }
62critical-section = "1.1" 62critical-section = "1.1"
63atomic-polyfill = "1.0.1" 63atomic-polyfill = "1.0.1"
64stm32-metapac = { version = "0.1.0", path = "../stm32-metapac", features = ["rt"] } 64stm32-metapac = { version = "0.1.0", path = "../stm32-metapac", features = ["rt"] }
@@ -77,7 +77,6 @@ stm32-metapac = { version = "0.1.0", path = "../stm32-metapac", default-features
77 77
78[features] 78[features]
79defmt = ["dep:defmt", "bxcan/unstable-defmt", "embassy-sync/defmt", "embassy-executor/defmt", "embassy-embedded-hal/defmt", "embassy-hal-common/defmt", "embedded-io?/defmt", "embassy-usb-driver?/defmt", "embassy-net-driver/defmt"] 79defmt = ["dep:defmt", "bxcan/unstable-defmt", "embassy-sync/defmt", "embassy-executor/defmt", "embassy-embedded-hal/defmt", "embassy-hal-common/defmt", "embedded-io?/defmt", "embassy-usb-driver?/defmt", "embassy-net-driver/defmt"]
80sdmmc-rs = ["embedded-sdmmc"]
81memory-x = ["stm32-metapac/memory-x"] 80memory-x = ["stm32-metapac/memory-x"]
82subghz = [] 81subghz = []
83exti = [] 82exti = []
diff --git a/embassy-stm32/src/sdmmc/mod.rs b/embassy-stm32/src/sdmmc/mod.rs
index a52c65b92..3f07e0c07 100644
--- a/embassy-stm32/src/sdmmc/mod.rs
+++ b/embassy-stm32/src/sdmmc/mod.rs
@@ -1532,7 +1532,7 @@ foreach_peripheral!(
1532 }; 1532 };
1533); 1533);
1534 1534
1535#[cfg(feature = "sdmmc-rs")] 1535#[cfg(feature = "embedded-sdmmc")]
1536mod sdmmc_rs { 1536mod sdmmc_rs {
1537 use core::future::Future; 1537 use core::future::Future;
1538 1538
@@ -1540,7 +1540,7 @@ mod sdmmc_rs {
1540 1540
1541 use super::*; 1541 use super::*;
1542 1542
1543 impl<'d, T: Instance, P: Pins<T>> BlockDevice for Sdmmc<'d, T, P> { 1543 impl<'d, T: Instance, Dma: SdmmcDma<T>> BlockDevice for Sdmmc<'d, T, Dma> {
1544 type Error = Error; 1544 type Error = Error;
1545 1545
1546 type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a 1546 type ReadFuture<'a> = impl Future<Output = Result<(), Self::Error>> + 'a
@@ -1558,19 +1558,14 @@ mod sdmmc_rs {
1558 _reason: &str, 1558 _reason: &str,
1559 ) -> Self::ReadFuture<'a> { 1559 ) -> Self::ReadFuture<'a> {
1560 async move { 1560 async move {
1561 let card_capacity = self.card()?.card_type;
1562 let inner = T::inner();
1563 let state = T::state();
1564 let mut address = start_block_idx.0; 1561 let mut address = start_block_idx.0;
1565 1562
1566 for block in blocks.iter_mut() { 1563 for block in blocks.iter_mut() {
1567 let block: &mut [u8; 512] = &mut block.contents; 1564 let block: &mut [u8; 512] = &mut block.contents;
1568 1565
1569 // NOTE(unsafe) Block uses align(4) 1566 // NOTE(unsafe) Block uses align(4)
1570 let buf = unsafe { &mut *(block as *mut [u8; 512] as *mut [u32; 128]) }; 1567 let block = unsafe { &mut *(block as *mut _ as *mut DataBlock) };
1571 inner 1568 self.read_block(address, block).await?;
1572 .read_block(address, buf, card_capacity, state, self.config.data_transfer_timeout)
1573 .await?;
1574 address += 1; 1569 address += 1;
1575 } 1570 }
1576 Ok(()) 1571 Ok(())
@@ -1579,19 +1574,14 @@ mod sdmmc_rs {
1579 1574
1580 fn write<'a>(&'a mut self, blocks: &'a [Block], start_block_idx: BlockIdx) -> Self::WriteFuture<'a> { 1575 fn write<'a>(&'a mut self, blocks: &'a [Block], start_block_idx: BlockIdx) -> Self::WriteFuture<'a> {
1581 async move { 1576 async move {
1582 let card = self.card.as_mut().ok_or(Error::NoCard)?;
1583 let inner = T::inner();
1584 let state = T::state();
1585 let mut address = start_block_idx.0; 1577 let mut address = start_block_idx.0;
1586 1578
1587 for block in blocks.iter() { 1579 for block in blocks.iter() {
1588 let block: &[u8; 512] = &block.contents; 1580 let block: &[u8; 512] = &block.contents;
1589 1581
1590 // NOTE(unsafe) DataBlock uses align 4 1582 // NOTE(unsafe) DataBlock uses align 4
1591 let buf = unsafe { &*(block as *const [u8; 512] as *const [u32; 128]) }; 1583 let block = unsafe { &*(block as *const _ as *const DataBlock) };
1592 inner 1584 self.write_block(address, block).await?;
1593 .write_block(address, buf, card, state, self.config.data_transfer_timeout)
1594 .await?;
1595 address += 1; 1585 address += 1;
1596 } 1586 }
1597 Ok(()) 1587 Ok(())