How to check free size on a sd card?

wxzhuhua
Posts: 16
Joined: Wed Jun 29, 2016 2:30 pm

How to check free size on a sd card?

Postby wxzhuhua » Fri Nov 25, 2022 3:42 am

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.

microwrk234
Posts: 4
Joined: Tue Nov 22, 2022 11:25 am

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

Postby microwrk234 » Fri Nov 25, 2022 6:46 am

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

wxzhuhua
Posts: 16
Joined: Wed Jun 29, 2016 2:30 pm

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

Postby wxzhuhua » 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.

microwrk234
Posts: 4
Joined: Tue Nov 22, 2022 11:25 am

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

Postby microwrk234 » Fri Nov 25, 2022 11:10 am

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

wxzhuhua
Posts: 16
Joined: Wed Jun 29, 2016 2:30 pm

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

Postby wxzhuhua » Sat Nov 26, 2022 10:20 am

Sounds good, I'll take a check, thank you.

Who is online

Users browsing this forum: ccrause and 241 guests