Skip to content

src/sdcard/spi.rs: Wait for idle gap after escape#249

Merged
thejpster merged 1 commit into
rust-embedded-community:developfrom
osdyne:fdomke/wait_idle_after_acmd
Jun 5, 2026
Merged

src/sdcard/spi.rs: Wait for idle gap after escape#249
thejpster merged 1 commit into
rust-embedded-community:developfrom
osdyne:fdomke/wait_idle_after_acmd

Conversation

@fdomke

@fdomke fdomke commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

After sending CMD55 (escape for ACMDs), the card is allowed to be busy again.

This fixes a regression that broke e.g. SanDisk Ultra 64GB SDXC cards.

This fixes a regression from a refactor that broke e.g. SanDisk Ultra
64GB SDXC cards.
@fdomke

fdomke commented Jun 4, 2026

Copy link
Copy Markdown
Contributor Author

This regressed in d2334e7#diff-a73d1482336da8457a9bf37e49622a3850bd9fc5bc55af1162e1f2ba13a14a52L460-R469:

-    fn card_acmd(&mut self, command: u8, arg: u32) -> Result<u8, Error> {
-        self.card_command(CMD55, 0)?;
-        self.card_command(command, arg)    // << this used to wait for busy
+    fn card_acmd(&mut self, command: AcmdId, arg: u32) -> Result<u8, Error> {
+        self.card_command(super::CmdId::_55_AppCmd, 0)?;
+        self.card_acmd_after_escape(command, arg)
+    }
+
+    fn card_acmd_after_escape(&mut self, command: AcmdId, arg: u32) -> Result<u8, Error> {
+        let mut buf = [
+            0x40 | command as u8,
+            (arg >> 24) as u8,
+            (arg >> 16) as u8,
+            (arg >> 8) as u8,
+            arg as u8,
+            0,
+        ];
+        buf[5] = crc7(&buf[0..5]);
+
+        self.write_bytes(&buf)?;  // << this does not wait anymore

[...]
    fn card_command(&mut self, command: CmdId, arg: u32) -> Result<u8, Error> {
        if command != super::CmdId::_0_GoIdleState && command != super::CmdId::_12_StopTransmission
        {
             self.wait_not_busy(Delay::new_command())?;
         }
[...]

after which wait_not_busy was not anymore called after CMD55.

@thejpster

Copy link
Copy Markdown
Member

Oops. Thanks for the fix.

@thejpster thejpster added this pull request to the merge queue Jun 5, 2026
Merged via the queue into rust-embedded-community:develop with commit ce5710f Jun 5, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants