硬件:STM32F103VDT,SD卡工作于SDIO模式;
问题:手上有2张SD卡,一张是128MB,一张是16GB;
128MB的卡,块读、块写、块擦除都OK;
16GB的卡,块读和块写OK,但块擦除不行。擦除命令下发后,从命令响应来看没有问题,但被擦的块读出来,内容没有变;
不知大家是否碰到类似的问题?16GB的卡和128MB的卡有什么不同?
UCHAR SD_Erase(ULONG startblock, ULONG endblock, USHORT blocksize)
{
ULONG delaytime;
UCHAR cardstate = 0;
UCHAR status;
ULONG startAdr,endAdr,ulTemp;
startAdr=startblock;
endAdr=endblock;
/*!< Check if the card coomnd class supports erase command */
if (((CSD_Tab[1] >> 20) & SD_CCCC_ERASE) == 0)
{
return SD_REQUEST_NOT_APPLICABLE;
}
if (SDIO_RESP1 & SD_CARD_LOCKED) //card is locked
{
return SD_LOCK_UNLOCK_FAILED;
}
if (CardType == SD_STD_CAPACITY)
{
startAdr *= blocksize;
endAdr *= blocksize;
}
if ((SD_CARD_V1_1== CardType) || (SD_CARD_V2_0 == CardType))
{
SDIO_SendCMD(SD_CMD_SD_ERASE_GRP_START, startAdr, SDIO_RESP_SHORT);
status=SDIO_Resp1State(SD_CMD_SD_ERASE_GRP_START, &ulTemp);
if(status != OK)
{
return FAIL;
}
SDIO_SendCMD(SD_CMD_SD_ERASE_GRP_END, endAdr, SDIO_RESP_SHORT);
status=SDIO_Resp1State(SD_CMD_SD_ERASE_GRP_END, &ulTemp);
if(status != OK)
{
return FAIL;
}
}
SDIO_SendCMD(SD_CMD_ERASE, 0, SDIO_RESP_SHORT);
status=SDIO_Resp1State(SD_CMD_ERASE, &ulTemp);
if(status != OK)
{
return FAIL;
}
delaytime = 120000 / ((SDIO_CLKCR & 0xFF) + 2);
while(delaytime--);
status = IsCardProgramming(&cardstate);
while ((status == OK) && ((SD_CARD_PROGRAMMING == cardstate) || (SD_CARD_RECEIVING == cardstate)))
{
status = IsCardProgramming(&cardstate);
}
return status;
}
|