Example of using the SDFileSystem library on a K64F to write data to files and also read data into dynamically created arrays.

Dependencies:   mbed

Committer:
eencae
Date:
Mon Feb 03 12:06:21 2020 +0000
Revision:
1:caceb9d9d17a
Updated Mbed library. Removed serial. Confirmed working Jan 2020.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
eencae 1:caceb9d9d17a 1 /*---------------------------------------------------------------------------/
eencae 1:caceb9d9d17a 2 / FatFs - FAT file system module configuration file R0.11a (C)ChaN, 2015
eencae 1:caceb9d9d17a 3 /---------------------------------------------------------------------------*/
eencae 1:caceb9d9d17a 4
eencae 1:caceb9d9d17a 5 #define _FFCONF 64180 /* Revision ID */
eencae 1:caceb9d9d17a 6
eencae 1:caceb9d9d17a 7 #define FFS_DBG 0
eencae 1:caceb9d9d17a 8
eencae 1:caceb9d9d17a 9 /*---------------------------------------------------------------------------/
eencae 1:caceb9d9d17a 10 / Function Configurations
eencae 1:caceb9d9d17a 11 /---------------------------------------------------------------------------*/
eencae 1:caceb9d9d17a 12
eencae 1:caceb9d9d17a 13 #define _FS_READONLY 0
eencae 1:caceb9d9d17a 14 /* This option switches read-only configuration. (0:Read/Write or 1:Read-only)
eencae 1:caceb9d9d17a 15 / Read-only configuration removes writing API functions, f_write(), f_sync(),
eencae 1:caceb9d9d17a 16 / f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(), f_getfree()
eencae 1:caceb9d9d17a 17 / and optional writing functions as well. */
eencae 1:caceb9d9d17a 18
eencae 1:caceb9d9d17a 19
eencae 1:caceb9d9d17a 20 #define _FS_MINIMIZE 0
eencae 1:caceb9d9d17a 21 /* This option defines minimization level to remove some basic API functions.
eencae 1:caceb9d9d17a 22 /
eencae 1:caceb9d9d17a 23 / 0: All basic functions are enabled.
eencae 1:caceb9d9d17a 24 / 1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_chmod(), f_utime(),
eencae 1:caceb9d9d17a 25 / f_truncate() and f_rename() function are removed.
eencae 1:caceb9d9d17a 26 / 2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1.
eencae 1:caceb9d9d17a 27 / 3: f_lseek() function is removed in addition to 2. */
eencae 1:caceb9d9d17a 28
eencae 1:caceb9d9d17a 29
eencae 1:caceb9d9d17a 30 #define _USE_STRFUNC 0
eencae 1:caceb9d9d17a 31 /* This option switches string functions, f_gets(), f_putc(), f_puts() and
eencae 1:caceb9d9d17a 32 / f_printf().
eencae 1:caceb9d9d17a 33 /
eencae 1:caceb9d9d17a 34 / 0: Disable string functions.
eencae 1:caceb9d9d17a 35 / 1: Enable without LF-CRLF conversion.
eencae 1:caceb9d9d17a 36 / 2: Enable with LF-CRLF conversion. */
eencae 1:caceb9d9d17a 37
eencae 1:caceb9d9d17a 38
eencae 1:caceb9d9d17a 39 #define _USE_FIND 0
eencae 1:caceb9d9d17a 40 /* This option switches filtered directory read feature and related functions,
eencae 1:caceb9d9d17a 41 / f_findfirst() and f_findnext(). (0:Disable or 1:Enable) */
eencae 1:caceb9d9d17a 42
eencae 1:caceb9d9d17a 43
eencae 1:caceb9d9d17a 44 #define _USE_MKFS 1
eencae 1:caceb9d9d17a 45 /* This option switches f_mkfs() function. (0:Disable or 1:Enable) */
eencae 1:caceb9d9d17a 46
eencae 1:caceb9d9d17a 47
eencae 1:caceb9d9d17a 48 #define _USE_FASTSEEK 0
eencae 1:caceb9d9d17a 49 /* This option switches fast seek feature. (0:Disable or 1:Enable) */
eencae 1:caceb9d9d17a 50
eencae 1:caceb9d9d17a 51
eencae 1:caceb9d9d17a 52 #define _USE_LABEL 0
eencae 1:caceb9d9d17a 53 /* This option switches volume label functions, f_getlabel() and f_setlabel().
eencae 1:caceb9d9d17a 54 / (0:Disable or 1:Enable) */
eencae 1:caceb9d9d17a 55
eencae 1:caceb9d9d17a 56
eencae 1:caceb9d9d17a 57 #define _USE_FORWARD 0
eencae 1:caceb9d9d17a 58 /* This option switches f_forward() function. (0:Disable or 1:Enable)
eencae 1:caceb9d9d17a 59 / To enable it, also _FS_TINY need to be set to 1. */
eencae 1:caceb9d9d17a 60
eencae 1:caceb9d9d17a 61
eencae 1:caceb9d9d17a 62 /*---------------------------------------------------------------------------/
eencae 1:caceb9d9d17a 63 / Locale and Namespace Configurations
eencae 1:caceb9d9d17a 64 /---------------------------------------------------------------------------*/
eencae 1:caceb9d9d17a 65
eencae 1:caceb9d9d17a 66 #define _CODE_PAGE 850
eencae 1:caceb9d9d17a 67 /* This option specifies the OEM code page to be used on the target system.
eencae 1:caceb9d9d17a 68 / Incorrect setting of the code page can cause a file open failure.
eencae 1:caceb9d9d17a 69 /
eencae 1:caceb9d9d17a 70 / 1 - ASCII (No extended character. Non-LFN cfg. only)
eencae 1:caceb9d9d17a 71 / 437 - U.S.
eencae 1:caceb9d9d17a 72 / 720 - Arabic
eencae 1:caceb9d9d17a 73 / 737 - Greek
eencae 1:caceb9d9d17a 74 / 771 - KBL
eencae 1:caceb9d9d17a 75 / 775 - Baltic
eencae 1:caceb9d9d17a 76 / 850 - Latin 1
eencae 1:caceb9d9d17a 77 / 852 - Latin 2
eencae 1:caceb9d9d17a 78 / 855 - Cyrillic
eencae 1:caceb9d9d17a 79 / 857 - Turkish
eencae 1:caceb9d9d17a 80 / 860 - Portuguese
eencae 1:caceb9d9d17a 81 / 861 - Icelandic
eencae 1:caceb9d9d17a 82 / 862 - Hebrew
eencae 1:caceb9d9d17a 83 / 863 - Canadian French
eencae 1:caceb9d9d17a 84 / 864 - Arabic
eencae 1:caceb9d9d17a 85 / 865 - Nordic
eencae 1:caceb9d9d17a 86 / 866 - Russian
eencae 1:caceb9d9d17a 87 / 869 - Greek 2
eencae 1:caceb9d9d17a 88 / 932 - Japanese (DBCS)
eencae 1:caceb9d9d17a 89 / 936 - Simplified Chinese (DBCS)
eencae 1:caceb9d9d17a 90 / 949 - Korean (DBCS)
eencae 1:caceb9d9d17a 91 / 950 - Traditional Chinese (DBCS)
eencae 1:caceb9d9d17a 92 */
eencae 1:caceb9d9d17a 93
eencae 1:caceb9d9d17a 94
eencae 1:caceb9d9d17a 95 #define _USE_LFN 1
eencae 1:caceb9d9d17a 96 #define _MAX_LFN 255
eencae 1:caceb9d9d17a 97 /* The _USE_LFN option switches the LFN feature.
eencae 1:caceb9d9d17a 98 /
eencae 1:caceb9d9d17a 99 / 0: Disable LFN feature. _MAX_LFN has no effect.
eencae 1:caceb9d9d17a 100 / 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe.
eencae 1:caceb9d9d17a 101 / 2: Enable LFN with dynamic working buffer on the STACK.
eencae 1:caceb9d9d17a 102 / 3: Enable LFN with dynamic working buffer on the HEAP.
eencae 1:caceb9d9d17a 103 /
eencae 1:caceb9d9d17a 104 / When enable the LFN feature, Unicode handling functions (option/unicode.c) must
eencae 1:caceb9d9d17a 105 / be added to the project. The LFN working buffer occupies (_MAX_LFN + 1) * 2 bytes.
eencae 1:caceb9d9d17a 106 / When use stack for the working buffer, take care on stack overflow. When use heap
eencae 1:caceb9d9d17a 107 / memory for the working buffer, memory management functions, ff_memalloc() and
eencae 1:caceb9d9d17a 108 / ff_memfree(), must be added to the project. */
eencae 1:caceb9d9d17a 109
eencae 1:caceb9d9d17a 110
eencae 1:caceb9d9d17a 111 #define _LFN_UNICODE 0
eencae 1:caceb9d9d17a 112 /* This option switches character encoding on the API. (0:ANSI/OEM or 1:Unicode)
eencae 1:caceb9d9d17a 113 / To use Unicode string for the path name, enable LFN feature and set _LFN_UNICODE
eencae 1:caceb9d9d17a 114 / to 1. This option also affects behavior of string I/O functions. */
eencae 1:caceb9d9d17a 115
eencae 1:caceb9d9d17a 116
eencae 1:caceb9d9d17a 117 #define _STRF_ENCODE 3
eencae 1:caceb9d9d17a 118 /* When _LFN_UNICODE is 1, this option selects the character encoding on the file to
eencae 1:caceb9d9d17a 119 / be read/written via string I/O functions, f_gets(), f_putc(), f_puts and f_printf().
eencae 1:caceb9d9d17a 120 /
eencae 1:caceb9d9d17a 121 / 0: ANSI/OEM
eencae 1:caceb9d9d17a 122 / 1: UTF-16LE
eencae 1:caceb9d9d17a 123 / 2: UTF-16BE
eencae 1:caceb9d9d17a 124 / 3: UTF-8
eencae 1:caceb9d9d17a 125 /
eencae 1:caceb9d9d17a 126 / When _LFN_UNICODE is 0, this option has no effect. */
eencae 1:caceb9d9d17a 127
eencae 1:caceb9d9d17a 128
eencae 1:caceb9d9d17a 129 #define _FS_RPATH 0
eencae 1:caceb9d9d17a 130 /* This option configures relative path feature.
eencae 1:caceb9d9d17a 131 /
eencae 1:caceb9d9d17a 132 / 0: Disable relative path feature and remove related functions.
eencae 1:caceb9d9d17a 133 / 1: Enable relative path feature. f_chdir() and f_chdrive() are available.
eencae 1:caceb9d9d17a 134 / 2: f_getcwd() function is available in addition to 1.
eencae 1:caceb9d9d17a 135 /
eencae 1:caceb9d9d17a 136 / Note that directory items read via f_readdir() are affected by this option. */
eencae 1:caceb9d9d17a 137
eencae 1:caceb9d9d17a 138
eencae 1:caceb9d9d17a 139 /*---------------------------------------------------------------------------/
eencae 1:caceb9d9d17a 140 / Drive/Volume Configurations
eencae 1:caceb9d9d17a 141 /---------------------------------------------------------------------------*/
eencae 1:caceb9d9d17a 142
eencae 1:caceb9d9d17a 143 #define _VOLUMES 1
eencae 1:caceb9d9d17a 144 /* Number of volumes (logical drives) to be used. */
eencae 1:caceb9d9d17a 145
eencae 1:caceb9d9d17a 146
eencae 1:caceb9d9d17a 147 #define _STR_VOLUME_ID 0
eencae 1:caceb9d9d17a 148 #define _VOLUME_STRS "RAM","NAND","CF","SD1","SD2","USB1","USB2","USB3"
eencae 1:caceb9d9d17a 149 /* _STR_VOLUME_ID option switches string volume ID feature.
eencae 1:caceb9d9d17a 150 / When _STR_VOLUME_ID is set to 1, also pre-defined strings can be used as drive
eencae 1:caceb9d9d17a 151 / number in the path name. _VOLUME_STRS defines the drive ID strings for each
eencae 1:caceb9d9d17a 152 / logical drives. Number of items must be equal to _VOLUMES. Valid characters for
eencae 1:caceb9d9d17a 153 / the drive ID strings are: A-Z and 0-9. */
eencae 1:caceb9d9d17a 154
eencae 1:caceb9d9d17a 155
eencae 1:caceb9d9d17a 156 #define _MULTI_PARTITION 0
eencae 1:caceb9d9d17a 157 /* This option switches multi-partition feature. By default (0), each logical drive
eencae 1:caceb9d9d17a 158 / number is bound to the same physical drive number and only an FAT volume found on
eencae 1:caceb9d9d17a 159 / the physical drive will be mounted. When multi-partition feature is enabled (1),
eencae 1:caceb9d9d17a 160 / each logical drive number is bound to arbitrary physical drive and partition
eencae 1:caceb9d9d17a 161 / listed in the VolToPart[]. Also f_fdisk() funciton will be available. */
eencae 1:caceb9d9d17a 162
eencae 1:caceb9d9d17a 163
eencae 1:caceb9d9d17a 164 #define _MIN_SS 512
eencae 1:caceb9d9d17a 165 #define _MAX_SS 512
eencae 1:caceb9d9d17a 166 /* These options configure the range of sector size to be supported. (512, 1024,
eencae 1:caceb9d9d17a 167 / 2048 or 4096) Always set both 512 for most systems, all type of memory cards and
eencae 1:caceb9d9d17a 168 / harddisk. But a larger value may be required for on-board flash memory and some
eencae 1:caceb9d9d17a 169 / type of optical media. When _MAX_SS is larger than _MIN_SS, FatFs is configured
eencae 1:caceb9d9d17a 170 / to variable sector size and GET_SECTOR_SIZE command must be implemented to the
eencae 1:caceb9d9d17a 171 / disk_ioctl() function. */
eencae 1:caceb9d9d17a 172
eencae 1:caceb9d9d17a 173
eencae 1:caceb9d9d17a 174 #define _USE_TRIM 0
eencae 1:caceb9d9d17a 175 /* This option switches ATA-TRIM feature. (0:Disable or 1:Enable)
eencae 1:caceb9d9d17a 176 / To enable Trim feature, also CTRL_TRIM command should be implemented to the
eencae 1:caceb9d9d17a 177 / disk_ioctl() function. */
eencae 1:caceb9d9d17a 178
eencae 1:caceb9d9d17a 179
eencae 1:caceb9d9d17a 180 #define _FS_NOFSINFO 0
eencae 1:caceb9d9d17a 181 /* If you need to know correct free space on the FAT32 volume, set bit 0 of this
eencae 1:caceb9d9d17a 182 / option, and f_getfree() function at first time after volume mount will force
eencae 1:caceb9d9d17a 183 / a full FAT scan. Bit 1 controls the use of last allocated cluster number.
eencae 1:caceb9d9d17a 184 /
eencae 1:caceb9d9d17a 185 / bit0=0: Use free cluster count in the FSINFO if available.
eencae 1:caceb9d9d17a 186 / bit0=1: Do not trust free cluster count in the FSINFO.
eencae 1:caceb9d9d17a 187 / bit1=0: Use last allocated cluster number in the FSINFO if available.
eencae 1:caceb9d9d17a 188 / bit1=1: Do not trust last allocated cluster number in the FSINFO.
eencae 1:caceb9d9d17a 189 */
eencae 1:caceb9d9d17a 190
eencae 1:caceb9d9d17a 191
eencae 1:caceb9d9d17a 192
eencae 1:caceb9d9d17a 193 /*---------------------------------------------------------------------------/
eencae 1:caceb9d9d17a 194 / System Configurations
eencae 1:caceb9d9d17a 195 /---------------------------------------------------------------------------*/
eencae 1:caceb9d9d17a 196
eencae 1:caceb9d9d17a 197 #define _FS_TINY 0
eencae 1:caceb9d9d17a 198 /* This option switches tiny buffer configuration. (0:Normal or 1:Tiny)
eencae 1:caceb9d9d17a 199 / At the tiny configuration, size of the file object (FIL) is reduced _MAX_SS
eencae 1:caceb9d9d17a 200 / bytes. Instead of private sector buffer eliminated from the file object,
eencae 1:caceb9d9d17a 201 / common sector buffer in the file system object (FATFS) is used for the file
eencae 1:caceb9d9d17a 202 / data transfer. */
eencae 1:caceb9d9d17a 203
eencae 1:caceb9d9d17a 204
eencae 1:caceb9d9d17a 205 #define _FS_NORTC 0
eencae 1:caceb9d9d17a 206 #define _NORTC_MON 1
eencae 1:caceb9d9d17a 207 #define _NORTC_MDAY 1
eencae 1:caceb9d9d17a 208 #define _NORTC_YEAR 2015
eencae 1:caceb9d9d17a 209 /* The _FS_NORTC option switches timestamp feature. If the system does not have
eencae 1:caceb9d9d17a 210 / an RTC function or valid timestamp is not needed, set _FS_NORTC to 1 to disable
eencae 1:caceb9d9d17a 211 / the timestamp feature. All objects modified by FatFs will have a fixed timestamp
eencae 1:caceb9d9d17a 212 / defined by _NORTC_MON, _NORTC_MDAY and _NORTC_YEAR.
eencae 1:caceb9d9d17a 213 / When timestamp feature is enabled (_FS_NORTC == 0), get_fattime() function need
eencae 1:caceb9d9d17a 214 / to be added to the project to read current time form RTC. _NORTC_MON,
eencae 1:caceb9d9d17a 215 / _NORTC_MDAY and _NORTC_YEAR have no effect.
eencae 1:caceb9d9d17a 216 / These options have no effect at read-only configuration (_FS_READONLY == 1). */
eencae 1:caceb9d9d17a 217
eencae 1:caceb9d9d17a 218
eencae 1:caceb9d9d17a 219 #define _FS_LOCK 0
eencae 1:caceb9d9d17a 220 /* The _FS_LOCK option switches file lock feature to control duplicated file open
eencae 1:caceb9d9d17a 221 / and illegal operation to open objects. This option must be 0 when _FS_READONLY
eencae 1:caceb9d9d17a 222 / is 1.
eencae 1:caceb9d9d17a 223 /
eencae 1:caceb9d9d17a 224 / 0: Disable file lock feature. To avoid volume corruption, application program
eencae 1:caceb9d9d17a 225 / should avoid illegal open, remove and rename to the open objects.
eencae 1:caceb9d9d17a 226 / >0: Enable file lock feature. The value defines how many files/sub-directories
eencae 1:caceb9d9d17a 227 / can be opened simultaneously under file lock control. Note that the file
eencae 1:caceb9d9d17a 228 / lock feature is independent of re-entrancy. */
eencae 1:caceb9d9d17a 229
eencae 1:caceb9d9d17a 230
eencae 1:caceb9d9d17a 231 #define _FS_REENTRANT 0
eencae 1:caceb9d9d17a 232 #define _FS_TIMEOUT 1000
eencae 1:caceb9d9d17a 233 #define _SYNC_t HANDLE
eencae 1:caceb9d9d17a 234 /* The _FS_REENTRANT option switches the re-entrancy (thread safe) of the FatFs
eencae 1:caceb9d9d17a 235 / module itself. Note that regardless of this option, file access to different
eencae 1:caceb9d9d17a 236 / volume is always re-entrant and volume control functions, f_mount(), f_mkfs()
eencae 1:caceb9d9d17a 237 / and f_fdisk() function, are always not re-entrant. Only file/directory access
eencae 1:caceb9d9d17a 238 / to the same volume is under control of this feature.
eencae 1:caceb9d9d17a 239 /
eencae 1:caceb9d9d17a 240 / 0: Disable re-entrancy. _FS_TIMEOUT and _SYNC_t have no effect.
eencae 1:caceb9d9d17a 241 / 1: Enable re-entrancy. Also user provided synchronization handlers,
eencae 1:caceb9d9d17a 242 / ff_req_grant(), ff_rel_grant(), ff_del_syncobj() and ff_cre_syncobj()
eencae 1:caceb9d9d17a 243 / function, must be added to the project. Samples are available in
eencae 1:caceb9d9d17a 244 / option/syscall.c.
eencae 1:caceb9d9d17a 245 /
eencae 1:caceb9d9d17a 246 / The _FS_TIMEOUT defines timeout period in unit of time tick.
eencae 1:caceb9d9d17a 247 / The _SYNC_t defines O/S dependent sync object type. e.g. HANDLE, ID, OS_EVENT*,
eencae 1:caceb9d9d17a 248 / SemaphoreHandle_t and etc.. A header file for O/S definitions needs to be
eencae 1:caceb9d9d17a 249 / included somewhere in the scope of ff.c. */
eencae 1:caceb9d9d17a 250
eencae 1:caceb9d9d17a 251
eencae 1:caceb9d9d17a 252 #define _WORD_ACCESS 0
eencae 1:caceb9d9d17a 253 /* The _WORD_ACCESS option is an only platform dependent option. It defines
eencae 1:caceb9d9d17a 254 / which access method is used to the word data on the FAT volume.
eencae 1:caceb9d9d17a 255 /
eencae 1:caceb9d9d17a 256 / 0: Byte-by-byte access. Always compatible with all platforms.
eencae 1:caceb9d9d17a 257 / 1: Word access. Do not choose this unless under both the following conditions.
eencae 1:caceb9d9d17a 258 /
eencae 1:caceb9d9d17a 259 / * Address misaligned memory access is always allowed to ALL instructions.
eencae 1:caceb9d9d17a 260 / * Byte order on the memory is little-endian.
eencae 1:caceb9d9d17a 261 /
eencae 1:caceb9d9d17a 262 / If it is the case, _WORD_ACCESS can also be set to 1 to reduce code size.
eencae 1:caceb9d9d17a 263 / Following table shows allowable settings of some type of processors.
eencae 1:caceb9d9d17a 264 /
eencae 1:caceb9d9d17a 265 / ARM7TDMI 0 *2 ColdFire 0 *1 V850E 0 *2
eencae 1:caceb9d9d17a 266 / Cortex-M3 0 *3 Z80 0/1 V850ES 0/1
eencae 1:caceb9d9d17a 267 / Cortex-M0 0 *2 x86 0/1 TLCS-870 0/1
eencae 1:caceb9d9d17a 268 / AVR 0/1 RX600(LE) 0/1 TLCS-900 0/1
eencae 1:caceb9d9d17a 269 / AVR32 0 *1 RL78 0 *2 R32C 0 *2
eencae 1:caceb9d9d17a 270 / PIC18 0/1 SH-2 0 *1 M16C 0/1
eencae 1:caceb9d9d17a 271 / PIC24 0 *2 H8S 0 *1 MSP430 0 *2
eencae 1:caceb9d9d17a 272 / PIC32 0 *1 H8/300H 0 *1 8051 0/1
eencae 1:caceb9d9d17a 273 /
eencae 1:caceb9d9d17a 274 / *1:Big-endian.
eencae 1:caceb9d9d17a 275 / *2:Unaligned memory access is not supported.
eencae 1:caceb9d9d17a 276 / *3:Some compilers generate LDM/STM for mem_cpy function.
eencae 1:caceb9d9d17a 277 */
eencae 1:caceb9d9d17a 278
eencae 1:caceb9d9d17a 279 #define FLUSH_ON_NEW_CLUSTER 0 /* Sync the file on every new cluster */
eencae 1:caceb9d9d17a 280 #define FLUSH_ON_NEW_SECTOR 1 /* Sync the file on every new sector */
eencae 1:caceb9d9d17a 281 /* Only one of these two defines needs to be set to 1. If both are set to 0
eencae 1:caceb9d9d17a 282 the file is only sync when closed.
eencae 1:caceb9d9d17a 283 Clusters are group of sectors (eg: 8 sectors). Flushing on new cluster means
eencae 1:caceb9d9d17a 284 it would be less often than flushing on new sector. Sectors are generally
eencae 1:caceb9d9d17a 285 512 Bytes long. */