|
发表于 2012-6-1 18:26:15
|
显示全部楼层
想请教楼主一个关于fatfs的问题,我现在的片子是lpc1850,自带sd控制器,代码已经移植好,f_mount正常返回0,然后我调用f_open(),返回1.单步跟进去,发现在f_open()函数中的chk_mounted()函数中有这样几句话:
/* Search FAT partition on the drive. Supports only generic partitionings, FDISK and SFD. */
fmt = check_fs(fs, bsect = 0); /* Load sector 0 and check if it is an FAT-VBR (in SFD) */
if (LD2PT(vol) && !fmt) fmt = 1; /* Force non-SFD if the volume is forced partition */
if (fmt == 1) { /* Not an FAT-VBR, the physical drive can be partitioned */
/* Check the partition listed in the partition table */
pi = LD2PT(vol);
if (pi) pi--;
tbl = &fs->win[MBR_Table + pi * SZ_PTE];/* 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;
第一句话返回1,然后进入下面的if,执行fmt = check_fs(fs, bsect);bsect此时等于243,然后进入这个函数,执行if (disk_read(fs->drv, fs->win, sect, 1) != RES_OK),再进入,执行disk_read(这里的sd卡驱动我是按照裸机下的sd卡读写代码加进来的),然后进入执行if (sdmmc_read_blocks((void *) buff, sector, count) != 0),这个函数内有句话: if ((end_block < start_block) || (start_block < 0) || (end_block > g_card_info->blocknr)) return 0; 此时参数end_block=1,start_block=243,很显然返回0,那么依次网上类推到最开始的地方,fmt = check_fs(fs, bsect);这个函数返回的就是1,然后f_open就返回FR_NO_FILESYSTEM。我非常郁闷,这是sd自带的驱动程序。而且我也在1788上测试这个代码,fmt正常返回0。不知道这个问题怎么解决?麻烦楼主指点一二!谢谢! |
|