From e616e22dd7bc768a659febcc72638b3b8d8fcda5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Wed, 26 Feb 2020 23:52:42 +0100 Subject: [PATCH] Improve single block writing and reading --- fatfs/shimatta_sdio_driver/shimatta_sdio.c | 24 +++++++++---------- .../shimatta_sdio_config.h | 4 ++-- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/fatfs/shimatta_sdio_driver/shimatta_sdio.c b/fatfs/shimatta_sdio_driver/shimatta_sdio.c index ebf48a5..a64e4d2 100644 --- a/fatfs/shimatta_sdio_driver/shimatta_sdio.c +++ b/fatfs/shimatta_sdio_driver/shimatta_sdio.c @@ -373,9 +373,12 @@ static void sdio_init_hw() static int sdio_send_read_block_cmd17(uint32_t addr) { uint32_t response; - + int retry; + int ret; + sdio_send_cmd(17, addr, SHORT_ANS); - return sdio_get_response(17, SHORT_ANS, &response); + ret = sdio_get_response(17, SHORT_ANS, &response); + return ret; } static int sdio_send_all_send_cid_cmd2() @@ -605,6 +608,7 @@ DRESULT sdio_disk_read(BYTE *buff, DWORD sector, UINT count){ uint32_t sdio_status; uint32_t fifo; uint32_t counter; + union sdio_status_conv status; addr = (card_info.type == SD_V2_HC ? (sector) : (sector*512)); for (; count > 0; count--) { @@ -619,7 +623,13 @@ DRESULT sdio_disk_read(BYTE *buff, DWORD sector, UINT count){ // DMASTREAM->CR = DMAP2M | DMA_SxCR_PL_1 | DMA_SxCR_PL_1; // DMASTREAM->CR |= DMA_SxCR_EN; + + do { + sdio_check_status_register_cmd13(card_info.rca, &status.value); + } while (status.statusstruct.CURRENT_STATE != CURRENT_STATE_TRAN); + SDIO->DLEN = (1 << BLOCKSIZE); + SDIO->DTIMER = DTIMEOUT; SDIO->ICR = SDIO_ICR_CCRCFAILC | SDIO_ICR_DCRCFAILC | SDIO_ICR_CTIMEOUTC | SDIO_ICR_DTIMEOUTC | SDIO_ICR_TXUNDERRC | SDIO_ICR_RXOVERRC | SDIO_ICR_CMDRENDC | SDIO_ICR_CMDSENTC | SDIO_ICR_DATAENDC | @@ -704,16 +714,6 @@ DRESULT sdio_disk_write(const BYTE *buff, DWORD sector, UINT count) addr = (card_info.type == SD_V2_HC ? (sector) : (sector * 512)); while (count) { - do { - sdio_check_status_register_cmd13(card_info.rca, &status.value); - } while (status.statusstruct.CURRENT_STATE == CURRENT_STATE_PRG || - status.statusstruct.CURRENT_STATE == CURRENT_STATE_RCV); - - if (status.statusstruct.CURRENT_STATE == CURRENT_STATE_STBY) { - if (sdio_send_select_card_cmd7(card_info.rca)) - return RES_ERROR; - } - do { sdio_check_status_register_cmd13(card_info.rca, &status.value); } while (status.statusstruct.READY_FOR_DATA != 1); diff --git a/fatfs/shimatta_sdio_driver/shimatta_sdio_config.h b/fatfs/shimatta_sdio_driver/shimatta_sdio_config.h index e6124c3..97217d7 100644 --- a/fatfs/shimatta_sdio_driver/shimatta_sdio_config.h +++ b/fatfs/shimatta_sdio_driver/shimatta_sdio_config.h @@ -14,9 +14,9 @@ //Initial Transfer CLK (ca. 400kHz) #define INITCLK 130 //120 //Working CLK (Maximum) -#define WORKCLK 50 //0 +#define WORKCLK 8 //0 //Data Timeout in CLK Cycles -#define DTIMEOUT 0x3000 //150 +#define DTIMEOUT 0x8000 //150 //DMA Stream used for TX and RX DMA2 Stream 3 or 6 possible // Currently not used due to possible misalignment of the data buffer. //#define DMASTREAM DMA2_Stream6