Skip to content

Commit

Permalink
Merge pull request #667 from UncleRus/sdio_cmd25_fix
Browse files Browse the repository at this point in the history
CMD25 workaround for SDIO, fix #666
  • Loading branch information
UncleRus authored Oct 17, 2018
2 parents f82a420 + e104409 commit 253ac07
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
5 changes: 5 additions & 0 deletions extras/sdio/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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))
24 changes: 20 additions & 4 deletions extras/sdio/sdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 253ac07

Please sign in to comment.