用的FATFS基本上是参考一个开发板附赠的程序,编译器是IAR 6.60.1,写一张2G的TF卡
跑到readblock这个函数这里
SD_Error SD_ReadBlock(uint8_t *readbuff, uint64_t ReadAddr, uint16_t BlockSize)
{
SD_Error errorstatus = SD_OK;
#if defined (SD_POLLING_MODE)
uint32_t count = 0, *tempbuff = (uint32_t *)readbuff;
#endif
TransferError = SD_OK;
TransferEnd = 0;
StopCondition = 0;
SDIO->DCTRL = 0x0;
#if defined (SD_DMA_MODE)
SDIO_ITConfig(SDIO_IT_DCRCFAIL | SDIO_IT_DTIMEOUT | SDIO_IT_DATAEND | SDIO_IT_RXOVERR | SDIO_IT_STBITERR, ENABLE);
SDIO_DMACmd(ENABLE);
SD_LowLevel_DMA_RxConfig((uint32_t *)readbuff, BlockSize);
#endif
if (CardType == SDIO_HIGH_CAPACITY_SD_CARD)
{
BlockSize = 512;
ReadAddr /= 512;
}
/* Set Block Size for Card */
SDIO_CmdInitStructure.SDIO_Argument = (uint32_t)BlockSize;
SDIO_CmdInitStructure.SDIO_CmdIndex = SD_CMD_SET_BLOCKLEN;
SDIO_CmdInitStructure.SDIO_Response = SDIO_Response_Short;
SDIO_CmdInitStructure.SDIO_Wait = SDIO_Wait_No;
SDIO_CmdInitStructure.SDIO_CPSM = SDIO_CPSM_Enable;
SDIO_SendCommand(&SDIO_CmdInitStructure);
errorstatus = CmdResp1Error(SD_CMD_SET_BLOCKLEN);
if (SD_OK != errorstatus)
{
return(errorstatus);
}
到这里返回错误SD_BLOCK_LEN_ERR,跳出函数,下面的代码都没得跑
f_mount无问题,返回FR_OK
是不是TF卡自身的问题?还是其他方面?
//------------------------------------------------------
嗯,这个问题目前是解决了,是前面一个小细节的错误。
现在是这样的
在chk_mounted函数中有这样一段代码
fmt = check_fs(fs, bsect = 0); /* Check sector 0 if it is a VBR */
if (fmt == 1) { /* Not an FAT-VBR, the disk may be partitioned */
/* Check the partition listed in top of the partition table */
tbl = &fs->win[MBR_Table + LD2PT(vol) * 16]; /* Partition table */
if (tbl[4]) { /* Is the partition existing? */
bsect = LD_DWORD(&tbl[8]); /* Partition offset in LBA */
fmt = check_fs(fs, bsect); /* Check the partition */
}
}
if (fmt == 3) return FR_DISK_ERR;
if (fmt) return FR_NO_FILESYSTEM; /* No FAT volume is found */
无非就是检测FAT分区的分区表和主引导记录之类
调用check_fs函数读取MBR和DBR的时候
BYTE check_fs ( /* 0:The FAT BR, 1:Valid BR but not an FAT, 2:Not a BR, 3 isk error */
FATFS *fs, /* File system object */
DWORD sect /* Sector# (lba) to check if it is an FAT boot record or not */
)
{
unsigned long int watch_pointer1;
// disk_read(fs->drv, fs->win, sect, 1);
watch_pointer1=LD_WORD(&fs->win[BS_55AA]);
if (disk_read(fs->drv, fs->win, sect, 1) != RES_OK) /* Load boot record */
{
return 3;
}
watch_pointer1=LD_WORD(&fs->win[BS_55AA]);
if (LD_WORD(&fs->win[BS_55AA]) != 0xAA55) /* Check record signature (always placed at offset 510 even if the sector size is >512) */
return 2;
if ((LD_DWORD(&fs->win[BS_FilSysType]) & 0xFFFFFF) == 0x544146) /* Check "FAT" string */
return 0;
if ((LD_DWORD(&fs->win[BS_FilSysType32]) & 0xFFFFFF) == 0x544146)
return 0;
return 1;
}
首先,BS_55AA是510,但实际上我们读回来的0xAA55位置是在508和509
其次,BS_FileType和BS_FileType32处没有分区表的信息,全部为0
第三就是如果将BS_55AA改到可以读回AA55的位置(508),依然没法读取到DBR
不知道有没有人知道这是什么问题
|