From 268da2fcde429887a7df879deb90d2383d9d754e Mon Sep 17 00:00:00 2001 From: Scott Mabin Date: Sun, 10 Sep 2023 14:51:59 +0100 Subject: [PATCH] Handle stbiterr in 4bit wide mode for sdmmc_v1 --- embassy-stm32/Cargo.toml | 4 +-- embassy-stm32/src/sdmmc/mod.rs | 56 ++++++++++++++++++++++++++++------ 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/embassy-stm32/Cargo.toml b/embassy-stm32/Cargo.toml index ded58aee..bd9b406a 100644 --- a/embassy-stm32/Cargo.toml +++ b/embassy-stm32/Cargo.toml @@ -58,7 +58,7 @@ sdio-host = "0.5.0" 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 = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-eaa4987e523408dfb31c1b76765dd345d2761373" } +stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-e667107cf81934383ec5744f49b2cda0599ec749" } vcell = "0.1.3" bxcan = "0.7.0" nb = "1.0.0" @@ -77,7 +77,7 @@ critical-section = { version = "1.1", features = ["std"] } [build-dependencies] proc-macro2 = "1.0.36" quote = "1.0.15" -stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-eaa4987e523408dfb31c1b76765dd345d2761373", default-features = false, features = ["metadata"]} +stm32-metapac = { git = "https://github.com/embassy-rs/stm32-data-generated", tag = "stm32-data-e667107cf81934383ec5744f49b2cda0599ec749", default-features = false, features = ["metadata"]} [features] default = ["rt"] diff --git a/embassy-stm32/src/sdmmc/mod.rs b/embassy-stm32/src/sdmmc/mod.rs index 6b532363..9fb380fd 100644 --- a/embassy-stm32/src/sdmmc/mod.rs +++ b/embassy-stm32/src/sdmmc/mod.rs @@ -33,6 +33,8 @@ impl InterruptHandler { w.set_dtimeoutie(enable); w.set_dataendie(enable); + #[cfg(sdmmc_v1)] + w.set_stbiterre(enable); #[cfg(sdmmc_v2)] w.set_dabortie(enable); }); @@ -102,6 +104,8 @@ pub enum Error { BadClock, SignalingSwitchFailed, PeripheralBusy, + #[cfg(sdmmc_v1)] + StBitErr, } /// A SD command @@ -707,9 +711,15 @@ impl<'d, T: Instance, Dma: SdmmcDma + 'd> Sdmmc<'d, T, Dma> { if status.dcrcfail() { return Poll::Ready(Err(Error::Crc)); - } else if status.dtimeout() { + } + if status.dtimeout() { return Poll::Ready(Err(Error::Timeout)); - } else if status.dataend() { + } + #[cfg(sdmmc_v1)] + if status.stbiterr() { + return Poll::Ready(Err(Error::StBitErr)); + } + if status.dataend() { return Poll::Ready(Ok(())); } Poll::Pending @@ -782,9 +792,15 @@ impl<'d, T: Instance, Dma: SdmmcDma + 'd> Sdmmc<'d, T, Dma> { if status.dcrcfail() { return Poll::Ready(Err(Error::Crc)); - } else if status.dtimeout() { + } + if status.dtimeout() { return Poll::Ready(Err(Error::Timeout)); - } else if status.dataend() { + } + #[cfg(sdmmc_v1)] + if status.stbiterr() { + return Poll::Ready(Err(Error::StBitErr)); + } + if status.dataend() { return Poll::Ready(Ok(())); } Poll::Pending @@ -836,6 +852,8 @@ impl<'d, T: Instance, Dma: SdmmcDma + 'd> Sdmmc<'d, T, Dma> { w.set_dataendc(true); w.set_dbckendc(true); w.set_sdioitc(true); + #[cfg(sdmmc_v1)] + w.set_stbiterrc(true); #[cfg(sdmmc_v2)] { @@ -873,9 +891,15 @@ impl<'d, T: Instance, Dma: SdmmcDma + 'd> Sdmmc<'d, T, Dma> { if status.dcrcfail() { return Poll::Ready(Err(Error::Crc)); - } else if status.dtimeout() { + } + if status.dtimeout() { return Poll::Ready(Err(Error::Timeout)); - } else if status.dataend() { + } + #[cfg(sdmmc_v1)] + if status.stbiterr() { + return Poll::Ready(Err(Error::StBitErr)); + } + if status.dataend() { return Poll::Ready(Ok(())); } Poll::Pending @@ -1156,9 +1180,15 @@ impl<'d, T: Instance, Dma: SdmmcDma + 'd> Sdmmc<'d, T, Dma> { if status.dcrcfail() { return Poll::Ready(Err(Error::Crc)); - } else if status.dtimeout() { + } + if status.dtimeout() { return Poll::Ready(Err(Error::Timeout)); - } else if status.dataend() { + } + #[cfg(sdmmc_v1)] + if status.stbiterr() { + return Poll::Ready(Err(Error::StBitErr)); + } + if status.dataend() { return Poll::Ready(Ok(())); } Poll::Pending @@ -1207,9 +1237,15 @@ impl<'d, T: Instance, Dma: SdmmcDma + 'd> Sdmmc<'d, T, Dma> { if status.dcrcfail() { return Poll::Ready(Err(Error::Crc)); - } else if status.dtimeout() { + } + if status.dtimeout() { return Poll::Ready(Err(Error::Timeout)); - } else if status.dataend() { + } + #[cfg(sdmmc_v1)] + if status.stbiterr() { + return Poll::Ready(Err(Error::StBitErr)); + } + if status.dataend() { return Poll::Ready(Ok(())); } Poll::Pending