2018-03-08 10:59 PM
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.
2018-03-08 11:24 PM
Yes, FatFs provides f_getfree ()
2018-03-12 06:11 AM
Hi Clive,
Thanks for your speedy response. Do you have a piece of sample code where f_getfree() is used?
2018-03-14 11:06 PM
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.
2018-03-15 03:29 AM
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.