Merge pull request #667 from UncleRus/sdio_cmd25_fix

CMD25 workaround for SDIO, fix #666
This commit is contained in:
Ruslan V. Uss 2018-10-17 14:15:48 +05:00 committed by GitHub
commit 253ac0790a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 4 deletions

View file

@ -4,4 +4,9 @@ INC_DIRS += $(sdio_ROOT)..
# args for passing into compile rule generation
sdio_SRC_DIR = $(sdio_ROOT)
# Workaround unsupported CMD25 for very old SD cards
SDIO_CMD25_WORKAROUND ?= 0
sdio_CFLAGS = $(CFLAGS) -DSDIO_CMD25_WORKAROUND=$(SDIO_CMD25_WORKAROUND)
$(eval $(call component_compile_rules,sdio))

View file

@ -49,6 +49,11 @@
#define WRITE_RES_OK 0x05
#ifndef SDIO_CMD25_WORKAROUND
#define SDIO_CMD25_WORKAROUND 0
#endif
#define CMD0 0x00 // GO_IDLE_STATE - Resets the SD Memory Card
#define CMD1 0x01 // SEND_OP_COND - Sends host capacity support information
// and activates the card's initialization process.
@ -420,19 +425,30 @@ sdio_error_t sdio_write_sectors(sdio_card_t *card, uint32_t sector, uint8_t *src
return set_error(card, SDIO_ERR_IO);
}
#if SDIO_CMD25_WORKAROUND
// Workaround for very old cards that don't support CMD25
while (count--)
{
// single block
if (command(card, CMD24, sector))
return set_error(card, SDIO_ERR_IO);
if (write_data_block(card, TOKEN_SINGLE_TRAN, src) != SDIO_ERR_NONE)
return card->error;
src += SDIO_BLOCK_SIZE;
}
#else
if (command(card, multi ? CMD25 : CMD24, sector))
return set_error(card, SDIO_ERR_IO);
while (count--)
{
if (write_data_block(card, multi ? TOKEN_MULTI_TRAN : TOKEN_SINGLE_TRAN, src) != SDIO_ERR_NONE){
return card->error;
}
if (write_data_block(card, multi ? TOKEN_MULTI_TRAN : TOKEN_SINGLE_TRAN, src) != SDIO_ERR_NONE)
return card->error;
src += SDIO_BLOCK_SIZE;
}
if (multi && command(card, CMD12, 0))
return set_error(card, SDIO_ERR_IO);
#endif
return set_error(card, SDIO_ERR_NONE);
}