Skip to content

Commit 13d0cc1

Browse files
Merge pull request #93 from LechevSpace/fix/multiblock-writes
fix: on multi-block writes send ACMD23 and wait not busy
2 parents b596d4a + f3fb15a commit 13d0cc1

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/sdcard/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,13 @@ where
237237
return Err(Error::WriteError);
238238
}
239239
} else {
240+
// > It is recommended using this command preceding CMD25, some of the cards will be faster for Multiple
241+
// > Write Blocks operation. Note that the host should send ACMD23 just before WRITE command if the host
242+
// > wants to use the pre-erased feature
243+
s.card_acmd(ACMD23, blocks.len() as u32)?;
244+
// wait for card to be ready before sending the next command
245+
s.wait_not_busy(Delay::new_write())?;
246+
240247
// Start a multi-block write
241248
s.card_command(CMD25, start_idx)?;
242249
for block in blocks.iter() {

src/sdcard/proto.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ pub const CMD55: u8 = 0x37;
6060
pub const CMD58: u8 = 0x3A;
6161
/// CRC_ON_OFF - enable or disable CRC checking
6262
pub const CMD59: u8 = 0x3B;
63+
/// Pre-erased before writing
64+
///
65+
/// > It is recommended using this command preceding CMD25, some of the cards will be faster for Multiple
66+
/// > Write Blocks operation. Note that the host should send ACMD23 just before WRITE command if the host
67+
/// > wants to use the pre-erased feature
68+
pub const ACMD23: u8 = 0x17;
6369
/// SD_SEND_OP_COMD - Sends host capacity support information and activates
6470
/// the card's initialization process
6571
pub const ACMD41: u8 = 0x29;

0 commit comments

Comments
 (0)