初级会员

- 积分
- 176
- 金钱
- 176
- 注册时间
- 2016-10-19
- 在线时间
- 52 小时
|
1金钱
在使用fatfs时,看到管理spiflash的时候,原子哥实验说的:#define FATFS_FLASH_SECTOR_SIZE 512
#define FATFS_FLASH_SECTOR_COUNT 1024*25*2
#define FATFS_FLASH_BLOCK_SIZE 8
对于W25Q256(32M),FATFS管理的是25M。这个25M的大小似乎不是人为设置的吧,而是W25Q256内部决定的。找了代码没有看到人为设置的地方。
FRESULT f_getfree (
const TCHAR* path, /* Path name of the logical drive number */
DWORD* nclst, /* Pointer to a variable to return number of free clusters */
FATFS** fatfs /* Pointer to return pointer to corresponding file system object */
)
{
FRESULT res;
FATFS *fs;
DWORD nfree, clst, sect, stat;
UINT i;
BYTE *p;
_FDID obj;
/* Get logical drive number */
res = find_volume(&path, &fs, 0);
if (res == FR_OK) {
*fatfs = fs; /* Return ptr to the fs object */
/* If free_clst is valid, return it without full cluster scan */
if (fs->free_clst <= fs->n_fatent - 2) {
*nclst = fs->free_clst;
} else {
/* Get number of free clusters */
nfree = 0;
if (fs->fs_type == FS_FAT12) { /* FAT12: Sector unalighed FAT entries */
clst = 2; obj.fs = fs;
do {
stat = get_fat(&obj, clst);
if (stat == 0xFFFFFFFF) { res = FR_DISK_ERR; break; }
if (stat == 1) { res = FR_INT_ERR; break; }
if (stat == 0) nfree++;
} while (++clst < fs->n_fatent);
} else {
#if _FS_EXFAT
if (fs->fs_type == FS_EXFAT) { /* exFAT: Scan bitmap table */
BYTE bm;
UINT b;
clst = fs->n_fatent - 2;
sect = fs->database;
i = 0;
do {
if (i == 0 && (res = move_window(fs, sect++)) != FR_OK) break;
for (b = 8, bm = fs->win; b && clst; b--, clst--) {
if (!(bm & 1)) nfree++;
bm >>= 1;
}
i = (i + 1) & (SS(fs) - 1);
} while (clst);
} else
#endif
{ /* FAT16/32: Sector alighed FAT entries */
clst = fs->n_fatent; sect = fs->fatbase;
i = 0; p = 0;
do {
if (i == 0) {
res = move_window(fs, sect++);
if (res != FR_OK) break;
p = fs->win;
i = SS(fs);
}
if (fs->fs_type == FS_FAT16) {
if (ld_word(p) == 0) nfree++;
p += 2; i -= 2;
} else {
if ((ld_dword(p) & 0x0FFFFFFF) == 0) nfree++;
p += 4; i -= 4;
}
} while (--clst);
}
}
*nclst = nfree; /* Return the free clusters */
fs->free_clst = nfree; /* Now free_clst is valid */
fs->fsi_flag |= 1; /* FSInfo is to be updated */
}
}
LEAVE_FF(fs, res);
}
直接使用读取函数读出来也是25M左右。这个大小是怎么来的,有大佬能讲一下吗。
|
最佳答案
查看完整内容[请看2#楼]
自己定义的,宏定义里面可以自己改,改成20M也行。SPI Flash是32M字节的,自己随意分配,只要小于32M字节就行,超过32M字节就会挂载文件系统失败。
|