Page 1 of 1

How to check free size on a sd card?

Posted: Fri Nov 25, 2022 3:42 am
by wxzhuhua
I'm using esp-idf 4.4.2, sd card is on SPI, fatfs mounted.
How to check it's free size?
I tried example_get_fatfs_usage in ext_flash_fatfs example, it don't work.

Re: How to check free size on a sd card?

Posted: Fri Nov 25, 2022 6:46 am
by microwrk234
Are you using this
https://sourcegraph.com/github.com/espr ... ple_main.c
example

try this
int file_space()
{
FATFS *fs;
DWORD fre_clust, fre_sect, tot_sect;
/* Get volume information and free clusters of drive 0 */
int res = 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;
/* Print the free space (assuming 512 bytes/sector) */
printf("%10u KiB total drive space.\r\n%10u KiB available.\r\n%10u free clust.\r\n",tot_sect / 2, fre_sect / 2,fre_clust);
return (fre_sect / 2);
}

or have you already tried this

Re: How to check free size on a sd card?

Posted: Fri Nov 25, 2022 9:43 am
by wxzhuhua
Yeah, I'm using that example, and already tried the f_getfree code, which don't work( got both 0 size)
I also tried to use 1: or 2: instead of 0: in f_getfree, they would make the program crash.

Any ideas?

Thanks for replying.

Re: How to check free size on a sd card?

Posted: Fri Nov 25, 2022 11:10 am
by microwrk234
wxzhuhua wrote:
Fri Nov 25, 2022 9:43 am
Yeah, I'm using that example, and already tried the f_getfree code, which don't work( got both 0 size)
I also tried to use 1: or 2: instead of 0: in f_getfree, they would make the program crash.

Any ideas?

Thanks for replying.
https://sourcegraph.com/github.com/espr ... ver=pinned

check whether this function works

Re: How to check free size on a sd card?

Posted: Sat Nov 26, 2022 10:20 am
by wxzhuhua
Sounds good, I'll take a check, thank you.