初级会员

- 积分
- 182
- 金钱
- 182
- 注册时间
- 2016-4-7
- 在线时间
- 41 小时
|

楼主 |
发表于 2016-10-27 23:55:00
|
显示全部楼层
没有用啊,我用的fatfs的版本里有[mw_shl_code=c,true]fmt = check_fs(fs, bsect); /* Load sector 0 and check if it is an FAT boot sector as SFD */
if (fmt == 1 || (!fmt && (LD2PT(vol)))) { /* Not an FAT boot sector or forced partition number */
for (i = 0; i < 4; i++) { /* Get partition offset */
pt = fs->win + MBR_Table + i * SZ_PTE;
br = pt[4] ? LD_DWORD(&pt[8]) : 0;
}
i = LD2PT(vol); /* Partition number: 0:auto, 1-4:forced */
if (i) i--;
do { /* Find an FAT volume */
bsect = br;
fmt = bsect ? check_fs(fs, bsect) : 2; /* Check the partition */
} while (!LD2PT(vol) && fmt && ++i < 4);
}[/mw_shl_code]
今天研究发现,MSD_ReadBlock()在读取DBR扇区时有时会收不到响应,导致检测不到"FAT",所以返回没有文件系统。请问啥原因,spi应该是没问题的啊
[mw_shl_code=applescript,true]uint8_t MSD_ReadBlock(uint8_t* pBuffer, uint32_t ReadAddr, uint16_t NumByteToRead)
{
uint32_t i = 0,len,Times;
uint8_t rvalue = MSD_RESPONSE_FAILURE;
uint8_t lDUMMY = 0XFF;
// MSD_SpiSpeedSet(1);//高速模式
/* MSD chip select low */
MSD_CS_LOW();
/* Send CMD17 (MSD_READ_SINGLE_BLOCK) to read one block */
MSD_SendCmd(MSD_READ_SINGLE_BLOCK, ReadAddr, 0xFF);
/* Check if the MSD acknowledged the read block command: R1 response (0x00: no errors) */
if (!MSD_GetResponse(MSD_RESPONSE_NO_ERROR))
{
/* Now look for the data token to signify the start of the data */
if (!MSD_GetResponse(MSD_START_DATA_SINGLE_BLOCK_READ))
{
//--------------------------
Times = NumByteToRead / 8;
while(Times--)
{
for(i = 0;i < 8;i++)
{
SPI_SpiUartWriteTxData(DUMMY);
}
SPI_SpiUartClearTxBuffer();
for(i = 0;i < 8;i++)
{
*pBuffer = SPI_SpiUartReadRxData();
pBuffer++;
}
}
/* Get CRC bytes (not really needed by us, but required by MSD) */
for(i = 0;i < 2;i++)
{
SPI_SpiUartWriteTxData(DUMMY);
}
SPI_SpiUartClearTxBuffer();
/* Set response value to success */
rvalue = MSD_RESPONSE_NO_ERROR;
}
}
/* MSD chip select high */
MSD_CS_HIGH();
/* Send dummy byte: 8 Clock pulses of delay */
MSD_WriteByte(DUMMY);
/* Returns the reponse */
// MSD_SpiSpeedSet(0);
return rvalue;
}[/mw_shl_code]
|
|