embedded-sdmmc-rs
embedded-sdmmc-rs copied to clipboard
Add the option to skip waiting in the init sequence when issuing CMD0.
Looking at #32 and #33, at least some cards get stuck in TimeoutWaitNotBusy
when trying to initialize them. #32 provides a fix, however it seems to break other cards' init sequence.
I suggest adding an option in AcquireOpts
to use this modified init sequence, with the default being to use the "regular" sequence.
It would awkward if you needed two versions of your code to work with the widest range of SD cards. My general approach has been "Do what Arduino does" - so I checked, and they don't do this.
Their init code is: https://github.com/greiman/SdFat/blob/master/src/SdCard/SdSpiCard.cpp#L170
Maybe we should add this loop of sending 255 lots of 0xFF
to clear the card instead?
// command to go idle in SPI mode
for (uint8_t i = 1;; i++) {
if (cardCommand(CMD0, 0) == R1_IDLE_STATE) {
break;
}
if (i == SD_CMD0_RETRY) {
error(SD_CARD_ERROR_CMD0);
goto fail;
}
// Force any active transfer to end for an already initialized card.
for (uint8_t j = 0; j < 0XFF; j++) {
spiSend(0XFF);
}
}
That would be even better. Just to clarify, that sequence would always run, without an option to skip it? I'll try to test it out with a few cards next week.
Well, it doesn't happen if your card returns IDLE on the first attempt. But every time it doesn't return IDLE, it gets flushed.
Does this work? I guess skip_wait_not_busy
is no longer required if so?
I'm not sure if it works yet. Getting my cards to fail to initialize is somewhat hard; it happens intermittently and is difficult to reproduce reliably. I'll have to do some more testing, but what I can say is I haven't had an initialization fail using this new method. But you're right that skip_wait_not_busy
won't be needed anymore if it works.