diff options
| author | Damien George | 2016-02-09 14:31:26 +0000 |
|---|---|---|
| committer | Damien George | 2016-02-10 08:59:58 +0000 |
| commit | 13a4c120ce2cdeb5aa1c210d9426d31e02898486 (patch) | |
| tree | 9628c421a90678e336f315dfd3e6c1e114bf2e25 | |
| parent | c33ad60a676d46cb18883beedd6c383d6fae9dd8 (diff) | |
lib/fatfs: Add support for sector sizes larger than 512 bytes.
If MICROPY_FATFS_MAX_SS is defined to power of 2 value between 1024 and
4096, support for dynamic sector size in FatFs will be enabled. Note
that FatFs reserves static buffer of MICROPY_FATFS_MAX_SS size for each
filesystem in use, so that value should be set sparingly.
Initial patch provided by @pfalcon.
| -rw-r--r-- | lib/fatfs/ffconf.h | 4 | ||||
| -rw-r--r-- | stmhal/diskio.c | 14 |
2 files changed, 18 insertions, 0 deletions
diff --git a/lib/fatfs/ffconf.h b/lib/fatfs/ffconf.h index 27e73e2b3..7bfb03add 100644 --- a/lib/fatfs/ffconf.h +++ b/lib/fatfs/ffconf.h @@ -217,7 +217,11 @@ #define _MIN_SS 512 +#ifdef MICROPY_FATFS_MAX_SS +#define _MAX_SS (MICROPY_FATFS_MAX_SS) +#else #define _MAX_SS 512 +#endif /* These options configure the range of sector size to be supported. (512, 1024, / 2048 or 4096) Always set both 512 for most systems, all type of memory cards and / harddisk. But a larger value may be required for on-board flash memory and some diff --git a/stmhal/diskio.c b/stmhal/diskio.c index 14eb9e297..9a4efd1a4 100644 --- a/stmhal/diskio.c +++ b/stmhal/diskio.c @@ -44,6 +44,7 @@ //#define BP_IOCTL_DEINIT (2) // unused #define BP_IOCTL_SYNC (3) #define BP_IOCTL_SEC_COUNT (4) +#define BP_IOCTL_SEC_SIZE (5) /*-----------------------------------------------------------------------*/ /* Initialize a Drive */ @@ -273,6 +274,15 @@ DRESULT disk_ioctl ( return RES_OK; } + case GET_SECTOR_SIZE: { + vfs->u.ioctl[2] = MP_OBJ_NEW_SMALL_INT(BP_IOCTL_SEC_SIZE); + vfs->u.ioctl[3] = MP_OBJ_NEW_SMALL_INT(0); // unused + mp_obj_t ret = mp_call_method_n_kw(2, 0, vfs->u.ioctl); + *((WORD*)buff) = mp_obj_get_int(ret); + vfs->u.ioctl[3] = MP_OBJ_SENTINEL; // indicate new protocol + return RES_OK; + } + case GET_BLOCK_SIZE: *((DWORD*)buff) = 1; // erase block size in units of sector size return RES_OK; @@ -292,6 +302,10 @@ DRESULT disk_ioctl ( return RES_OK; } + case GET_SECTOR_SIZE: + *((WORD*)buff) = 512; // old protocol had fixed sector size + return RES_OK; + case GET_BLOCK_SIZE: *((DWORD*)buff) = 1; // erase block size in units of sector size return RES_OK; |
