Page 1 of 1

Get SD card free space not updating?

Posted: Fri Mar 29, 2019 7:43 pm
by gunar.kroeger
I am able to read SD card free space by using this function:
  1. bool SD_getFreeSpace(uint32_t *tot, uint32_t *free)
  2. {
  3.     FATFS *fs;
  4.     DWORD fre_clust, fre_sect, tot_sect;
  5.  
  6.     /* Get volume information and free clusters of drive 0 */
  7.     if(f_getfree("0:", &fre_clust, &fs) == FR_OK)
  8.     {
  9.         /* Get total sectors and free sectors */
  10.         tot_sect = (fs->n_fatent - 2) * fs->csize;
  11.         fre_sect = fre_clust * fs->csize;
  12.  
  13.         *tot = tot_sect / 2;
  14.         *free = fre_sect / 2;
  15.  
  16.         /* Print the free space (assuming 512 bytes/sector) */
  17.         ESP_LOGD(TAG, "%10lu KiB total drive space. %10lu KiB available.", *tot, *free);
  18.  
  19.         return true;
  20.     }
  21.     return false;
  22. }
But even if I remove the SD card after I mounted the card I still get the same values as before removing the card. Is there a way to get free and total space without unmounting and remounting the SD card? I wish to check at least if the SD card has been removed.
Currently I am opening and closing an empty file to do this.

Re: Get SD card free space not updating?

Posted: Sat Apr 06, 2019 8:09 am
by pilidfast-mail
That's the software bug, nothing to do with hardware. Report the issue, next update might (will) solve it.

Re: Get SD card free space not updating?

Posted: Mon Apr 08, 2019 3:20 pm
by gunar.kroeger
pilidfast-mail wrote:
Sat Apr 06, 2019 8:09 am
That's the software bug, nothing to do with hardware. Report the issue, next update might (will) solve it.
https://github.com/espressif/esp-idf/issues/3278