cancel
Showing results for 
Search instead for 
Did you mean: 

How to calculate free space on a USB stick using f_getfree

Chris Rice
Associate III

Hello, I found this handy site with example code on getting free space on a USB connected to my STM32F7. The example code says "assuming 512 bytes/sector"... but I can't get the math to work out. How do I tell how many bytes per sector is on my USB drive, and will this be the same for all USB drives? OR is there another query I need to do on the card to figure out this bytes/sector parameter? Thanks!

Oops, here's the handy site. Got me *almost* all the way there.

http://elm-chan.org/fsw/ff/doc/getfree.html

1 REPLY 1
dbgarasiya
Senior II

Hi

using this function, you will get number of free clusters

FRESULT f_getfree (

const TCHAR* path, /* Path name of the logical drive number */

DWORD* nclst, /* Pointer to a variable to return number of free clusters */

FATFS** fatfs /* Pointer to return pointer to corresponding file system object */

)

and evry cluster size is fixed

so based on that you wil get available size of usb stick

Best of luck