cancel
Showing results for 
Search instead for 
Did you mean: 

How to get free memory on USB drive with FatFs?

Ondrej1
Associate II

Hello,

I would like to get free memory on USB drive (64GB, FAT32) with FatFs library. Here is part of my code:

 

 

DWORD fre_clust, fre_sect;
uint64_t free_memory;

res_file = f_mount(&fs, "0:", 1);
res_file = f_getfree("0:", &fre_clust, &fs);
fre_sect = fre_clust * fs.csize;
free_memory = (uint64_t)((uint64_t)fre_sect*(uint64_t)fs.ssize)/1048576;//MB

 

 

The problem is that f_getfree() always returns same value, even if data size is changed.

Also I would like to say that res_file has return value FR_OK in both cases and

Iam able to write data on USB drive with FatFs.

 

(Iam using STM32CubeIDE 1.14.1 and STM32H753)

 

Does anyone know what Iam doing wrong?

Thank you for your response.

1 ACCEPTED SOLUTION

Accepted Solutions
Ondrej1
Associate II

Reformatting the usb drive fixed my issue.

View solution in original post

1 REPLY 1
Ondrej1
Associate II

Reformatting the usb drive fixed my issue.