Hello,
I try to get size of SD card and I use:
DWORD tx;
FATFS *fs;
FRESULT res;
res = f_getfree("0:",&tx,&fs);
then
MMC size: (fs->n_fatent - 2) * fs->csize ) / 2 /1024
MMC free space: (tx * fs->csize) / 2 /1024
Result:
MMC size: 7528
MMC free space: 7178
vs Real:
MMC size: 7708
MMC free space: 6789
the problem is, that (tx * fs->csize) / 2 /1024 returns only value 7178.
Can me sombody help?
Thank you
Hello,
so in new libraryff13a.zip works f_fetfree but there is again a problem with the function f_open.
Hi Jan,
Thanks for your updated information.
What's the problem with the f_open, it returns open failed? Please give me more details about it.
As you know, the official lpcopen code is really old, so it use the old fatfs file, I think in that time, the fatfs lib also have the getfree problem, that's why it updated it in the new version.
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hi Kerry,
when I started to use new library ff13a.zip, I can't write anything in the
file....
The problem is in the function :
FRESULT find_volume ( /* 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 filesystem object */
BYTE mode /* !=0: Check write protection for write access */
)
I dont know why, but this function doesnt work... .
Whe I import the library ff13a.zip, the problem can be:
- I use the file fs_mci.c , this file has the functions as a file diskio.c
(ff13a.zip)
- the problem can be in that, functions in fs_mci.c are changed by NXP and
if I want to use new library ff13a.zip, I have to change the diskio.c
I have to do update because in old library doesn't wok f_getfree.
This function works with #define FF_FS_NOFSINFO 1.
But FF_FS_NOFSINFO is from release ff10.
I am satisfied with old library, but I need to know free space in SD card.
Thank you for help
J.M.
Hi J.M,
If you still want to use the old library, I have another thought, if you have interest, you can try it on your side.
In the old library, just compare the difference of f_getfree with the new library, then copy the new f_getfree.function to old library, whether it works or not?
You can try it, any updated information, you can let me know.
When I have time, I also will try the new fatfs lib porting.
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hello,
i want to try it,but it is very complicated..
I look also o lpc54xx and there is newer library,i copied this library on
lpc18,but doesnt work...
Thanks for help
Hi Jan,
I will try it on my side, then will let you know the updated information, please wait patiently.
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hello Kerry,
super, thank you...
Hello Jan,
From your code, you are using the FatFs system in your SD card.
Do you mean, why your returned free space is smaller than the total MMC size?
If yes, as you know, the FatFS system file also need to occupy the SD size, the other size is used by the Fatfs system, more details, you can find some knowledge about the FatFs system files.
Wish it helps you!
If you still have question about it, please kindly let me know.
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hello Kerry,
thank you for answer. Yes, I use SD card, where is FAT32. I have SD card 8Gb.
But:
The card has free space 6789bytes. The function returns: 7178 bytes.
The card has free space 1200bytes. The function returns: 7178 bytes.
The problem is, the function returns the same value and it doesnt depend on free space on the SD card. I think a little, that problem is with function f_getfree.
It may have a solution, that I read all files on SD card and make a sum of size files. But it is not correct solutions...
Thanks
Jan,
I just grabbed my code when using FATFs (I use this same code across all my projects) and it seems to work ok:
If it helps you or not I don't know. But maybe there are some pointers
int i;
DWORD fre_clust, fre_sect, tot_sect;
if (i=f_mount(&Fatfs, "0:", 1) != FR_OK) {
messageDebug(DBG_ERR, __MODULE__, __LINE__,"f_mount(1) returned %i", i);
return 1;
} else {
messageDebug(DBG_WAR, __MODULE__, __LINE__,"-----------------------------------------------");
messageDebug(DBG_WAR, __MODULE__, __LINE__,"SD Card mounted succesfully");
// Print free space in unit of KB (assuming 512 bytes/sector)
f_getfree("0:", &fre_clust, &fs);
// Get total sectors and free sectors
tot_sect = (fs->n_fatent - 2) * fs->csize;
fre_sect = fre_clust * fs->csize;
OS_WAIT(200);
messageDebug(DBG_WAR, __MODULE__, __LINE__," %lu KB total drive space", tot_sect / 2);
messageDebug(DBG_WAR, __MODULE__, __LINE__," %lu KB available (%lu KB used)", fre_sect / 2, (tot_sect / 2) - (fre_sect / 2));
messageDebug(DBG_WAR, __MODULE__, __LINE__,"-----------------------------------------------");
fileSystemValid=TRUE;
return 0;
}
Hello Carsten,
thank you for your help. I don't use OS, so f_mount is:
FRESULT f_mount (
BYTE vol, /* Logical drive number to be mounted/unmounted */
FATFS *fs /* Pointer to new file system object (NULL for unmount)*/
)
I try it again:
DWORD fre_clust, fre_sect, tot_sect;
FATFS *fs;
FRESULT res;
NVIC_DisableIRQ(SDIO_IRQn);
Chip_Clock_Disable(CLK_MX_SDIO);
Chip_SDIF_DeInit(LPC_SDMMC);
App_SDMMC_Init();
NVIC_EnableIRQ(SDIO_IRQn);
f_mount(0, &Fatfs);
res = f_getfree("0:", &fre_clust, &fs);
tot_sect = (fs->n_fatent - 2) * fs->csize;
fre_sect = fre_clust * fs->csize;
//debug into file
res_file = f_open(&Fil, "SD_info.txt", FA_WRITE | FA_CREATE_ALWAYS);
itoa(res, str_file, 10);
f_write(&Fil, str_file, strlen(str_file), &bw);
f_write(&Fil, "\n", 1, &bw);
itoa(fs->n_fatent, str_file, 10);
f_write(&Fil, str_file, strlen(str_file), &bw);
f_write(&Fil, "\n", 1, &bw);
itoa(fre_clust, str_file, 10);
f_write(&Fil, str_file, strlen(str_file), &bw);
f_write(&Fil, "\n", 1, &bw);
//total drive space
itoa(tot_sect / 2 , str_file, 10);
f_write(&Fil, str_file, strlen(str_file), &bw);
f_write(&Fil, "\n", 1, &bw);
//free space
itoa(fre_sect / 2 , str_file, 10);
f_write(&Fil, str_file, strlen(str_file), &bw);
f_write(&Fil, "\n", 1, &bw);
f_close(&Fil);
And:
SD card from Total commander:
Free space: 4 149 056 kB
SD size: 7 708 672 kB
From program:
0 -> OK - return value from f_getfree
120450 -> fs->n_fatent
64830 ->fre_clust
7708672 -> total drive space: 7708672/1024 = 7528MB
4149120 -> free space: 4149120/1024 = 4051MB
I don't understand, why now it works. I did only "Error Control" in Windows .
The code from my question is "same"....
Hi Jan,
1. You said, you are using only "Error Control" in Windows .
Could you give me more details about this, give me a picture about it.
2. About the hardware, you can try do the fat32 Format at first, then insert it to your board, test it again.
3. About the software, f_getfree, after check the the fatfs official website,
I find these information:
FF_FS_NOFSINFO can be configured in the ffconf.h, you also can try this solutions.
Wish it helps you!
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Hello Kerry,
1) "Error control " - I thought (I have it only in Czech language):
2) I will try it, but the problem will habe the Customer again, when the card will not be formatted...
3) Thanks for links. I found this also, but in LPC library isn't hasn't FF_FS_NOFSINFO in ffconf.h (anywhere).
Hi Jan,
I think you can try the newest Fatfs file package, you can download it from the fatfs offiical website:
http://elm-chan.org/fsw/ff/arc/ff13a.zip
This package, ffconf.h have the FF_FS_NOFSINFO definition.
Have a great day,
Kerry
-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------
Ok, thanks.
I use Fatfs file package from examples LPCopen 2.X.
So I did library update - ff13a.zip and then I set up FF_FS_NOFSINFO to 1 and it works:)
When I use old library, function f_getfree returns the same value. I can delete or add files, the return value was the same. Now it is correct...