Skip to main content
Associate II
April 18, 2024
Solved

How to get free memory on USB drive with FatFs?

  • April 18, 2024
  • 1 reply
  • 1059 views

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.

Best answer by Ondrej1

Reformatting the usb drive fixed my issue.

1 reply

Ondrej1AuthorBest answer
Associate II
April 19, 2024

Reformatting the usb drive fixed my issue.