我在GD32F4上实现SD卡的FATFS移植。单独对sd读写正常。移植fatfs后,res=f_mkdir(pcVariable); 执行这句时就出现写CMD16时,返回SD_CMD_RESP_TIMEOUT超时。可能是什么原因呢?读写函数为:
DRESULT SD_read(BYTE lun, BYTE *buff, DWORD sector, UINT count)
{
DRESULT res = RES_OK;
if (count > 1)
{
/* Read multiple block */
if(sd_multiblocks_read((uint32_t *)buff,
(uint32_t) (sector * BLOCK_SIZE),
BLOCK_SIZE,
count) != SD_OK)
return RES_ERROR;
/* Check if the Transfer is finished */
}
else
{
/* Read block */
if(sd_block_read((uint32_t *)buff,
(uint32_t) (sector * BLOCK_SIZE),
BLOCK_SIZE) != SD_OK)
return RES_ERROR;
/* Check if the Transfer is finished */
while(sd_transfer_state_get() != SD_NO_TRANSFER);
}
return res;
}
DRESULT SD_write(BYTE lun, const BYTE *buff, DWORD sector, UINT count)
{
DRESULT res = RES_OK;
if (count > 1)
{
/* Write multiple block */
if(sd_multiblocks_write((uint32_t *)buff,
(uint32_t) (sector * BLOCK_SIZE),
BLOCK_SIZE,
count) != SD_OK)
return RES_ERROR;
/* Check if the Transfer is finished */
}
else
{
/* Write block */
if(sd_block_write((uint32_t *)buff,
(uint32_t) (sector * BLOCK_SIZE),
BLOCK_SIZE) != SD_OK)
return RES_ERROR;
/* Check if the Transfer is finished */
while(sd_transfer_state_get() != SD_NO_TRANSFER);
}
return res;
}
谢谢大家 |