mirror of
https://github.com/marqs85/ossc.git
synced 2024-09-27 20:56:27 +00:00
ulibSD/sd_io.c: Fix writing to SD card.
There were a few things wrong with the SD card write implementation: 1. The protocol change regarding the interpretation of offsets introduced with SDHC cards was not taken into account in the write path, unlike in the read path. 2. All SPI writes involved in the process were actually issued as reads due to the use of the SPI_RW() function, the implementation of which seems to have gone through some churn. Likely just an instance of bit-rot.
This commit is contained in:
parent
556140dd62
commit
598705c7fa
@ -160,15 +160,15 @@ SDRESULTS __SD_Write_Block(SD_DEV *dev, void *dat, BYTE token)
|
|||||||
WORD idx;
|
WORD idx;
|
||||||
BYTE line;
|
BYTE line;
|
||||||
// Send token (single or multiple)
|
// Send token (single or multiple)
|
||||||
SPI_RW(token);
|
SPI_WW(token);
|
||||||
// Single block write?
|
// Single block write?
|
||||||
if(token != 0xFD)
|
if(token != 0xFD)
|
||||||
{
|
{
|
||||||
// Send block data
|
// Send block data
|
||||||
for(idx=0; idx!=SD_BLK_SIZE; idx++) SPI_RW(*((BYTE*)dat + idx));
|
for(idx=0; idx!=SD_BLK_SIZE; idx++) SPI_WW(*((BYTE*)dat + idx));
|
||||||
/* Dummy CRC */
|
/* Dummy CRC */
|
||||||
SPI_RW(0xFF);
|
SPI_WW(0xFF);
|
||||||
SPI_RW(0xFF);
|
SPI_WW(0xFF);
|
||||||
// If not accepted, returns the reject error
|
// If not accepted, returns the reject error
|
||||||
if((SPI_RW(0xFF) & 0x1F) != 0x05) return(SD_REJECT);
|
if((SPI_RW(0xFF) & 0x1F) != 0x05) return(SD_REJECT);
|
||||||
}
|
}
|
||||||
@ -447,9 +447,13 @@ SDRESULTS SD_Write(SD_DEV *dev, void *dat, DWORD sector)
|
|||||||
#else // uControllers
|
#else // uControllers
|
||||||
// Query ok?
|
// Query ok?
|
||||||
if(sector > dev->last_sector) return(SD_PARERR);
|
if(sector > dev->last_sector) return(SD_PARERR);
|
||||||
|
// Convert sector number to byte address (sector * SD_BLK_SIZE) for SDC1
|
||||||
|
if (!(dev->cardtype & SDCT_BLOCK))
|
||||||
|
sector *= SD_BLK_SIZE;
|
||||||
|
|
||||||
// Single block write (token <- 0xFE)
|
// Single block write (token <- 0xFE)
|
||||||
// Convert sector number to bytes address (sector * SD_BLK_SIZE)
|
// Convert sector number to bytes address (sector * SD_BLK_SIZE)
|
||||||
if(__SD_Send_Cmd(CMD24, sector * SD_BLK_SIZE)==0)
|
if(__SD_Send_Cmd(CMD24, sector)==0)
|
||||||
return(__SD_Write_Block(dev, dat, 0xFE));
|
return(__SD_Write_Block(dev, dat, 0xFE));
|
||||||
else
|
else
|
||||||
return(SD_ERROR);
|
return(SD_ERROR);
|
||||||
|
Loading…
Reference in New Issue
Block a user