Skip to content

Commit

Permalink
Merge #361
Browse files Browse the repository at this point in the history
361: Wait for sdmmc card to return to transfer mode after each write r=richardeoin a=richardeoin



Co-authored-by: Richard Meadows <962920+richardeoin@users.noreply.github.com>
  • Loading branch information
bors[bot] and richardeoin authored Apr 24, 2022
2 parents 8a76d7f + 75b3833 commit 216835d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
19 changes: 18 additions & 1 deletion examples/sdmmc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,23 @@ fn main() -> ! {
info!("Read 10 blocks at {} bytes/s", 5120. / duration);
info!("");

// Write 10 blocks
let write_buffer = [0x34; 512];
let start = pac::DWT::cycle_count();

for i in 0..10 {
if let Err(err) = sdmmc.write_block(i, &write_buffer) {
info!("Failed to write block {}: {:?}", i, err);
}
}

let end = pac::DWT::cycle_count();
let duration = (end - start) as f32 / ccdr.clocks.c_ck().raw() as f32;

info!("Wrote 10 blocks at {} bytes/s", 5120. / duration);
info!("");

info!("Verification test...");
// Write 10 blocks
for i in 0..10 {
if let Err(err) = sdmmc.write_block(i, &write_buffer) {
info!("Failed to write block {}: {:?}", i, err);
Expand All @@ -178,6 +193,8 @@ fn main() -> ! {
for byte in buffer.iter() {
assert_eq!(*byte, 0x34);
}
info!("Verified 10 blocks");
info!("");

info!("Done!");

Expand Down
9 changes: 3 additions & 6 deletions src/sdmmc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,14 +717,11 @@ macro_rules! sdmmc {

let mut timeout: u32 = 0xFFFF_FFFF;

// Try to read card status (ACMD13)
// Try to read card status (CMD13)
while timeout > 0 {
match self.read_status() {
Ok(_) => return Ok(()),
Err(Error::Timeout) => (), // Try again
Err(e) => return Err(e),
if self.card_ready()? {
return Ok(());
}

timeout -= 1;
}
Err(Error::SoftwareTimeout)
Expand Down

0 comments on commit 216835d

Please sign in to comment.