Merge pull request #608 from rerobika/sdio_write_block_fix

Fix for sdio_write_sectors
This commit is contained in:
Ruslan V. Uss 2018-04-17 01:03:38 +05:00 committed by GitHub
commit 4581999feb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 13 deletions

View file

@ -12,6 +12,7 @@
#define CS_GPIO_PIN 2
#define TEST_FILENAME "/test_loooong_filename.txt"
#define TEST_DIRECTORYNAME "my_directory"
#define TEST_CONTENTS "Hello! It's FatFs on esp8266 with ESP Open RTOS!"
#define READBUF_SIZE 256
#define DELAY_MS 3000
@ -69,6 +70,19 @@ void check_fatfs()
if (failed(f_chdrive(vol)))
return;
// Create a directory if it not exists
FILINFO info;
if (failed(f_stat(TEST_DIRECTORYNAME, &info)) && info.fattrib & AM_DIR)
{
printf("f_mkdir (\"%s\")\n", TEST_DIRECTORYNAME);
if (failed(f_mkdir(TEST_DIRECTORYNAME)))
return;
}
else
{
printf("\"%s\" directory already exists\n", TEST_DIRECTORYNAME);
}
FIL f;
// Create test file
printf("f_open(&f, \"%s\", FA_WRITE | FA_CREATE_ALWAYS)", TEST_FILENAME);

View file

@ -394,16 +394,10 @@ sdio_error_t sdio_write_sectors(sdio_card_t *card, uint32_t sector, uint8_t *src
if (card->type != SDIO_TYPE_SDHC)
sector <<= 9;
if (count == 1)
{
// single block
if (command(card, CMD24, sector))
return set_error(card, SDIO_ERR_IO);
return set_error(card, write_data_block(card, TOKEN_SINGLE_TRAN, src));
}
bool multi = count != 1;
// send pre-erase count
if ((card->type == SDIO_TYPE_SD1
if (multi && (card->type == SDIO_TYPE_SD1
|| card->type == SDIO_TYPE_SD2
|| card->type == SDIO_TYPE_SDHC)
&& app_command(card, ACMD23, count))
@ -411,16 +405,19 @@ sdio_error_t sdio_write_sectors(sdio_card_t *card, uint32_t sector, uint8_t *src
return set_error(card, SDIO_ERR_IO);
}
if (command(card, CMD25, sector))
if (command(card, multi ? CMD25 : CMD24, sector))
return set_error(card, SDIO_ERR_IO);
while (count--)
{
if (write_data_block(card, TOKEN_MULTI_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;
}
spi_transfer_8(BUS, TOKEN_STOP_TRAN);
if (multi && command(card, CMD12, 0))
return set_error(card, SDIO_ERR_IO);
return set_error(card, SDIO_ERR_NONE);
}
@ -449,4 +446,3 @@ sdio_error_t sdio_erase_sectors(sdio_card_t *card, uint32_t first, uint32_t last
return set_error(card, wait() ? SDIO_ERR_NONE : SDIO_ERR_TIMEOUT);
}