Allow read/write more then one sector (512 bytes) in one time

pull/52/head
DiSlord Live 3 years ago
parent 84342fbd43
commit 517428bd01

@ -1351,7 +1351,7 @@ static bool SD_RxDataBlock(uint8_t *buff, uint16_t len, uint8_t token) {
} }
// Transmit data block to SD // Transmit data block to SD
static bool SD_TxDataBlock(const uint8_t *buff, uint8_t token) { static bool SD_TxDataBlock(const uint8_t *buff, uint16_t len, uint8_t token) {
uint8_t resp; uint8_t resp;
// Transmit token // Transmit token
spi_TxByte(token); spi_TxByte(token);
@ -1361,13 +1361,13 @@ static bool SD_TxDataBlock(const uint8_t *buff, uint8_t token) {
#endif #endif
#ifdef __USE_SDCARD_DMA__ #ifdef __USE_SDCARD_DMA__
spi_DMATxBuffer((uint8_t*)buff, SD_SECTOR_SIZE, true); spi_DMATxBuffer((uint8_t*)buff, len, true);
#else #else
spi_TxBuffer((uint8_t*)buff, SD_SECTOR_SIZE); spi_TxBuffer((uint8_t*)buff, len);
#endif #endif
// Send CRC // Send CRC
#ifdef SD_USE_DATA_CRC #ifdef SD_USE_DATA_CRC
uint16_t bcrc = crc16(buff, SD_SECTOR_SIZE); uint16_t bcrc = crc16(buff, len);
spi_TxWord(bcrc); spi_TxWord(bcrc);
#else #else
spi_TxWord(0xFFFF); spi_TxWord(0xFFFF);
@ -1590,14 +1590,18 @@ DRESULT disk_read(BYTE pdrv, BYTE* buff, DWORD sector, UINT count) {
#endif #endif
SD_Select_SPI(); SD_Select_SPI();
// READ_SINGLE_BLOCK uint8_t cmd = count == 1 ? CMD17 : CMD18;
uint8_t cnt = SD_READ_WRITE_REPEAT; // read repeat count // convert to byte address
do{ if (!(CardType & CT_BLOCK)) sector*= SD_SECTOR_SIZE;
if ((SD_SendCmd(CMD17, sector) == 0) && SD_RxDataBlock(buff, SD_SECTOR_SIZE, SD_TOKEN_START_BLOCK)){ // Read single / multiple block
count = 0; if (SD_SendCmd(cmd, sector) == 0) {
break; do {
} if (SD_RxDataBlock(buff, SD_SECTOR_SIZE, SD_TOKEN_START_BLOCK))
}while (--cnt); buff+= SD_SECTOR_SIZE;
else break;
} while(--count);
}
if (cmd == CMD18) SD_SendCmd(CMD12, 0); // Finish multiple block transfer
SD_Unselect_SPI(); SD_Unselect_SPI();
#if DEBUG == 1 #if DEBUG == 1
@ -1625,9 +1629,6 @@ DRESULT disk_write(BYTE pdrv, const BYTE* buff, DWORD sector, UINT count) {
if (pdrv != 0 || count != 1 || (Stat & STA_NOINIT)) return RES_NOTRDY; if (pdrv != 0 || count != 1 || (Stat & STA_NOINIT)) return RES_NOTRDY;
// Write protection // Write protection
if (Stat & STA_PROTECT) return RES_WRPRT; if (Stat & STA_PROTECT) return RES_WRPRT;
// Convert to byte address if no Block mode
if (!(CardType & CT_BLOCK)) sector*= SD_SECTOR_SIZE;
#if DEBUG == 1 #if DEBUG == 1
#if 0 #if 0
DEBUG_PRINT("Sector write 0x%08X, %d\r\n", sector, count); DEBUG_PRINT("Sector write 0x%08X, %d\r\n", sector, count);
@ -1642,14 +1643,14 @@ DRESULT disk_write(BYTE pdrv, const BYTE* buff, DWORD sector, UINT count) {
#endif #endif
SD_Select_SPI(); SD_Select_SPI();
// WRITE_SINGLE_BLOCK do {
uint8_t cnt = SD_READ_WRITE_REPEAT; // write repeat count // WRITE_SINGLE_BLOCK * count
do{ uint32_t sect = (CardType & CT_BLOCK) ? sector : sector * SD_SECTOR_SIZE;
if ((SD_SendCmd(CMD24, sector) == 0) && SD_TxDataBlock(buff, SD_TOKEN_START_BLOCK)){ if ((SD_SendCmd(CMD24, sect) == 0) && SD_TxDataBlock(buff, SD_SECTOR_SIZE, SD_TOKEN_START_BLOCK)) {
count = 0; sector++;
break; buff+= SD_SECTOR_SIZE;
} } else break;
} while (--cnt); } while (--count);
SD_Unselect_SPI(); SD_Unselect_SPI();
#if DEBUG == 1 #if DEBUG == 1

Loading…
Cancel
Save

Powered by TurnKey Linux.