Get SD card free space not updating?
Posted: Fri Mar 29, 2019 7:43 pm
I am able to read SD card free space by using this function:
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.
- bool SD_getFreeSpace(uint32_t *tot, uint32_t *free)
- {
- FATFS *fs;
- DWORD fre_clust, fre_sect, tot_sect;
- /* Get volume information and free clusters of drive 0 */
- if(f_getfree("0:", &fre_clust, &fs) == FR_OK)
- {
- /* Get total sectors and free sectors */
- tot_sect = (fs->n_fatent - 2) * fs->csize;
- fre_sect = fre_clust * fs->csize;
- *tot = tot_sect / 2;
- *free = fre_sect / 2;
- /* Print the free space (assuming 512 bytes/sector) */
- ESP_LOGD(TAG, "%10lu KiB total drive space. %10lu KiB available.", *tot, *free);
- return true;
- }
- return false;
- }
Currently I am opening and closing an empty file to do this.