cancel
Showing results for 
Search instead for 
Did you mean: 

SD card memory status checking

Niyathi Shenoy
Associate II
Posted on March 09, 2018 at 07:59

Hi I am storing files into SD card using the SDIO interface. I am using a 32 GB sd card. Now i want to check everytime how much space is available on the sd  card. Are there any API's available to do this? I am using STM32F407.

4 REPLIES 4
Posted on March 09, 2018 at 08:24

Yes, FatFs provides f_getfree ()

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on March 12, 2018 at 13:11

Hi Clive,

Thanks for your speedy response. Do you have a piece of sample code where f_getfree() is used?

Posted on March 15, 2018 at 06:06

Hi clive,

I am using a 32 GB SD card,

My code by using the API f_getfree() is as follows:

if (f_mount(&myFATAFS, SDPath, 1) == FR_OK) {

HAL_GPIO_TogglePin(GPIOD, GPIO_PIN_12);

f_getfree('1:', &Free_clust, &myFATAFS);

tot_sect = (myFATAFS.n_fatent - 2) * myFATAFS.csize;

fre_sect = Free_clust * myFATAFS.csize;

sprintf(coeff3,'%10lu MiB total drive space.\n\r %10lu MiB available.\n\r', tot_sect/2/1024,Free_clust/2/1024);

HAL_UART_Transmit(&huart2,(uint8_t *) coeff3, 65, 50);

}

But the output that i get is as follows :

30416 MiB total drive space.

0 MiB available.

However, my SD card is formatted and there is nothing in it.Please help me here.

Posted on March 15, 2018 at 10:29

Also, f_getfree API returns a FR_INVALID_DRIVE error i.e., finding the logical drive function returns me the volume as -1 even if my sd card is connected.But a f_write api writes files and directories into the sd card. Please help.