/** * @brief Storage get free space * @param unit: logical storage unit index. * @retval int */ uint32_t k_StorageGetFree (uint8_t unit) { uint32_t fre_clust = 0; FATFS *fs; FRESULT res = FR_INT_ERR; if(unit == 0) { fs = &USBDISK_FatFs; res = f_getfree("0:", (DWORD *)&fre_clust, &fs); } else if (unit == 1) { fs = &mSDDISK_FatFs; res = f_getfree("1:", (DWORD *)&fre_clust, &fs); } if(res == FR_OK) { return (fre_clust * fs->csize); } else { return 0; } }
void cmd_tree(BaseSequentialStream *chp, int argc, char *argv[]) { FRESULT err; unsigned long clusters; unsigned long long total = 0; FATFS *fsp; (void)argv; if (argc > 0) { SHELLDBG("Usage: tree\r\n"); return; } if (!fs_ready) { SHELLDBG("File System not mounted\r\n"); return; } err = f_getfree("/", &clusters, &fsp); if (err != FR_OK) { err = f_getfree("/", &clusters, &fsp); if (err != FR_OK) { SHELLDBG("FS: f_getfree() failed. FRESULT: %d\r\n", err); return; } } SHELLDBG("FS: %lu free clusters, %lu sectors per cluster, %lu bytes free.\r\n", clusters, (uint32_t)SDC_FS.csize, total); fbuff[0] = 0; sdc_scan_files(chp, (char *)fbuff); }
/* * Executed as event handler at 500mS intervals. */ static void TimerHandler(eventid_t id) { (void)id; if (!palReadPad(IOPORT1, PA_BUTTON1)) { if (fs_ready) { FRESULT err; uint32_t clusters; FATFS *fsp; err = f_getfree("/", &clusters, &fsp); if (err != FR_OK) { chprintf((BaseSequentialStream *)&SD1, "FS: f_getfree() failed\r\n"); return; } chprintf((BaseSequentialStream *)&SD1, "FS: %lu free clusters, %lu sectors per cluster, %lu bytes free\r\n", clusters, (uint32_t)MMC_FS.csize, clusters * (uint32_t)MMC_FS.csize * (uint32_t)MMCSD_BLOCK_SIZE); fbuff[0] = 0; scan_files((BaseSequentialStream *)&SD1, (char *)fbuff); } } else if (!palReadPad(IOPORT1, PA_BUTTON2)) { static WORKING_AREA(waTestThread, 256); Thread *tp = chThdCreateStatic(waTestThread, sizeof(waTestThread), NORMALPRIO, TestThread, &SD1); chThdWait(tp); buzzPlay(500, MS2ST(100)); } }
// Get information about the SD card and interface speed MassStorage::InfoResult MassStorage::GetCardInfo(size_t slot, uint64_t& capacity, uint64_t& freeSpace, uint32_t& speed, uint32_t& clSize) { if (slot >= NumSdCards) { return InfoResult::badSlot; } SdCardInfo& inf = info[slot]; if (!inf.isMounted) { return InfoResult::noCard; } capacity = (uint64_t)sd_mmc_get_capacity(slot) * 1024; speed = sd_mmc_get_interface_speed(slot); String<ShortScratchStringLength> path; path.printf("%u:/", slot); uint32_t freeClusters; FATFS *fs; const FRESULT fr = f_getfree(path.c_str(), &freeClusters, &fs); if (fr == FR_OK) { clSize = fs->csize * 512; freeSpace = (fr == FR_OK) ? (uint64_t)freeClusters * clSize : 0; } else { clSize = 0; freeSpace = 0; } return InfoResult::ok; }
static void cmd_tree(BaseSequentialStream *chp, int argc, char *argv[]) { FRESULT err; uint32_t fre_clust; FATFS *fsp; (void)argv; if (argc > 0) { chprintf(chp, "Usage: tree\r\n"); return; } if (!fs_ready) { chprintf(chp, "File System not mounted\r\n"); return; } err = f_getfree("/", &fre_clust, &fsp); if (err != FR_OK) { chprintf(chp, "FS: f_getfree() failed\r\n"); return; } chprintf(chp, "FS: %lu free clusters with %lu sectors (%lu bytes) per cluster\r\n", fre_clust, (uint32_t)fsp->csize, (uint32_t)fsp->csize * 512); fbuff[0] = 0; scan_files(chp, (char *)fbuff); }
//显示剩余容量 //drv:盘符 //返回值:剩余容量(字节) u32 mf_showfree(u8 *drv) { FATFS *fs1; u8 res; u32 fre_clust=0, fre_sect=0, tot_sect=0; //得到磁盘信息及空闲簇数量 res = f_getfree((const TCHAR*)drv, &fre_clust, &fs1); if(res==0) { tot_sect = (fs1->n_fatent - 2) * fs1->csize;//得到总扇区数 fre_sect = fre_clust * fs1->csize; //得到空闲扇区数 #if _MAX_SS!=512 tot_sect*=fs1->ssize/512; fre_sect*=fs1->ssize/512; #endif if(tot_sect<20480)//总容量小于10M { /* Print free space in unit of KB (assuming 512 bytes/sector) */ // printf("\r\n磁盘总容量:%d KB\r\n" // "可用空间:%d KB\r\n", // tot_sect>>1,fre_sect>>1); }else { /* Print free space in unit of KB (assuming 512 bytes/sector) */ // printf("\r\n磁盘总容量:%d MB\r\n" // "可用空间:%d MB\r\n", // tot_sect>>11,fre_sect>>11); } } return fre_sect; }
/******************************************************************************* * @函数名称 MP3_getSdSize * @函数说明 文件空间占用情况 * @输入参数 无 * @输出参数 无 * @返回参数 1: 成功 0: 失败 * @注意事项 无 *****************************************************************************/ u8 MP3_getSdSize(SD_sizeInfo *pSdSizeInfo) { FATFS *fs; DWORD fre_clust; res = f_getfree(path, &fre_clust, &fs); /* 必须是根目录,选择磁盘0 */ if ( res==FR_OK ) { //printf("\n\rget %s drive space.\n\r",path); /* Print free space in unit of MB (assuming 512 bytes/sector) */ //printf("%d MB total drive space.\r\n" // "%d MB available.\r\n", // ( (fs->n_fatent - 2) * fs->csize ) / 2 /1024 , (fre_clust * fs->csize) / 2 /1024 ); pSdSizeInfo->totalSize = ((fs->n_fatent - 2) * fs->csize ) / 2 /1024; pSdSizeInfo->availableSize = (fre_clust * fs->csize) / 2 /1024; return 1; } else { printf("\n\rGet total drive space faild!\n\r"); return 0; } }
/* * ======== printDrive ======== * Function to print drive information such as the total disk space * This function was created by referencing FatFs's API documentation * http://elm-chan.org/fsw/ff/en/getfree.html * * This function call may take a while to process, depending on the size of * SD Card used. */ void printDrive(const char *driveNumber, FATFS **fatfs) { FRESULT fresult; DWORD freeClusterCount; DWORD totalSectorCount; DWORD freeSectorCount; System_printf("Reading disk information..."); System_flush(); fresult = f_getfree(driveNumber, &freeClusterCount, fatfs); if (fresult) { System_abort("Error getting the free cluster count from the FatFs object"); } else { System_printf("done\n"); /* Get total sectors and free sectors */ totalSectorCount = ((*fatfs)->n_fatent - 2) * (*fatfs)->csize; freeSectorCount = freeClusterCount * (*fatfs)->csize; /* Print the free space (assuming 512 bytes/sector) */ System_printf("Total Disk size: %10lu KiB\n" "Free Disk space: %10lu KiB\n", totalSectorCount / 2, freeSectorCount / 2); } }
void get_disk_info(void) { FATFS fs; FATFS *fls = &fs; FRESULT res; DWORD clust,tot_sect,fre_sect; res = f_mount(0,&fs); // printf("f_mount---%u---",res); if (res != FR_OK) { printf("\r\n挂载文件系统失败,错误代码: %u",res); return; } res = f_getfree((const TCHAR*)"0:",&clust,&fls); if (res == FR_OK) { tot_sect = (fls->n_fatent - 2) * fls->csize; fre_sect = clust * fls->csize; printf("\r\nfree space in unit of KB (assuming 512B/sector)"); printf("\r\n%lu KB total drive space.\r\n" "%lu KB available.", fre_sect / 2, tot_sect / 2); } else { printf("\r\n获得磁盘信息失败!"); printf("\r\n错误代码: %u",res); } f_mount(0,NULL); }
int FATFileSystem::statvfs(const char *path, struct statvfs *buf) { memset(buf, 0, sizeof(struct statvfs)); FATFS *fs; DWORD fre_clust; lock(); FRESULT res = f_getfree(_fsid, &fre_clust, &fs); if (res != FR_OK) { unlock(); return fat_error_remap(res); } buf->f_bsize = fs->ssize; buf->f_frsize = fs->ssize; buf->f_blocks = (fs->n_fatent - 2) * fs->csize; buf->f_bfree = fre_clust * fs->csize; buf->f_bavail = buf->f_bfree; #if FF_USE_LFN buf->f_namemax = FF_LFN_BUF; #else buf->f_namemax = FF_SFN_BUF; #endif unlock(); return 0; }
// Отображение статуса устройства void PrintStorageStatus(void) { unsigned long rLong; WORD rWord; BYTE rByte; if (disk_ioctl(0, GET_SECTOR_COUNT, &rLong) == RES_OK) { printf("Drive size: %u sectors\r\n", (unsigned int)rLong); } if (disk_ioctl(0, GET_SECTOR_SIZE, &rWord) == RES_OK) { printf("Sector size: %u\r\n", rWord); } if (disk_ioctl(0, GET_BLOCK_SIZE, &rLong) == RES_OK) { printf("Erase block size: %u sectors\r\n", (unsigned int)rLong); } if (disk_ioctl(0, MMC_GET_TYPE, &rByte) == RES_OK) { printf("MMC/SDC type: %u\r\n", rByte); } FATFS *fs = &_FatFs; rByte = f_getfree("", (DWORD*)&rLong, &fs); if (!rByte) { printf("FAT type = %u (%s)\n\rNumber of FATs = %u\n\r", (WORD)_FatFs.fs_type, (_FatFs.fs_type==FS_FAT12) ? "FAT12" : (_FatFs.fs_type==FS_FAT16) ? "FAT16" : "FAT32", (WORD)_FatFs.n_fats); } else { printf("Cannot get more info. Error in getfree: %d\n\r", rByte); } }
FRESULT getMountedMemorySize(uint8_t mount_ret, uint32_t * totalSize, uint32_t * availableSize) { FATFS *fs; DWORD fre_clust, fre_sect, tot_sect; FRESULT res; /* Get volume information and free clusters of drive 1 */ if(mount_ret == SPI_FLASHM) res = f_getfree("0:", &fre_clust, &fs); //else if((mount_ret >= CARD_MMC) && (mount_ret <= CARD_SDHC)) // res = f_getfree("1:", &fre_clust, &fs); if (!res) { /* Get total sectors and free sectors */ tot_sect = (fs->n_fatent - 2) * fs->csize; fre_sect = fre_clust * fs->csize; /* Print the free space (assuming 512 bytes/sector) */ //printf(" - Available memory size : %8ld / %8ld kB\r\n", fre_sect / 2, tot_sect / 2); *totalSize = tot_sect / 2; *availableSize = fre_sect / 2; } return res; }
uint8_t slave_null_read_data(uint8_t slave_addr, uint8_t* buf, uint8_t max_len) { /* limit number of registers to the max. available */ if(max_len > sizeof(modbus_null_input_register_list)) { max_len = sizeof(modbus_null_input_register_list); } #if MODBUS_NULL_SLAVE_SIMULATION == 0 /* Detecta equipamentos de medição e faz a leitura dos dados */ NULL_IRList.Reg.Pressure_Valve = sensors_read(PRESSURE_VALVE); NULL_IRList.Reg.Oil_Level = sensors_read(SENSOR_LEVEL); FATFS *fs; /* Pointer to file system object */ uint32_t p1; if (f_getfree(".", (DWORD*)&p1, &fs) == FR_OK) { NULL_IRList.Reg.SD_bytes_available = (uint32_t)(p1 * fs->csize * 512); } NULL_IRList.Reg.Local_time = (uint32_t)simon_clock_get(); #else uint8_t nregs = 0; /* return random data */ for(nregs = NULL_REGLIST_OFFSET_NREGS; nregs < (NULL_REGLIST_INPUT_NREGS+NULL_REGLIST_OFFSET_NREGS);nregs++) { NULL_IRList.Regs16[nregs] = random_get(); } #endif /* get and set timestamp of reading and device id */ SetModbusHeader(slave_addr, NULL_IRList.Regs8); memcpy(buf,NULL_IRList.Regs8,max_len); return (max_len); }
void LTK_get_disk_info(void) { FATFS fs; FATFS *fls = &fs; FRESULT res; DWORD fre_clust,tot_sect,fre_sect; res = f_mount(0,&fs); if (res != FR_OK) { printf("mont file system error, error code: %u\n",res); return; } res = f_getfree("/",&fre_clust,&fls); if (res == FR_OK) { tot_sect = (fls->n_fatent - 2) * fls->csize; fre_sect = fre_clust * fls->csize; /* Print free space in unit of KB (assuming 512 bytes/sector) */ printf("%lu KB total drive space.\n" "%lu KB available.\n", fre_sect / 2, tot_sect / 2); } else { printf("failed to get disk info, error code: %u\n", res); } f_mount(0,NULL); }
static void cmd_tree(BaseChannel *chp, int argc, char *argv[]) { FRESULT err; uint32_t clusters; FATFS *fsp; (void)argv; if (argc > 0) { chprintf(chp, "Usage: tree\r\n"); return; } if (!fs_ready) { chprintf(chp, "File System not mounted\r\n"); return; } err = f_getfree("/", &clusters, &fsp); if (err != FR_OK) { chprintf(chp, "FS: f_getfree() failed\r\n"); return; } chprintf(chp, "FS: %lu free clusters, %lu sectors per cluster, %lu bytes free\r\n", clusters, (uint32_t)MMC_FS.csize, clusters * (uint32_t)MMC_FS.csize * (uint32_t)MMC_SECTOR_SIZE); fbuff[0] = 0; scan_files(chp, (char *)fbuff); }
void getSDCardInfo() { u8 ret; uint64_t rl; u8 buf[1024]; ret = sd.get_CID(buf); uart1.printf("\r\n========================"); uart1.printf("\r\nget CID Info,ret = %d", ret); uart1.printf("\r\n"); uart1.printf((const char *)buf); rl = sd.get_capacity(); uart1.printf("\r\n========================"); uart1.printf("\r\ncapacity = %dMB", rl / 1024 / 1024); uart1.printf("\r\ncapacity = %0.1fGB", rl / 1024 / 1024/1024.0); uart1.printf("\r\nWaiting..."); res = f_getfree("/", &free_clust, &fss); if(res == FR_OK) { uart1.printf("\r\npartition size:%dMB", (fss->free_clust) * (fss->csize) / 2048); uart1.printf("\r\npartition free sectors: %d", (fss->free_clust) * (fss->csize)); uart1.printf("\r\npartition free clust:%d", free_clust); } else uart1.printf("\r\nget capacity faile,err = %d", res); uart1.printf("\r\nOVER !"); }
int dfs_elm_statfs(struct dfs_filesystem *fs, struct statfs *buf) { FATFS *f; FRESULT res; char driver[4]; DWORD fre_clust, fre_sect, tot_sect; RT_ASSERT(fs != RT_NULL); RT_ASSERT(buf != RT_NULL); f = (FATFS *)fs->data; rt_snprintf(driver, sizeof(driver), "%d:", f->drv); res = f_getfree(driver, &fre_clust, &f); if (res) return elm_result_to_dfs(res); /* Get total sectors and free sectors */ tot_sect = (f->n_fatent - 2) * f->csize; fre_sect = fre_clust * f->csize; buf->f_bfree = fre_sect; buf->f_blocks = tot_sect; #if _MAX_SS != 512 buf->f_bsize = f->ssize; #else buf->f_bsize = 512; #endif return 0; }
static msg_t SdThread(void *arg){ chRegSetThreadName("MicroSD"); (void)arg; FRESULT err; uint32_t clusters; FATFS *fsp; FIL Log; msg_t id; /* wait until card not ready */ NOT_READY: while (!sdcIsCardInserted(&SDCD1)) chThdSleepMilliseconds(SDC_POLLING_INTERVAL); chThdSleepMilliseconds(SDC_POLLING_INTERVAL); if (!sdcIsCardInserted(&SDCD1)) goto NOT_READY; else insert_handler(); /* fs mounted? */ if (!fs_ready) return RDY_RESET; /* are we have at least 16MB of free space? */ err = f_getfree("/", &clusters, &fsp); err_check(); if ((clusters * (uint32_t)SDC_FS.csize * (uint32_t)MMCSD_BLOCK_SIZE) < (16*1024*1024)) return RDY_RESET; /* open file for writing log */ char namebuf[MAX_FILENAME_SIZE]; name_from_time(namebuf); err = f_open(&Log, namebuf, FA_WRITE | FA_CREATE_ALWAYS); err_check(); /* main write cycle * This writer waits msg_t with mavlink message ID. Based on that ID it * will pack extern mavlink struct with proper packing function. */ setGlobalFlag(GlobalFlags.logger_ready); while (TRUE){ /* wait ID */ if (logwriter_mb.fetch(&id, TIME_INFINITE) == RDY_OK){ if (!sdcIsCardInserted(&SDCD1)){ clearGlobalFlag(GlobalFlags.logger_ready); remove_handler(); goto NOT_READY; } err = WriteLog(&Log, id, &fresh_data); err_check(); } err = fs_sync(&Log); err_check(); } return 0; }
uintmax_t FSFreeSpace(const wchar_t *path) { FATFS *fs; DWORD fre_clust; if (f_getfree(path, &fre_clust, &fs) != FR_OK) return 0; return (uintmax_t)fre_clust * fs->csize * _MIN_SS; }
int main(void) { DelayInit(); GPIO_QuickInit(HW_GPIOE, 6, kGPIO_Mode_OPP); UART_QuickInit(UART0_RX_PD06_TX_PD07, 115200); printf("FATFS test\r\n"); printf("please insert SD card...\r\n"); if(SD_QuickInit(20*1000*1000)) { printf("SD card init failed!\r\n"); while(1); } printf("SD size:%dMB\r\n", SD_GetSizeInMB()); FRESULT rc; FATFS fs_sd; FIL fil; FATFS *fs; fs = &fs_sd; UINT bw,br; /* bw = byte writted br = byte readed */ DWORD fre_clust, fre_sect, tot_sect; /* 挂载文件系统 */ rc = f_mount(fs, "0:", 0); ERROR_TRACE(rc); rc = f_getfree("0:", &fre_clust, &fs); ERROR_TRACE(rc); /* 计算磁盘空间及剩余空间 */ tot_sect = (fs->n_fatent - 2) * fs->csize; fre_sect = fre_clust * fs->csize; printf("%d KB total drive space.\r\n%d KB available.\r\n", tot_sect / 2, fre_sect / 2); /* 写入文件 */ printf("open or create file\r\n"); rc = f_open(&fil, "0:/fatfs.txt", FA_WRITE | FA_CREATE_ALWAYS); ERROR_TRACE(rc); printf("write file\r\n"); rc = f_write(&fil, "HelloWorld\r\n", 12, &bw); ERROR_TRACE(rc); printf("%d bytes writen\r\n", bw); rc = f_close(&fil); /* 读取文件 */ rc = f_open(&fil, "0:/fatfs.txt", FA_READ); ERROR_TRACE(rc); printf("file size:%l\r\n", f_size(&fil)); printf("file contents:\r\n"); while(1) { rc = f_read(&fil, buf, sizeof(buf), &br); if(rc || !br ) break; printf("%s", buf); } rc = f_close(&fil); ERROR_TRACE(rc); while(1) { GPIO_ToggleBit(HW_GPIOE, 6); DelayMs(500); } }
uint32_t diskdrive_sector_count() { disk_interface_t* disk = diskdrive_get_disk(current_drive); FATFS *fs; DWORD fre_clust; DWORD tot_sect; f_getfree(disk->volume.lvn, &fre_clust, &fs); tot_sect = (fs->n_fatent - 2) * fs->csize; return (uint32_t)tot_sect; }
unsigned int long long getpartitionfree(const TCHAR* driverpath){ unsigned long freeclst; FATFS *fs; FRESULT r ; r = f_getfree(driverpath,&freeclst,&fs); if (FR_OK!=r) { return 0; } return (long long)freeclst * fs->csize * SS(fs); }
uint32_t sdGetFreeSectors() { DWORD nofree; FATFS * fat; if (f_getfree("", &nofree, &fat) != FR_OK) { return 0; } return nofree * fat->csize; }
void setup() { ebox_init(); uart1.begin(9600); ret = sd.begin(); if(!ret) uart1.printf("\r\nsdcard init ok!"); f_mount(0, &fs); w5500.begin(mac,lip,sub,gw); attachEthToSocket(&w5500); attachSDCardToFat(&sd); w5500.getMAC (ip); uart1.printf("\r\nmac : %02x.%02x.%02x.%02x.%02x.%02x\r\n", ip[0],ip[1],ip[2],ip[3],ip[4],ip[5]); w5500.getIP (ip); uart1.printf("IP : %d.%d.%d.%d\r\n", ip[0],ip[1],ip[2],ip[3]); w5500.getSubnet(ip); uart1.printf("mask : %d.%d.%d.%d\r\n", ip[0],ip[1],ip[2],ip[3]); w5500.getGateway(ip); uart1.printf("GW : %d.%d.%d.%d\r\n", ip[0],ip[1],ip[2],ip[3]); uart1.printf("Network is ready.\r\n"); if(udp1.begin(0,30000) == 0) uart1.printf("\r\nudp1 server creat ok! listen on 30000"); uart1.printf("\r\nret = %d",ret); ret = sd.getCID(buf); uart1.printf("\r\nret = %d",ret); uart1.printf((const char*)buf); ret = sd.getCSD(buf); uart1.printf("\r\nret = %d",ret); rl = sd.getCapacity(); x = (float)rl; uart1.printf("\r\n容量 = %f",x/1024/1024); res=f_getfree("/",&free_clust,&fss); uart1.printf("该分区所有扇区数为:%d\r\n",(fss->max_clust-2)*(fss->csize)); if(res==FR_OK) { uart1.printf("该分区所有扇区数为:%d\r\n",(fss->max_clust-2)*(fss->csize)); uart1.printf("该分区大小为:%dM\r\n",(fss->max_clust-2)*(fss->csize)/2048); uart1.printf("该分区空簇数为:%d\r\n",free_clust); uart1.printf("该分区空扇区数为:%d\r\n",free_clust*(fss->csize)); } else uart1.printf("获取分区空簇失败\r\n,res = %d",res); uart1.printf("\r\n"); }
uint32_t diskdrive_clusters_free() { disk_interface_t* disk = diskdrive_get_disk(current_drive); if(disk) { FATFS *fs; DWORD nclst; f_getfree(disk->volume.lvn, &nclst, &fs); return nclst; } return 0; }
int getSDFreeSpace() { FATFS *fs1; DWORD fre_clust,fre_sect; DWORD free = 0; FRESULT res; res = f_getfree((const TCHAR*)SDPath, (DWORD*)&fre_clust, &fs1); if(res==FR_OK) { fre_sect=fre_clust*fs1->csize; free=fre_sect>>1; return free; }
/********************************************************************** functionName:float get_free_space(void) description:获取SD卡剩余空间,单位是Mb **********************************************************************/ FRESULT get_free_space(float *space) { FRESULT fresult; unsigned long free_space=0; FATFS *fs; fresult = f_getfree("/", &free_space, &fs); if(fresult != FR_OK) { *space=0; return(fresult); } *space=free_space * fs->csize /2048.0f; //之前用的时0.04版本的FATFS系统,0.07E版本的文件系统不一样 return FR_OK; }
void sdcardInit(void) { /* static const evhandler_t evhndl[] = { InsertHandler, RemoveHandler }; struct EventListener el0, el1; */ palSetPadMode(GPIOC, 8, PAL_MODE_ALTERNATE(12) | PAL_STM32_OSPEED_HIGHEST); palSetPadMode(GPIOC, 9, PAL_MODE_ALTERNATE(12) | PAL_STM32_OSPEED_HIGHEST); palSetPadMode(GPIOC, 10, PAL_MODE_ALTERNATE(12) | PAL_STM32_OSPEED_HIGHEST); palSetPadMode(GPIOC, 11, PAL_MODE_ALTERNATE(12) | PAL_STM32_OSPEED_HIGHEST); palSetPadMode(GPIOC, 12, PAL_MODE_ALTERNATE(12) | PAL_STM32_OSPEED_HIGHEST); palSetPadMode(GPIOD, 2, PAL_MODE_ALTERNATE(12) | PAL_STM32_OSPEED_HIGHEST); chThdSleepMilliseconds(50); sdcStart(&SDCD1, NULL); chThdSleepMilliseconds(50); InsertHandler(0); FRESULT err; uint32_t clusters; FATFS *fsp; err = f_getfree("/", &clusters, &fsp); int retries = 3; while (err != FR_OK) { InsertHandler(0); chThdSleepMilliseconds(20); err = f_getfree("/", &clusters, &fsp); chThdSleepMilliseconds(50); retries--; if (!retries) break; } }
FRESULT TM_FATFS_DriveSize(uint32_t* total, uint32_t* free) { FATFS *fs; DWORD fre_clust; FRESULT res; // Get volume information and free clusters of drive res = f_getfree("0:", &fre_clust, &fs); if (res != FR_OK) { return res; } // Get total sectors and free sectors *total = (fs->n_fatent - 2) * fs->csize / 2; *free = fre_clust * fs->csize / 2; return FR_OK; }
/** * @brief Storage get free space * @param unit: * @retval int */ uint32_t kStorage_GetFree(void) { uint32_t fre_clust = 0; FATFS *fs ; FRESULT res = FR_INT_ERR; fs = &mSDDISK_FatFs; res = f_getfree("1:", (DWORD *)&fre_clust, &fs); if(res == FR_OK) { return (fre_clust * fs->csize); } else { return 0; } }