中级会员
 
- 积分
- 260
- 金钱
- 260
- 注册时间
- 2013-1-10
- 在线时间
- 10 小时
|
5金钱
关于调用exf_getfree();函数获取sd卡错误,我追踪发现在chk_mounted ()里边返回的值0x0c;
u8 exf_getfree(u8 *drv,u32 *total,u32 *free)
{
FATFS *fs1;
u8 res;
DWORD fre_clust=0, fre_sect=0, tot_sect=0;
//得到磁盘信息及空闲簇数量
res = f_getfree((const TCHAR*)drv, &fre_clust, &fs1);
if(res==0)
{
tot_sect=(fs1->n_fatent-2)*fs1->csize; //得到总扇区数
fre_sect=fre_clust*fs1->csize; //得到空闲扇区数
#if _MAX_SS!=512 //扇区大小不是512字节,则转换为512字节
tot_sect*=fs1->ssize/512;
fre_sect*=fs1->ssize/512;
#endif
*total=tot_sect>>1; //单位为KB
*free=fre_sect>>1; //单位为KB
}
return res;
}
?///////////////////////////////////////////////////////////////////////
static
FRESULT chk_mounted ( /* FR_OK(0): successful, !=0: any error occurred */
const TCHAR **path, /* Pointer to pointer to the path name (drive number) */
FATFS **rfs, /* Pointer to pointer to the found file system object */
BYTE chk_wp /* !=0: Check media write protection for write access */
)
{
BYTE fmt, b, pi, *tbl;
UINT vol;
DSTATUS stat;
DWORD bsect, fasize, tsect, sysect, nclst, szbfat;
WORD nrsv;
const TCHAR *p = *path;
FATFS *fs;
/* Get logical drive number from the path name */
vol = p[0] - '0'; /* Is there a drive number? */
if (vol <= 9 && p[1] == ':') { /* Found a drive number, get and strip it */
p += 2; *path = p; /* Return pointer to the path name */
} else { /* No drive number is given */
#if _FS_RPATH
vol = CurrVol; /* Use current drive */
#else
vol = 0; /* Use drive 0 */
#endif
}
/* Check if the file system object is valid or not */
if (vol >= _VOLUMES) /* Is the drive number valid? */
return FR_INVALID_DRIVE;
*rfs = fs = FatFs[vol]; /* Return pointer to the corresponding file system object */
if (!fs) return
FR_NOT_ENABLED; /* Is the file system object available? */
上边带颜色部分发现fs的值仍为0,所以返回0x0c,不知为什么?请求各位做过fatfs的指示一下,用的是原子哥的例程
|
最佳答案
查看完整内容[请看2#楼]
回复【4楼】雨山:
---------------------------------
你这代码看上去没问题。
用了内存管理么?fs是数组?还是指针?
|