Merge pull request #5694 from adafruit/7.1.x

Merge 7.1.x into main (for sdcard fix)
This commit is contained in:
Limor "Ladyada" Fried 2021-12-09 12:40:13 -05:00 committed by GitHub
commit a24397eeda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 1 deletions

View File

@ -230,11 +230,18 @@ STATIC const compressed_string_t *init_card(sdcardio_sdcard_obj_t *self) {
common_hal_digitalio_digitalinout_set_value(&self->cs, false);
assert(!self->in_cmd25);
self->in_cmd25 = false; // should be false already
// CMD0: init card: should return _R1_IDLE_STATE (allow 5 attempts)
{
bool reached_idle_state = false;
for (int i = 0; i < 5; i++) {
if (cmd(self, 0, 0, NULL, 0, true, true) == R1_IDLE_STATE) {
// do not call cmd with wait=true, because that will return
// prematurely if the idle state is not reached. we can't depend on
// this when the card is not yet in SPI mode
(void)wait_for_ready(self);
if (cmd(self, 0, 0, NULL, 0, true, false) == R1_IDLE_STATE) {
reached_idle_state = true;
break;
}
@ -259,6 +266,7 @@ STATIC const compressed_string_t *init_card(sdcardio_sdcard_obj_t *self) {
return result;
}
} else {
DEBUG_PRINT("Reading card version, response=0x%02x\n", response);
return translate("couldn't determine SD card version");
}
}