0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Zynq > SD書込み (FatFS) > B. microSDの残りサイズを知る

Last updated at Posted at 2015-12-23

自分のメモ整理 (2015/4/9)

microSDの残りサイズを知る

f_getfree()を使う。

f_getfree()を使うには、ffconf.hの設定を変更する必要がある。 f_getfree > 「_FS_READONLY == 0で、且つ_FS_MINIMIZE == 0のとき使用可能です。」。 ZynqFSBL_bsp > ps7_cortexa9_0 > libsrc > xilffs_v2_2 > src > include > ffconf.h の以下を変更する

  • #define _FS_READONLY 0 (デフォルト0のため変更なし)
  • #define _FS_MINIMIZE 0 (デフォルト1となっているので、0にする)

SDのトータルサイズと空きサイズを知るには以下のコードをベアメタルアプリに追加してfile_getDiskSizeInfo()を使う

test.c
# include "ff.h" // for FatFS
 
 
# define RET_NG (-1)
# define RET_OK (0)
 
 
static signed int file_getDiskSizeInfo()
{
    FRESULT rc;
    FATFS *fatfs;
    DWORD free_clust, free_sect, total_sect;
 
 
    // results
    DWORD total_KB, free_KB, total_MB, free_MB;
 
 
    rc = f_mount(0, fatfs);
    if (rc != FR_OK) {
        return RET_NG;
    }
 
 
    rc = f_getfree("0:", &free_clust, &fatfs); // 0th drive
    if (rc != FR_OK) {
        f_mount(0,0);
        return RET_NG;
    }
 
 
    total_sect = (fatfs->n_fatent - 2) * fatfs->csize;
    free_sect = free_clust * fatfs->csize;
 
 
    // assuming 512bytes/sector
    total_KB = total_sect / 2;
    free_KB = free_sect / 2;
    total_MB = total_KB / 1024;
    free_MB = free_KB / 1024;
 
 
    f_mount(0, 0); // unmount
    return RET_OK;
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?