├── .gitignore ├── LICENSE.md ├── README.md ├── ffsystem ├── ffsystem_baremetal.c ├── ffsystem_cmsis_os.c └── ffsystem_template.c ├── library.json ├── library.properties ├── src ├── 00history.txt ├── 00readme.txt ├── FatFs.h ├── diskio.c ├── diskio.h ├── drivers │ ├── sd_diskio.c │ └── sd_diskio.h ├── ff.c ├── ff.h ├── ff_gen_drv.c ├── ff_gen_drv.h ├── ffconf_template.h ├── ffsystem.c ├── ffunicode.c ├── integer.h └── st_readme.txt └── st_license.txt /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2015, ChaN, all right reserved. 2 | # Copyright (c) 2019 STMicroelectronics. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | 3. Neither the name of the copyright holder nor the names of its contributors 15 | may be used to endorse or promote products derived from this software without 16 | specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FatFs 2 | FatFs is a generic FAT file system module for small embedded systems. The FatFs is written in compliance with ANSI C and completely separated from the disk I/O layer. Therefore it is independent of hardware architecture. 3 | 4 | FatFs has being developped as a personal project of the author, ChaN. 5 | 6 | See [elm-chan.org/fsw/ff](http://elm-chan.org/fsw/ff/00index_e.html) 7 | 8 | Modified by ST, used source from [stm32_mw_fatfs](https://github.com/STMicroelectronics/stm32_mw_fatfs) and modified to fit Arduino libraries specifications. 9 | 10 | It is used by the [STM32SD](https://github.com/stm32duino/STM32SD) library. 11 | -------------------------------------------------------------------------------- /ffsystem/ffsystem_baremetal.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stm32duino/FatFs/0b3658677882a0245b67b0ec6b328d3dbc471c5b/ffsystem/ffsystem_baremetal.c -------------------------------------------------------------------------------- /ffsystem/ffsystem_cmsis_os.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stm32duino/FatFs/0b3658677882a0245b67b0ec6b328d3dbc471c5b/ffsystem/ffsystem_cmsis_os.c -------------------------------------------------------------------------------- /ffsystem/ffsystem_template.c: -------------------------------------------------------------------------------- 1 | /*------------------------------------------------------------------------*/ 2 | /* A Sample Code of User Provided OS Dependent Functions for FatFs */ 3 | /*------------------------------------------------------------------------*/ 4 | 5 | #include "ff.h" 6 | 7 | 8 | #if FF_USE_LFN == 3 /* Use dynamic memory allocation */ 9 | 10 | /*------------------------------------------------------------------------*/ 11 | /* Allocate/Free a Memory Block */ 12 | /*------------------------------------------------------------------------*/ 13 | 14 | 15 | void* ff_memalloc ( /* Returns pointer to the allocated memory block (null if not enough core) */ 16 | UINT msize /* Number of bytes to allocate */ 17 | ) 18 | { 19 | void* mem_ptr = NULL; /* Memory block to be allocated */ 20 | 21 | return mem_ptr; 22 | } 23 | 24 | 25 | void ff_memfree ( 26 | void* mblock /* Pointer to the memory block to free (no effect if null) */ 27 | ) 28 | { 29 | free(mblock); /* Free the memory block */ 30 | } 31 | 32 | #endif 33 | 34 | 35 | 36 | 37 | #if FF_FS_REENTRANT /* Mutal exclusion */ 38 | /*------------------------------------------------------------------------*/ 39 | /* Create a Mutex */ 40 | /*------------------------------------------------------------------------*/ 41 | /* This function is called in f_mount function to create a new mutex 42 | / or semaphore for the volume. When a 0 is returned, the f_mount function 43 | / fails with FR_INT_ERR. 44 | */ 45 | 46 | int ff_mutex_create ( /* Returns 1:Function succeeded or 0:Could not create the mutex */ 47 | int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */ 48 | ) 49 | { 50 | return 1; 51 | } 52 | 53 | 54 | /*------------------------------------------------------------------------*/ 55 | /* Delete a Mutex */ 56 | /*------------------------------------------------------------------------*/ 57 | /* This function is called in f_mount function to delete a mutex or 58 | / semaphore of the volume created with ff_mutex_create function. 59 | */ 60 | 61 | void ff_mutex_delete ( /* Returns 1:Function succeeded or 0:Could not delete due to an error */ 62 | int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */ 63 | ) 64 | { 65 | return 1; 66 | } 67 | 68 | 69 | /*------------------------------------------------------------------------*/ 70 | /* Request a Grant to Access the Volume */ 71 | /*------------------------------------------------------------------------*/ 72 | /* This function is called on enter file functions to lock the volume. 73 | / When a 0 is returned, the file function fails with FR_TIMEOUT. 74 | */ 75 | 76 | int ff_mutex_take ( /* Returns 1:Succeeded or 0:Timeout */ 77 | int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */ 78 | ) 79 | { 80 | return 1; 81 | } 82 | 83 | 84 | 85 | /*------------------------------------------------------------------------*/ 86 | /* Release a Grant to Access the Volume */ 87 | /*------------------------------------------------------------------------*/ 88 | /* This function is called on leave file functions to unlock the volume. 89 | */ 90 | 91 | void ff_mutex_give ( 92 | int vol /* Mutex ID: Volume mutex (0 to FF_VOLUMES - 1) or system mutex (FF_VOLUMES) */ 93 | ) 94 | { 95 | return 1; 96 | } 97 | 98 | #endif /* FF_FS_REENTRANT */ 99 | 100 | -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "FatFS", 3 | "keywords": "Fat, FS, Storage", 4 | "description": "FAT file system based on open-source FatFS solution", 5 | "repository": { 6 | "type": "git", 7 | "url": "https://github.com/stm32duino/FatFs.git" 8 | }, 9 | "version": "4.0.0", 10 | "authors": [ 11 | { 12 | "url": "http://elm-chan.org/fsw/ff/00index_e.html", 13 | "maintainer": false, 14 | "email": "user5@elm-chan.org", 15 | "name": "Chan" 16 | }, 17 | { 18 | "url": "https://www.st.com/", 19 | "maintainer": false, 20 | "email": null, 21 | "name": "STMicroelectronics" 22 | } 23 | ], 24 | "frameworks": "*", 25 | "platforms": "*" 26 | } 27 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=FatFs 2 | version=4.0.0 3 | author=Chan , ST 4 | maintainer=stm32duino 5 | sentence=FAT file system based on open-source FatFS solution. 6 | paragraph=FatFs is a generic FAT file system module for small embedded systems. The FatFs is written in compliance with ANSI C and completely separated from the disk I/O layer. Therefore it is independent of hardware architecture. 7 | category=Data Storage 8 | url=https://github.com/stm32duino/FatFs 9 | architectures=stm32 10 | -------------------------------------------------------------------------------- /src/00history.txt: -------------------------------------------------------------------------------- 1 | ---------------------------------------------------------------------------- 2 | Revision history of FatFs module 3 | ---------------------------------------------------------------------------- 4 | 5 | R0.00 (February 26, 2006) 6 | 7 | Prototype. 8 | 9 | 10 | 11 | R0.01 (April 29, 2006) 12 | 13 | The first release. 14 | 15 | 16 | 17 | R0.02 (June 01, 2006) 18 | 19 | Added FAT12 support. 20 | Removed unbuffered mode. 21 | Fixed a problem on small (<32M) partition. 22 | 23 | 24 | 25 | R0.02a (June 10, 2006) 26 | 27 | Added a configuration option (_FS_MINIMUM). 28 | 29 | 30 | 31 | R0.03 (September 22, 2006) 32 | 33 | Added f_rename(). 34 | Changed option _FS_MINIMUM to _FS_MINIMIZE. 35 | 36 | 37 | 38 | R0.03a (December 11, 2006) 39 | 40 | Improved cluster scan algorithm to write files fast. 41 | Fixed f_mkdir() creates incorrect directory on FAT32. 42 | 43 | 44 | 45 | R0.04 (February 04, 2007) 46 | 47 | Added f_mkfs(). 48 | Supported multiple drive system. 49 | Changed some interfaces for multiple drive system. 50 | Changed f_mountdrv() to f_mount(). 51 | 52 | 53 | 54 | R0.04a (April 01, 2007) 55 | 56 | Supported multiple partitions on a physical drive. 57 | Added a capability of extending file size to f_lseek(). 58 | Added minimization level 3. 59 | Fixed an endian sensitive code in f_mkfs(). 60 | 61 | 62 | 63 | R0.04b (May 05, 2007) 64 | 65 | Added a configuration option _USE_NTFLAG. 66 | Added FSINFO support. 67 | Fixed DBCS name can result FR_INVALID_NAME. 68 | Fixed short seek (<= csize) collapses the file object. 69 | 70 | 71 | 72 | R0.05 (August 25, 2007) 73 | 74 | Changed arguments of f_read(), f_write() and f_mkfs(). 75 | Fixed f_mkfs() on FAT32 creates incorrect FSINFO. 76 | Fixed f_mkdir() on FAT32 creates incorrect directory. 77 | 78 | 79 | 80 | R0.05a (February 03, 2008) 81 | 82 | Added f_truncate() and f_utime(). 83 | Fixed off by one error at FAT sub-type determination. 84 | Fixed btr in f_read() can be mistruncated. 85 | Fixed cached sector is not flushed when create and close without write. 86 | 87 | 88 | 89 | R0.06 (April 01, 2008) 90 | 91 | Added fputc(), fputs(), fprintf() and fgets(). 92 | Improved performance of f_lseek() on moving to the same or following cluster. 93 | 94 | 95 | 96 | R0.07 (April 01, 2009) 97 | 98 | Merged Tiny-FatFs as a configuration option. (_FS_TINY) 99 | Added long file name feature. (_USE_LFN) 100 | Added multiple code page feature. (_CODE_PAGE) 101 | Added re-entrancy for multitask operation. (_FS_REENTRANT) 102 | Added auto cluster size selection to f_mkfs(). 103 | Added rewind option to f_readdir(). 104 | Changed result code of critical errors. 105 | Renamed string functions to avoid name collision. 106 | 107 | 108 | 109 | R0.07a (April 14, 2009) 110 | 111 | Septemberarated out OS dependent code on reentrant cfg. 112 | Added multiple sector size feature. 113 | 114 | 115 | 116 | R0.07c (June 21, 2009) 117 | 118 | Fixed f_unlink() can return FR_OK on error. 119 | Fixed wrong cache control in f_lseek(). 120 | Added relative path feature. 121 | Added f_chdir() and f_chdrive(). 122 | Added proper case conversion to extended character. 123 | 124 | 125 | 126 | R0.07e (November 03, 2009) 127 | 128 | Septemberarated out configuration options from ff.h to ffconf.h. 129 | Fixed f_unlink() fails to remove a sub-directory on _FS_RPATH. 130 | Fixed name matching error on the 13 character boundary. 131 | Added a configuration option, _LFN_UNICODE. 132 | Changed f_readdir() to return the SFN with always upper case on non-LFN cfg. 133 | 134 | 135 | 136 | R0.08 (May 15, 2010) 137 | 138 | Added a memory configuration option. (_USE_LFN = 3) 139 | Added file lock feature. (_FS_SHARE) 140 | Added fast seek feature. (_USE_FASTSEEK) 141 | Changed some types on the API, XCHAR->TCHAR. 142 | Changed .fname in the FILINFO structure on Unicode cfg. 143 | String functions support UTF-8 encoding files on Unicode cfg. 144 | 145 | 146 | 147 | R0.08a (August 16, 2010) 148 | 149 | Added f_getcwd(). (_FS_RPATH = 2) 150 | Added sector erase feature. (_USE_ERASE) 151 | Moved file lock semaphore table from fs object to the bss. 152 | Fixed f_mkfs() creates wrong FAT32 volume. 153 | 154 | 155 | 156 | R0.08b (January 15, 2011) 157 | 158 | Fast seek feature is also applied to f_read() and f_write(). 159 | f_lseek() reports required table size on creating CLMP. 160 | Extended format syntax of f_printf(). 161 | Ignores duplicated directory separators in given path name. 162 | 163 | 164 | 165 | R0.09 (September 06, 2011) 166 | 167 | f_mkfs() supports multiple partition to complete the multiple partition feature. 168 | Added f_fdisk(). 169 | 170 | 171 | 172 | R0.09a (August 27, 2012) 173 | 174 | Changed f_open() and f_opendir() reject null object pointer to avoid crash. 175 | Changed option name _FS_SHARE to _FS_LOCK. 176 | Fixed assertion failure due to OS/2 EA on FAT12/16 volume. 177 | 178 | 179 | 180 | R0.09b (January 24, 2013) 181 | 182 | Added f_setlabel() and f_getlabel(). 183 | 184 | 185 | 186 | R0.10 (October 02, 2013) 187 | 188 | Added selection of character encoding on the file. (_STRF_ENCODE) 189 | Added f_closedir(). 190 | Added forced full FAT scan for f_getfree(). (_FS_NOFSINFO) 191 | Added forced mount feature with changes of f_mount(). 192 | Improved behavior of volume auto detection. 193 | Improved write throughput of f_puts() and f_printf(). 194 | Changed argument of f_chdrive(), f_mkfs(), disk_read() and disk_write(). 195 | Fixed f_write() can be truncated when the file size is close to 4GB. 196 | Fixed f_open(), f_mkdir() and f_setlabel() can return incorrect value on error. 197 | 198 | 199 | 200 | R0.10a (January 15, 2014) 201 | 202 | Added arbitrary strings as drive number in the path name. (_STR_VOLUME_ID) 203 | Added a configuration option of minimum sector size. (_MIN_SS) 204 | 2nd argument of f_rename() can have a drive number and it will be ignored. 205 | Fixed f_mount() with forced mount fails when drive number is >= 1. (appeared at R0.10) 206 | Fixed f_close() invalidates the file object without volume lock. 207 | Fixed f_closedir() returns but the volume lock is left acquired. (appeared at R0.10) 208 | Fixed creation of an entry with LFN fails on too many SFN collisions. (appeared at R0.07) 209 | 210 | 211 | 212 | R0.10b (May 19, 2014) 213 | 214 | Fixed a hard error in the disk I/O layer can collapse the directory entry. 215 | Fixed LFN entry is not deleted when delete/rename an object with lossy converted SFN. (appeared at R0.07) 216 | 217 | 218 | 219 | R0.10c (November 09, 2014) 220 | 221 | Added a configuration option for the platforms without RTC. (_FS_NORTC) 222 | Changed option name _USE_ERASE to _USE_TRIM. 223 | Fixed volume label created by Mac OS X cannot be retrieved with f_getlabel(). (appeared at R0.09b) 224 | Fixed a potential problem of FAT access that can appear on disk error. 225 | Fixed null pointer dereference on attempting to delete the root direcotry. (appeared at R0.08) 226 | 227 | 228 | 229 | R0.11 (February 09, 2015) 230 | 231 | Added f_findfirst(), f_findnext() and f_findclose(). (_USE_FIND) 232 | Fixed f_unlink() does not remove cluster chain of the file. (appeared at R0.10c) 233 | Fixed _FS_NORTC option does not work properly. (appeared at R0.10c) 234 | 235 | 236 | 237 | R0.11a (September 05, 2015) 238 | 239 | Fixed wrong media change can lead a deadlock at thread-safe configuration. 240 | Added code page 771, 860, 861, 863, 864, 865 and 869. (_CODE_PAGE) 241 | Removed some code pages actually not exist on the standard systems. (_CODE_PAGE) 242 | Fixed errors in the case conversion teble of code page 437 and 850 (ff.c). 243 | Fixed errors in the case conversion teble of Unicode (cc*.c). 244 | 245 | 246 | 247 | R0.12 (April 12, 2016) 248 | 249 | Added support for exFAT file system. (_FS_EXFAT) 250 | Added f_expand(). (_USE_EXPAND) 251 | Changed some members in FINFO structure and behavior of f_readdir(). 252 | Added an option _USE_CHMOD. 253 | Removed an option _WORD_ACCESS. 254 | Fixed errors in the case conversion table of Unicode (cc*.c). 255 | 256 | 257 | 258 | R0.12a (July 10, 2016) 259 | 260 | Added support for creating exFAT volume with some changes of f_mkfs(). 261 | Added a file open method FA_OPEN_APPEND. An f_lseek() following f_open() is no longer needed. 262 | f_forward() is available regardless of _FS_TINY. 263 | Fixed f_mkfs() creates wrong volume. (appeared at R0.12) 264 | Fixed wrong memory read in create_name(). (appeared at R0.12) 265 | Fixed compilation fails at some configurations, _USE_FASTSEEK and _USE_FORWARD. 266 | 267 | 268 | 269 | R0.12b (September 04, 2016) 270 | 271 | Made f_rename() be able to rename objects with the same name but case. 272 | Fixed an error in the case conversion teble of code page 866. (ff.c) 273 | Fixed writing data is truncated at the file offset 4GiB on the exFAT volume. (appeared at R0.12) 274 | Fixed creating a file in the root directory of exFAT volume can fail. (appeared at R0.12) 275 | Fixed f_mkfs() creating exFAT volume with too small cluster size can collapse unallocated memory. (appeared at R0.12) 276 | Fixed wrong object name can be returned when read directory at Unicode cfg. (appeared at R0.12) 277 | Fixed large file allocation/removing on the exFAT volume collapses allocation bitmap. (appeared at R0.12) 278 | Fixed some internal errors in f_expand() and f_lseek(). (appeared at R0.12) 279 | 280 | 281 | 282 | R0.12c (March 04, 2017) 283 | 284 | Improved write throughput at the fragmented file on the exFAT volume. 285 | Made memory usage for exFAT be able to be reduced as decreasing _MAX_LFN. 286 | Fixed successive f_getfree() can return wrong count on the FAT12/16 volume. (appeared at R0.12) 287 | Fixed configuration option _VOLUMES cannot be set 10. (appeared at R0.10c) 288 | 289 | 290 | 291 | R0.13 (May 21, 2017) 292 | 293 | Changed heading character of configuration keywords "_" to "FF_". 294 | Removed ASCII-only configuration, FF_CODE_PAGE = 1. Use FF_CODE_PAGE = 437 instead. 295 | Added f_setcp(), run-time code page configuration. (FF_CODE_PAGE = 0) 296 | Improved cluster allocation time on stretch a deep buried cluster chain. 297 | Improved processing time of f_mkdir() with large cluster size by using FF_USE_LFN = 3. 298 | Improved NoFatChain flag of the fragmented file to be set after it is truncated and got contiguous. 299 | Fixed archive attribute is left not set when a file on the exFAT volume is renamed. (appeared at R0.12) 300 | Fixed exFAT FAT entry can be collapsed when write or lseek operation to the existing file is done. (appeared at R0.12c) 301 | Fixed creating a file can fail when a new cluster allocation to the exFAT directory occures. (appeared at R0.12c) 302 | 303 | 304 | 305 | R0.13a (October 14, 2017) 306 | 307 | Added support for UTF-8 encoding on the API. (FF_LFN_UNICODE = 2) 308 | Added options for file name output buffer. (FF_LFN_BUF, FF_SFN_BUF). 309 | Added dynamic memory allocation option for working buffer of f_mkfs() and f_fdisk(). 310 | Fixed f_fdisk() and f_mkfs() create the partition table with wrong CHS parameters. (appeared at R0.09) 311 | Fixed f_unlink() can cause lost clusters at fragmented file on the exFAT volume. (appeared at R0.12c) 312 | Fixed f_setlabel() rejects some valid characters for exFAT volume. (appeared at R0.12) 313 | 314 | 315 | 316 | R0.13b (April 07, 2018) 317 | 318 | Added support for UTF-32 encoding on the API. (FF_LFN_UNICODE = 3) 319 | Added support for Unix style volume ID. (FF_STR_VOLUME_ID = 2) 320 | Fixed accesing any object on the exFAT root directory beyond the cluster boundary can fail. (appeared at R0.12c) 321 | Fixed f_setlabel() does not reject some invalid characters. (appeared at R0.09b) 322 | 323 | 324 | 325 | R0.13c (October 14, 2018) 326 | Supported stdint.h for C99 and later. (integer.h was included in ff.h) 327 | Fixed reading a directory gets infinite loop when the last directory entry is not empty. (appeared at R0.12) 328 | Fixed creating a sub-directory in the fragmented sub-directory on the exFAT volume collapses FAT chain of the parent directory. (appeared at R0.12) 329 | Fixed f_getcwd() cause output buffer overrun when the buffer has a valid drive number. (appeared at R0.13b) 330 | 331 | 332 | 333 | R0.14 (October 14, 2019) 334 | Added support for 64-bit LBA and GUID partition table (FF_LBA64 = 1) 335 | Changed some API functions, f_mkfs() and f_fdisk(). 336 | Fixed f_open() function cannot find the file with file name in length of FF_MAX_LFN characters. 337 | Fixed f_readdir() function cannot retrieve long file names in length of FF_MAX_LFN - 1 characters. 338 | Fixed f_readdir() function returns file names with wrong case conversion. (appeared at R0.12) 339 | Fixed f_mkfs() function can fail to create exFAT volume in the second partition. (appeared at R0.12) 340 | 341 | -------------------------------------------------------------------------------- /src/00readme.txt: -------------------------------------------------------------------------------- 1 | FatFs Module Source Files R0.14 2 | 3 | 4 | FILES 5 | 6 | 00readme.txt This file. 7 | 00history.txt Revision history. 8 | ff.c FatFs module. 9 | ffconf.h Configuration file of FatFs module. 10 | ff.h Common include file for FatFs and application module. 11 | diskio.h Common include file for FatFs and disk I/O module. 12 | diskio.c An example of glue function to attach existing disk I/O module to FatFs. 13 | ffunicode.c Optional Unicode utility functions. 14 | ffsystem.c An example of optional O/S related functions. 15 | 16 | 17 | Low level disk I/O module is not included in this archive because the FatFs 18 | module is only a generic file system layer and it does not depend on any specific 19 | storage device. You need to provide a low level disk I/O module written to 20 | control the storage device that attached to the target system. 21 | 22 | -------------------------------------------------------------------------------- /src/FatFs.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file FatFs.h 4 | * @author Frederic Pillon for STMicroelectronics 5 | * @version V1.0.0 6 | * @date 30-Aug-2017 7 | * @brief Include FatFs source files 8 | ****************************************************************************** 9 | * @attention 10 | * 11 | *

© COPYRIGHT(c) 2017 STMicroelectronics

12 | * 13 | * Redistribution and use in source and binary forms, with or without modification, 14 | * are permitted provided that the following conditions are met: 15 | * 1. Redistributions of source code must retain the above copyright notice, 16 | * this list of conditions and the following disclaimer. 17 | * 2. Redistributions in binary form must reproduce the above copyright notice, 18 | * this list of conditions and the following disclaimer in the documentation 19 | * and/or other materials provided with the distribution. 20 | * 3. Neither the name of STMicroelectronics nor the names of its contributors 21 | * may be used to endorse or promote products derived from this software 22 | * without specific prior written permission. 23 | * 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 25 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 30 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 32 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 33 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | * 35 | ****************************************************************************** 36 | */ 37 | /* Define to prevent recursive inclusion -------------------------------------*/ 38 | #ifndef __FATFS_H__ 39 | #define __FATFS_H__ 40 | 41 | /* This file is the enter point of the library for Arduino */ 42 | #include "ff_gen_drv.h" 43 | #include "drivers/sd_diskio.h" 44 | 45 | #endif /* __FATFS_H__ */ 46 | -------------------------------------------------------------------------------- /src/diskio.c: -------------------------------------------------------------------------------- 1 | /*-----------------------------------------------------------------------*/ 2 | /* Low level disk I/O module skeleton for FatFs (C)ChaN, 2023 */ 3 | /* */ 4 | /* Portions COPYRIGHT 2017-2023 STMicroelectronics */ 5 | /* Portions Copyright (C) 2013, ChaN, all right reserved */ 6 | /*-----------------------------------------------------------------------*/ 7 | /* If a working storage control module is available, it should be */ 8 | /* attached to the FatFs via a glue function rather than modifying it. */ 9 | /* This is an example of glue functions to attach various existing */ 10 | /* storage control modules to the FatFs module with a defined API. */ 11 | /*-----------------------------------------------------------------------*/ 12 | 13 | /* Includes ------------------------------------------------------------------*/ 14 | #include "diskio.h" 15 | #include "ff_gen_drv.h" 16 | 17 | #if defined ( __GNUC__ ) 18 | #ifndef __weak 19 | #define __weak __attribute__((weak)) 20 | #endif 21 | #endif 22 | 23 | /* Private typedef -----------------------------------------------------------*/ 24 | /* Private define ------------------------------------------------------------*/ 25 | /* Private variables ---------------------------------------------------------*/ 26 | extern Disk_drvTypeDef disk; 27 | 28 | /* Private function prototypes -----------------------------------------------*/ 29 | /* Private functions ---------------------------------------------------------*/ 30 | 31 | /** 32 | * @brief Gets Disk Status 33 | * @param pdrv: Physical drive number (0..) 34 | * @retval DSTATUS: Operation status 35 | */ 36 | DSTATUS disk_status ( 37 | BYTE pdrv /* Physical drive number to identify the drive */ 38 | ) 39 | { 40 | DSTATUS stat; 41 | 42 | stat = disk.drv[pdrv]->disk_status(disk.lun[pdrv]); 43 | return stat; 44 | } 45 | 46 | /** 47 | * @brief Initializes a Drive 48 | * @param pdrv: Physical drive number (0..) 49 | * @retval DSTATUS: Operation status 50 | */ 51 | DSTATUS disk_initialize ( 52 | BYTE pdrv /* Physical drive nmuber to identify the drive */ 53 | ) 54 | { 55 | DSTATUS stat = RES_OK; 56 | 57 | if(disk.is_initialized[pdrv] == 0) 58 | { 59 | stat = disk.drv[pdrv]->disk_initialize(disk.lun[pdrv]); 60 | if(stat == RES_OK) 61 | { 62 | disk.is_initialized[pdrv] = 1; 63 | } 64 | } 65 | return stat; 66 | } 67 | 68 | /** 69 | * @brief Reads Sector(s) 70 | * @param pdrv: Physical drive number (0..) 71 | * @param *buff: Data buffer to store read data 72 | * @param sector: Sector address (LBA) 73 | * @param count: Number of sectors to read (1..128) 74 | * @retval DRESULT: Operation result 75 | */ 76 | DRESULT disk_read ( 77 | BYTE pdrv, /* Physical drive nmuber to identify the drive */ 78 | BYTE *buff, /* Data buffer to store read data */ 79 | LBA_t sector, /* Sector address in LBA */ 80 | UINT count /* Number of sectors to read */ 81 | ) 82 | 83 | { 84 | DRESULT res; 85 | 86 | res = disk.drv[pdrv]->disk_read(disk.lun[pdrv], buff, sector, count); 87 | return res; 88 | } 89 | 90 | /** 91 | * @brief Writes Sector(s) 92 | * @param pdrv: Physical drive number (0..) 93 | * @param *buff: Data to be written 94 | * @param sector: Sector address (LBA) 95 | * @param count: Number of sectors to write (1..128) 96 | * @retval DRESULT: Operation result 97 | */ 98 | 99 | DRESULT disk_write ( 100 | BYTE pdrv, /* Physical drive nmuber to identify the drive */ 101 | const BYTE *buff, /* Data to be written */ 102 | LBA_t sector, /* Sector address in LBA */ 103 | UINT count /* Number of sectors to write */ 104 | ) 105 | { 106 | DRESULT res; 107 | 108 | res = disk.drv[pdrv]->disk_write(disk.lun[pdrv], buff, sector, count); 109 | return res; 110 | } 111 | 112 | 113 | /** 114 | * @brief I/O control operation 115 | * @param pdrv: Physical drive number (0..) 116 | * @param cmd: Control code 117 | * @param *buff: Buffer to send/receive control data 118 | * @retval DRESULT: Operation result 119 | */ 120 | 121 | DRESULT disk_ioctl ( 122 | BYTE pdrv, /* Physical drive nmuber (0..) */ 123 | BYTE cmd, /* Control code */ 124 | void *buff /* Buffer to send/receive control data */ 125 | ) 126 | { 127 | DRESULT res; 128 | 129 | res = disk.drv[pdrv]->disk_ioctl(disk.lun[pdrv], cmd, buff); 130 | return res; 131 | } 132 | 133 | 134 | /** 135 | * @brief Gets Time from RTC 136 | * @param None 137 | * @retval Time in DWORD 138 | */ 139 | __weak DWORD get_fattime (void) 140 | { 141 | return 0; 142 | } 143 | 144 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 145 | 146 | -------------------------------------------------------------------------------- /src/diskio.h: -------------------------------------------------------------------------------- 1 | /*-----------------------------------------------------------------------/ 2 | / Low level disk interface modlue include file (C)ChaN, 2019 / 3 | /-----------------------------------------------------------------------*/ 4 | 5 | #ifndef _DISKIO_DEFINED 6 | #define _DISKIO_DEFINED 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | #include "ff.h" 13 | 14 | /* Status of Disk Functions */ 15 | typedef BYTE DSTATUS; 16 | 17 | /* Results of Disk Functions */ 18 | typedef enum { 19 | RES_OK = 0, /* 0: Successful */ 20 | RES_ERROR, /* 1: R/W Error */ 21 | RES_WRPRT, /* 2: Write Protected */ 22 | RES_NOTRDY, /* 3: Not Ready */ 23 | RES_PARERR /* 4: Invalid Parameter */ 24 | } DRESULT; 25 | 26 | 27 | /*---------------------------------------*/ 28 | /* Prototypes for disk control functions */ 29 | 30 | 31 | DSTATUS disk_initialize (BYTE pdrv); 32 | DSTATUS disk_status (BYTE pdrv); 33 | DRESULT disk_read (BYTE pdrv, BYTE* buff, LBA_t sector, UINT count); 34 | DRESULT disk_write (BYTE pdrv, const BYTE* buff, LBA_t sector, UINT count); 35 | DRESULT disk_ioctl (BYTE pdrv, BYTE cmd, void* buff); 36 | 37 | 38 | /* Disk Status Bits (DSTATUS) */ 39 | 40 | #define STA_NOINIT 0x01 /* Drive not initialized */ 41 | #define STA_NODISK 0x02 /* No medium in the drive */ 42 | #define STA_PROTECT 0x04 /* Write protected */ 43 | 44 | 45 | /* Command code for disk_ioctrl fucntion */ 46 | 47 | /* Generic command (Used by FatFs) */ 48 | #define CTRL_SYNC 0 /* Complete pending write process (needed at FF_FS_READONLY == 0) */ 49 | #define GET_SECTOR_COUNT 1 /* Get media size (needed at FF_USE_MKFS == 1) */ 50 | #define GET_SECTOR_SIZE 2 /* Get sector size (needed at FF_MAX_SS != FF_MIN_SS) */ 51 | #define GET_BLOCK_SIZE 3 /* Get erase block size (needed at FF_USE_MKFS == 1) */ 52 | #define CTRL_TRIM 4 /* Inform device that the data on the block of sectors is no longer used (needed at FF_USE_TRIM == 1) */ 53 | 54 | /* Generic command (Not used by FatFs) */ 55 | #define CTRL_POWER 5 /* Get/Set power status */ 56 | #define CTRL_LOCK 6 /* Lock/Unlock media removal */ 57 | #define CTRL_EJECT 7 /* Eject media */ 58 | #define CTRL_FORMAT 8 /* Create physical format on the media */ 59 | 60 | /* MMC/SDC specific ioctl command */ 61 | #define MMC_GET_TYPE 10 /* Get card type */ 62 | #define MMC_GET_CSD 11 /* Get CSD */ 63 | #define MMC_GET_CID 12 /* Get CID */ 64 | #define MMC_GET_OCR 13 /* Get OCR */ 65 | #define MMC_GET_SDSTAT 14 /* Get SD status */ 66 | #define ISDIO_READ 55 /* Read data form SD iSDIO register */ 67 | #define ISDIO_WRITE 56 /* Write data to SD iSDIO register */ 68 | #define ISDIO_MRITE 57 /* Masked write data to SD iSDIO register */ 69 | 70 | /* ATA/CF specific ioctl command */ 71 | #define ATA_GET_REV 20 /* Get F/W revision */ 72 | #define ATA_GET_MODEL 21 /* Get model name */ 73 | #define ATA_GET_SN 22 /* Get serial number */ 74 | 75 | #ifdef __cplusplus 76 | } 77 | #endif 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /src/drivers/sd_diskio.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file sd_diskio.c 4 | * @author MCD Application Team 5 | * @brief SD Disk I/O driver based on BSP v1 api. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2017-2019 STMicroelectronics. All rights reserved. 10 | * 11 | * This software component is licensed by ST under BSD 3-Clause license, 12 | * the "License"; You may not use this file except in compliance with the 13 | * License. You may obtain a copy of the License at: 14 | * opensource.org/licenses/BSD-3-Clause 15 | * 16 | ****************************************************************************** 17 | **/ 18 | /* Includes ------------------------------------------------------------------*/ 19 | #include "ff_gen_drv.h" 20 | #include "sd_diskio.h" 21 | 22 | 23 | /* Private typedef -----------------------------------------------------------*/ 24 | /* Private define ------------------------------------------------------------*/ 25 | /* use the default SD timout as defined in the platform BSP driver*/ 26 | #if defined(SDMMC_DATATIMEOUT) 27 | #define SD_TIMEOUT SDMMC_DATATIMEOUT 28 | #elif defined(SD_DATATIMEOUT) 29 | #define SD_TIMEOUT SD_DATATIMEOUT 30 | #else 31 | #define SD_TIMEOUT 30 * 1000 32 | #endif 33 | 34 | #define SD_DEFAULT_BLOCK_SIZE 512 35 | 36 | /* 37 | * Depending on the usecase, the SD card initialization could be done at the 38 | * application level, if it is the case define the flag below to disable 39 | * the BSP_SD_Init() call in the SD_Initialize(). 40 | */ 41 | 42 | /* #define DISABLE_SD_INIT */ 43 | 44 | /* Private variables ---------------------------------------------------------*/ 45 | /* Disk status */ 46 | static volatile DSTATUS Stat = STA_NOINIT; 47 | 48 | /* Private function prototypes -----------------------------------------------*/ 49 | static DSTATUS SD_CheckStatus(BYTE lun); 50 | DSTATUS SD_initialize (BYTE); 51 | DSTATUS SD_status (BYTE); 52 | DRESULT SD_read (BYTE, BYTE*, DWORD, UINT); 53 | #if _USE_WRITE == 1 54 | DRESULT SD_write (BYTE, const BYTE*, DWORD, UINT); 55 | #endif /* _USE_WRITE == 1 */ 56 | #if _USE_IOCTL == 1 57 | DRESULT SD_ioctl (BYTE, BYTE, void*); 58 | #endif /* _USE_IOCTL == 1 */ 59 | 60 | const Diskio_drvTypeDef SD_Driver = 61 | { 62 | SD_initialize, 63 | SD_status, 64 | SD_read, 65 | #if _USE_WRITE == 1 66 | SD_write, 67 | #endif /* _USE_WRITE == 1 */ 68 | 69 | #if _USE_IOCTL == 1 70 | SD_ioctl, 71 | #endif /* _USE_IOCTL == 1 */ 72 | }; 73 | 74 | /* Private functions ---------------------------------------------------------*/ 75 | static DSTATUS SD_CheckStatus(BYTE lun) 76 | { 77 | (void)lun; 78 | Stat = STA_NOINIT; 79 | 80 | if(BSP_SD_GetCardState() == MSD_OK) 81 | { 82 | Stat &= ~STA_NOINIT; 83 | } 84 | 85 | return Stat; 86 | } 87 | 88 | /** 89 | * @brief Initializes a Drive 90 | * @param lun : not used 91 | * @retval DSTATUS: Operation status 92 | */ 93 | DSTATUS SD_initialize(BYTE lun) 94 | { 95 | Stat = STA_NOINIT; 96 | #if !defined(DISABLE_SD_INIT) 97 | 98 | if(BSP_SD_Init() == MSD_OK) 99 | { 100 | Stat = SD_CheckStatus(lun); 101 | } 102 | 103 | #else 104 | Stat = SD_CheckStatus(lun); 105 | #endif 106 | return Stat; 107 | } 108 | 109 | /** 110 | * @brief Gets Disk Status 111 | * @param lun : not used 112 | * @retval DSTATUS: Operation status 113 | */ 114 | DSTATUS SD_status(BYTE lun) 115 | { 116 | return SD_CheckStatus(lun); 117 | } 118 | 119 | /** 120 | * @brief Reads Sector(s) 121 | * @param lun : not used 122 | * @param *buff: Data buffer to store read data 123 | * @param sector: Sector address (LBA) 124 | * @param count: Number of sectors to read (1..128) 125 | * @retval DRESULT: Operation result 126 | */ 127 | DRESULT SD_read(BYTE lun, BYTE *buff, DWORD sector, UINT count) 128 | { 129 | (void)lun; 130 | DRESULT res = RES_ERROR; 131 | 132 | if(BSP_SD_ReadBlocks((uint32_t*)buff, 133 | (uint32_t) (sector), 134 | count, SD_TIMEOUT) == MSD_OK) 135 | { 136 | /* wait until the read operation is finished */ 137 | while(BSP_SD_GetCardState()!= MSD_OK) 138 | { 139 | } 140 | res = RES_OK; 141 | } 142 | 143 | return res; 144 | } 145 | 146 | /** 147 | * @brief Writes Sector(s) 148 | * @param lun : not used 149 | * @param *buff: Data to be written 150 | * @param sector: Sector address (LBA) 151 | * @param count: Number of sectors to write (1..128) 152 | * @retval DRESULT: Operation result 153 | */ 154 | #if _USE_WRITE == 1 155 | DRESULT SD_write(BYTE lun, const BYTE *buff, DWORD sector, UINT count) 156 | { 157 | (void)lun; 158 | DRESULT res = RES_ERROR; 159 | 160 | if(BSP_SD_WriteBlocks((uint32_t*)buff, 161 | (uint32_t)(sector), 162 | count, SD_TIMEOUT) == MSD_OK) 163 | { 164 | /* wait until the Write operation is finished */ 165 | while(BSP_SD_GetCardState() != MSD_OK) 166 | { 167 | } 168 | res = RES_OK; 169 | } 170 | 171 | return res; 172 | } 173 | #endif /* _USE_WRITE == 1 */ 174 | 175 | /** 176 | * @brief I/O control operation 177 | * @param lun : not used 178 | * @param cmd: Control code 179 | * @param *buff: Buffer to send/receive control data 180 | * @retval DRESULT: Operation result 181 | */ 182 | #if _USE_IOCTL == 1 183 | DRESULT SD_ioctl(BYTE lun, BYTE cmd, void *buff) 184 | { 185 | (void)lun; 186 | DRESULT res = RES_ERROR; 187 | BSP_SD_CardInfo CardInfo; 188 | 189 | if (Stat & STA_NOINIT) return RES_NOTRDY; 190 | 191 | switch (cmd) 192 | { 193 | /* Make sure that no pending write process */ 194 | case CTRL_SYNC : 195 | res = RES_OK; 196 | break; 197 | 198 | /* Get number of sectors on the disk (DWORD) */ 199 | case GET_SECTOR_COUNT : 200 | BSP_SD_GetCardInfo(&CardInfo); 201 | *(DWORD*)buff = CardInfo.LogBlockNbr; 202 | res = RES_OK; 203 | break; 204 | 205 | /* Get R/W sector size (WORD) */ 206 | case GET_SECTOR_SIZE : 207 | BSP_SD_GetCardInfo(&CardInfo); 208 | *(WORD*)buff = CardInfo.LogBlockSize; 209 | res = RES_OK; 210 | break; 211 | 212 | /* Get erase block size in unit of sector (DWORD) */ 213 | case GET_BLOCK_SIZE : 214 | BSP_SD_GetCardInfo(&CardInfo); 215 | *(DWORD*)buff = CardInfo.LogBlockSize / SD_DEFAULT_BLOCK_SIZE; 216 | res = RES_OK; 217 | break; 218 | 219 | default: 220 | res = RES_PARERR; 221 | } 222 | 223 | return res; 224 | } 225 | #endif /* _USE_IOCTL == 1 */ 226 | 227 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 228 | 229 | -------------------------------------------------------------------------------- /src/drivers/sd_diskio.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file sd_diskio.h 4 | * @author MCD Application Team 5 | * @brief Header for sd_diskio.c module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2017 STMicroelectronics. All rights reserved. 10 | * 11 | * This software component is licensed by ST under BSD 3-Clause license, 12 | * the "License"; You may not use this file except in compliance with the 13 | * License. You may obtain a copy of the License at: 14 | * opensource.org/licenses/BSD-3-Clause 15 | * 16 | ****************************************************************************** 17 | **/ 18 | /* Define to prevent recursive inclusion -------------------------------------*/ 19 | #ifndef __SD_DISKIO_H 20 | #define __SD_DISKIO_H 21 | 22 | /* Includes ------------------------------------------------------------------*/ 23 | /* Exported types ------------------------------------------------------------*/ 24 | /* Exported constants --------------------------------------------------------*/ 25 | /* Exported functions ------------------------------------------------------- */ 26 | extern const Diskio_drvTypeDef SD_Driver; 27 | 28 | #endif /* __SD_DISKIO_H */ 29 | 30 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 31 | 32 | -------------------------------------------------------------------------------- /src/ff.h: -------------------------------------------------------------------------------- 1 | /*----------------------------------------------------------------------------/ 2 | / FatFs - Generic FAT Filesystem module R0.15 / 3 | /-----------------------------------------------------------------------------/ 4 | / 5 | / Copyright (C) 2022, ChaN, all right reserved. 6 | / 7 | / FatFs module is an open source software. Redistribution and use of FatFs in 8 | / source and binary forms, with or without modification, are permitted provided 9 | / that the following condition is met: 10 | 11 | / 1. Redistributions of source code must retain the above copyright notice, 12 | / this condition and the following disclaimer. 13 | / 14 | / This software is provided by the copyright holder and contributors "AS IS" 15 | / and any warranties related to this software are DISCLAIMED. 16 | / The copyright owner or contributors be NOT LIABLE for any damages caused 17 | / by use of this software. 18 | / 19 | /----------------------------------------------------------------------------*/ 20 | 21 | 22 | #ifndef FF_DEFINED 23 | #define FF_DEFINED 80286 /* Revision ID */ 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | #include "ffconf.h" /* FatFs configuration options */ 30 | 31 | #if FF_DEFINED != FFCONF_DEF 32 | #error Wrong configuration file (ffconf.h). 33 | #endif 34 | 35 | 36 | /* Integer types used for FatFs API */ 37 | 38 | #if defined(_WIN32) /* Windows VC++ (for development only) */ 39 | #define FF_INTDEF 2 40 | #include 41 | typedef unsigned __int64 QWORD; 42 | #include 43 | #define isnan(v) _isnan(v) 44 | #define isinf(v) (!_finite(v)) 45 | 46 | #elif (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || defined(__cplusplus) /* C99 or later */ 47 | #define FF_INTDEF 2 48 | #include 49 | typedef unsigned int UINT; /* int must be 16-bit or 32-bit */ 50 | typedef unsigned char BYTE; /* char must be 8-bit */ 51 | typedef uint16_t WORD; /* 16-bit unsigned integer */ 52 | typedef uint32_t DWORD; /* 32-bit unsigned integer */ 53 | typedef uint64_t QWORD; /* 64-bit unsigned integer */ 54 | typedef WORD WCHAR; /* UTF-16 character type */ 55 | 56 | #else /* Earlier than C99 */ 57 | #define FF_INTDEF 1 58 | typedef unsigned int UINT; /* int must be 16-bit or 32-bit */ 59 | typedef unsigned char BYTE; /* char must be 8-bit */ 60 | typedef unsigned short WORD; /* 16-bit unsigned integer */ 61 | typedef unsigned long DWORD; /* 32-bit unsigned integer */ 62 | typedef WORD WCHAR; /* UTF-16 character type */ 63 | #endif 64 | 65 | 66 | /* Type of file size and LBA variables */ 67 | 68 | #if FF_FS_EXFAT 69 | #if FF_INTDEF != 2 70 | #error exFAT feature wants C99 or later 71 | #endif 72 | typedef QWORD FSIZE_t; 73 | #if FF_LBA64 74 | typedef QWORD LBA_t; 75 | #else 76 | typedef DWORD LBA_t; 77 | #endif 78 | #else 79 | #if FF_LBA64 80 | #error exFAT needs to be enabled when enable 64-bit LBA 81 | #endif 82 | typedef DWORD FSIZE_t; 83 | typedef DWORD LBA_t; 84 | #endif 85 | 86 | 87 | 88 | /* Type of path name strings on FatFs API (TCHAR) */ 89 | 90 | #if FF_USE_LFN && FF_LFN_UNICODE == 1 /* Unicode in UTF-16 encoding */ 91 | typedef WCHAR TCHAR; 92 | #define _T(x) L ## x 93 | #define _TEXT(x) L ## x 94 | #elif FF_USE_LFN && FF_LFN_UNICODE == 2 /* Unicode in UTF-8 encoding */ 95 | typedef char TCHAR; 96 | #define _T(x) u8 ## x 97 | #define _TEXT(x) u8 ## x 98 | #elif FF_USE_LFN && FF_LFN_UNICODE == 3 /* Unicode in UTF-32 encoding */ 99 | typedef DWORD TCHAR; 100 | #define _T(x) U ## x 101 | #define _TEXT(x) U ## x 102 | #elif FF_USE_LFN && (FF_LFN_UNICODE < 0 || FF_LFN_UNICODE > 3) 103 | #error Wrong FF_LFN_UNICODE setting 104 | #else /* ANSI/OEM code in SBCS/DBCS */ 105 | typedef char TCHAR; 106 | #define _T(x) x 107 | #define _TEXT(x) x 108 | #endif 109 | 110 | 111 | 112 | /* Definitions of volume management */ 113 | 114 | #if FF_MULTI_PARTITION /* Multiple partition configuration */ 115 | typedef struct { 116 | BYTE pd; /* Physical drive number */ 117 | BYTE pt; /* Partition: 0:Auto detect, 1-4:Forced partition) */ 118 | } PARTITION; 119 | extern PARTITION VolToPart[]; /* Volume - Partition mapping table */ 120 | #endif 121 | 122 | #if FF_STR_VOLUME_ID 123 | #ifndef FF_VOLUME_STRS 124 | extern const char* VolumeStr[FF_VOLUMES]; /* User defied volume ID */ 125 | #endif 126 | #endif 127 | 128 | 129 | 130 | /* Filesystem object structure (FATFS) */ 131 | 132 | typedef struct { 133 | BYTE fs_type; /* Filesystem type (0:not mounted) */ 134 | BYTE pdrv; /* Volume hosting physical drive */ 135 | BYTE ldrv; /* Logical drive number (used only when FF_FS_REENTRANT) */ 136 | BYTE n_fats; /* Number of FATs (1 or 2) */ 137 | BYTE wflag; /* win[] status (b0:dirty) */ 138 | BYTE fsi_flag; /* FSINFO status (b7:disabled, b0:dirty) */ 139 | WORD id; /* Volume mount ID */ 140 | WORD n_rootdir; /* Number of root directory entries (FAT12/16) */ 141 | WORD csize; /* Cluster size [sectors] */ 142 | #if FF_MAX_SS != FF_MIN_SS 143 | WORD ssize; /* Sector size (512, 1024, 2048 or 4096) */ 144 | #endif 145 | #if FF_USE_LFN 146 | WCHAR* lfnbuf; /* LFN working buffer */ 147 | #endif 148 | #if FF_FS_EXFAT 149 | BYTE* dirbuf; /* Directory entry block scratchpad buffer for exFAT */ 150 | #endif 151 | #if !FF_FS_READONLY 152 | DWORD last_clst; /* Last allocated cluster */ 153 | DWORD free_clst; /* Number of free clusters */ 154 | #endif 155 | #if FF_FS_RPATH 156 | DWORD cdir; /* Current directory start cluster (0:root) */ 157 | #if FF_FS_EXFAT 158 | DWORD cdc_scl; /* Containing directory start cluster (invalid when cdir is 0) */ 159 | DWORD cdc_size; /* b31-b8:Size of containing directory, b7-b0: Chain status */ 160 | DWORD cdc_ofs; /* Offset in the containing directory (invalid when cdir is 0) */ 161 | #endif 162 | #endif 163 | DWORD n_fatent; /* Number of FAT entries (number of clusters + 2) */ 164 | DWORD fsize; /* Number of sectors per FAT */ 165 | LBA_t volbase; /* Volume base sector */ 166 | LBA_t fatbase; /* FAT base sector */ 167 | LBA_t dirbase; /* Root directory base sector (FAT12/16) or cluster (FAT32/exFAT) */ 168 | LBA_t database; /* Data base sector */ 169 | #if FF_FS_EXFAT 170 | LBA_t bitbase; /* Allocation bitmap base sector */ 171 | #endif 172 | LBA_t winsect; /* Current sector appearing in the win[] */ 173 | BYTE win[FF_MAX_SS]; /* Disk access window for Directory, FAT (and file data at tiny cfg) */ 174 | } FATFS; 175 | 176 | 177 | 178 | /* Object ID and allocation information (FFOBJID) */ 179 | 180 | typedef struct { 181 | FATFS* fs; /* Pointer to the hosting volume of this object */ 182 | WORD id; /* Hosting volume's mount ID */ 183 | BYTE attr; /* Object attribute */ 184 | BYTE stat; /* Object chain status (b1-0: =0:not contiguous, =2:contiguous, =3:fragmented in this session, b2:sub-directory stretched) */ 185 | DWORD sclust; /* Object data start cluster (0:no cluster or root directory) */ 186 | FSIZE_t objsize; /* Object size (valid when sclust != 0) */ 187 | #if FF_FS_EXFAT 188 | DWORD n_cont; /* Size of first fragment - 1 (valid when stat == 3) */ 189 | DWORD n_frag; /* Size of last fragment needs to be written to FAT (valid when not zero) */ 190 | DWORD c_scl; /* Containing directory start cluster (valid when sclust != 0) */ 191 | DWORD c_size; /* b31-b8:Size of containing directory, b7-b0: Chain status (valid when c_scl != 0) */ 192 | DWORD c_ofs; /* Offset in the containing directory (valid when file object and sclust != 0) */ 193 | #endif 194 | #if FF_FS_LOCK 195 | UINT lockid; /* File lock ID origin from 1 (index of file semaphore table Files[]) */ 196 | #endif 197 | } FFOBJID; 198 | 199 | 200 | 201 | /* File object structure (FIL) */ 202 | 203 | typedef struct { 204 | FFOBJID obj; /* Object identifier (must be the 1st member to detect invalid object pointer) */ 205 | BYTE flag; /* File status flags */ 206 | BYTE err; /* Abort flag (error code) */ 207 | FSIZE_t fptr; /* File read/write pointer (Zeroed on file open) */ 208 | DWORD clust; /* Current cluster of fpter (invalid when fptr is 0) */ 209 | LBA_t sect; /* Sector number appearing in buf[] (0:invalid) */ 210 | #if !FF_FS_READONLY 211 | LBA_t dir_sect; /* Sector number containing the directory entry (not used at exFAT) */ 212 | BYTE* dir_ptr; /* Pointer to the directory entry in the win[] (not used at exFAT) */ 213 | #endif 214 | #if FF_USE_FASTSEEK 215 | DWORD* cltbl; /* Pointer to the cluster link map table (nulled on open, set by application) */ 216 | #endif 217 | #if !FF_FS_TINY 218 | BYTE buf[FF_MAX_SS]; /* File private data read/write window */ 219 | #endif 220 | } FIL; 221 | 222 | 223 | 224 | /* Directory object structure (DIR) */ 225 | 226 | typedef struct { 227 | FFOBJID obj; /* Object identifier */ 228 | DWORD dptr; /* Current read/write offset */ 229 | DWORD clust; /* Current cluster */ 230 | LBA_t sect; /* Current sector (0:Read operation has terminated) */ 231 | BYTE* dir; /* Pointer to the directory item in the win[] */ 232 | BYTE fn[12]; /* SFN (in/out) {body[8],ext[3],status[1]} */ 233 | #if FF_USE_LFN 234 | DWORD blk_ofs; /* Offset of current entry block being processed (0xFFFFFFFF:Invalid) */ 235 | #endif 236 | #if FF_USE_FIND 237 | const TCHAR* pat; /* Pointer to the name matching pattern */ 238 | #endif 239 | } DIR; 240 | 241 | 242 | 243 | /* File information structure (FILINFO) */ 244 | 245 | typedef struct { 246 | FSIZE_t fsize; /* File size */ 247 | WORD fdate; /* Modified date */ 248 | WORD ftime; /* Modified time */ 249 | BYTE fattrib; /* File attribute */ 250 | #if FF_USE_LFN 251 | TCHAR altname[FF_SFN_BUF + 1];/* Alternative file name */ 252 | TCHAR fname[FF_LFN_BUF + 1]; /* Primary file name */ 253 | #else 254 | TCHAR fname[12 + 1]; /* File name */ 255 | #endif 256 | } FILINFO; 257 | 258 | 259 | 260 | /* Format parameter structure (MKFS_PARM) */ 261 | 262 | typedef struct { 263 | BYTE fmt; /* Format option (FM_FAT, FM_FAT32, FM_EXFAT and FM_SFD) */ 264 | BYTE n_fat; /* Number of FATs */ 265 | UINT align; /* Data area alignment (sector) */ 266 | UINT n_root; /* Number of root directory entries */ 267 | DWORD au_size; /* Cluster size (byte) */ 268 | } MKFS_PARM; 269 | 270 | 271 | 272 | /* File function return code (FRESULT) */ 273 | 274 | typedef enum { 275 | FR_OK = 0, /* (0) Succeeded */ 276 | FR_DISK_ERR, /* (1) A hard error occurred in the low level disk I/O layer */ 277 | FR_INT_ERR, /* (2) Assertion failed */ 278 | FR_NOT_READY, /* (3) The physical drive cannot work */ 279 | FR_NO_FILE, /* (4) Could not find the file */ 280 | FR_NO_PATH, /* (5) Could not find the path */ 281 | FR_INVALID_NAME, /* (6) The path name format is invalid */ 282 | FR_DENIED, /* (7) Access denied due to prohibited access or directory full */ 283 | FR_EXIST, /* (8) Access denied due to prohibited access */ 284 | FR_INVALID_OBJECT, /* (9) The file/directory object is invalid */ 285 | FR_WRITE_PROTECTED, /* (10) The physical drive is write protected */ 286 | FR_INVALID_DRIVE, /* (11) The logical drive number is invalid */ 287 | FR_NOT_ENABLED, /* (12) The volume has no work area */ 288 | FR_NO_FILESYSTEM, /* (13) There is no valid FAT volume */ 289 | FR_MKFS_ABORTED, /* (14) The f_mkfs() aborted due to any problem */ 290 | FR_TIMEOUT, /* (15) Could not get a grant to access the volume within defined period */ 291 | FR_LOCKED, /* (16) The operation is rejected according to the file sharing policy */ 292 | FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated */ 293 | FR_TOO_MANY_OPEN_FILES, /* (18) Number of open files > FF_FS_LOCK */ 294 | FR_INVALID_PARAMETER /* (19) Given parameter is invalid */ 295 | } FRESULT; 296 | 297 | 298 | 299 | 300 | /*--------------------------------------------------------------*/ 301 | /* FatFs Module Application Interface */ 302 | /*--------------------------------------------------------------*/ 303 | 304 | FRESULT f_open (FIL* fp, const TCHAR* path, BYTE mode); /* Open or create a file */ 305 | FRESULT f_close (FIL* fp); /* Close an open file object */ 306 | FRESULT f_read (FIL* fp, void* buff, UINT btr, UINT* br); /* Read data from the file */ 307 | FRESULT f_write (FIL* fp, const void* buff, UINT btw, UINT* bw); /* Write data to the file */ 308 | FRESULT f_lseek (FIL* fp, FSIZE_t ofs); /* Move file pointer of the file object */ 309 | FRESULT f_truncate (FIL* fp); /* Truncate the file */ 310 | FRESULT f_sync (FIL* fp); /* Flush cached data of the writing file */ 311 | FRESULT f_opendir (DIR* dp, const TCHAR* path); /* Open a directory */ 312 | FRESULT f_closedir (DIR* dp); /* Close an open directory */ 313 | FRESULT f_readdir (DIR* dp, FILINFO* fno); /* Read a directory item */ 314 | FRESULT f_findfirst (DIR* dp, FILINFO* fno, const TCHAR* path, const TCHAR* pattern); /* Find first file */ 315 | FRESULT f_findnext (DIR* dp, FILINFO* fno); /* Find next file */ 316 | FRESULT f_mkdir (const TCHAR* path); /* Create a sub directory */ 317 | FRESULT f_unlink (const TCHAR* path); /* Delete an existing file or directory */ 318 | FRESULT f_rename (const TCHAR* path_old, const TCHAR* path_new); /* Rename/Move a file or directory */ 319 | FRESULT f_stat (const TCHAR* path, FILINFO* fno); /* Get file status */ 320 | FRESULT f_chmod (const TCHAR* path, BYTE attr, BYTE mask); /* Change attribute of a file/dir */ 321 | FRESULT f_utime (const TCHAR* path, const FILINFO* fno); /* Change timestamp of a file/dir */ 322 | FRESULT f_chdir (const TCHAR* path); /* Change current directory */ 323 | FRESULT f_chdrive (const TCHAR* path); /* Change current drive */ 324 | FRESULT f_getcwd (TCHAR* buff, UINT len); /* Get current directory */ 325 | FRESULT f_getfree (const TCHAR* path, DWORD* nclst, FATFS** fatfs); /* Get number of free clusters on the drive */ 326 | FRESULT f_getlabel (const TCHAR* path, TCHAR* label, DWORD* vsn); /* Get volume label */ 327 | FRESULT f_setlabel (const TCHAR* label); /* Set volume label */ 328 | FRESULT f_forward (FIL* fp, UINT(*func)(const BYTE*,UINT), UINT btf, UINT* bf); /* Forward data to the stream */ 329 | FRESULT f_expand (FIL* fp, FSIZE_t fsz, BYTE opt); /* Allocate a contiguous block to the file */ 330 | FRESULT f_mount (FATFS* fs, const TCHAR* path, BYTE opt); /* Mount/Unmount a logical drive */ 331 | FRESULT f_mkfs (const TCHAR* path, const MKFS_PARM* opt, void* work, UINT len); /* Create a FAT volume */ 332 | FRESULT f_fdisk (BYTE pdrv, const LBA_t ptbl[], void* work); /* Divide a physical drive into some partitions */ 333 | FRESULT f_setcp (WORD cp); /* Set current code page */ 334 | int f_putc (TCHAR c, FIL* fp); /* Put a character to the file */ 335 | int f_puts (const TCHAR* str, FIL* cp); /* Put a string to the file */ 336 | int f_printf (FIL* fp, const TCHAR* str, ...); /* Put a formatted string to the file */ 337 | TCHAR* f_gets (TCHAR* buff, int len, FIL* fp); /* Get a string from the file */ 338 | 339 | /* Some API fucntions are implemented as macro */ 340 | 341 | #define f_eof(fp) ((int)((fp)->fptr == (fp)->obj.objsize)) 342 | #define f_error(fp) ((fp)->err) 343 | #define f_tell(fp) ((fp)->fptr) 344 | #define f_size(fp) ((fp)->obj.objsize) 345 | #define f_rewind(fp) f_lseek((fp), 0) 346 | #define f_rewinddir(dp) f_readdir((dp), 0) 347 | #define f_rmdir(path) f_unlink(path) 348 | #define f_unmount(path) f_mount(0, path, 0) 349 | 350 | 351 | 352 | 353 | /*--------------------------------------------------------------*/ 354 | /* Additional Functions */ 355 | /*--------------------------------------------------------------*/ 356 | 357 | /* RTC function (provided by user) */ 358 | #if !FF_FS_READONLY && !FF_FS_NORTC 359 | DWORD get_fattime (void); /* Get current time */ 360 | #endif 361 | 362 | 363 | /* LFN support functions (defined in ffunicode.c) */ 364 | 365 | #if FF_USE_LFN >= 1 366 | WCHAR ff_oem2uni (WCHAR oem, WORD cp); /* OEM code to Unicode conversion */ 367 | WCHAR ff_uni2oem (DWORD uni, WORD cp); /* Unicode to OEM code conversion */ 368 | DWORD ff_wtoupper (DWORD uni); /* Unicode upper-case conversion */ 369 | #endif 370 | 371 | 372 | /* O/S dependent functions (samples available in ffsystem.c) */ 373 | 374 | #if FF_USE_LFN == 3 /* Dynamic memory allocation */ 375 | void* ff_memalloc (UINT msize); /* Allocate memory block */ 376 | void ff_memfree (void* mblock); /* Free memory block */ 377 | #endif 378 | #if FF_FS_REENTRANT /* Sync functions */ 379 | int ff_mutex_create (int vol); /* Create a sync object */ 380 | void ff_mutex_delete (int vol); /* Delete a sync object */ 381 | int ff_mutex_take (int vol); /* Lock sync object */ 382 | void ff_mutex_give (int vol); /* Unlock sync object */ 383 | #endif 384 | 385 | 386 | 387 | 388 | /*--------------------------------------------------------------*/ 389 | /* Flags and Offset Address */ 390 | /*--------------------------------------------------------------*/ 391 | 392 | /* File access mode and open method flags (3rd argument of f_open) */ 393 | #define FA_READ 0x01 394 | #define FA_WRITE 0x02 395 | #define FA_OPEN_EXISTING 0x00 396 | #define FA_CREATE_NEW 0x04 397 | #define FA_CREATE_ALWAYS 0x08 398 | #define FA_OPEN_ALWAYS 0x10 399 | #define FA_OPEN_APPEND 0x30 400 | 401 | /* Fast seek controls (2nd argument of f_lseek) */ 402 | #define CREATE_LINKMAP ((FSIZE_t)0 - 1) 403 | 404 | /* Format options (2nd argument of f_mkfs) */ 405 | #define FM_FAT 0x01 406 | #define FM_FAT32 0x02 407 | #define FM_EXFAT 0x04 408 | #define FM_ANY 0x07 409 | #define FM_SFD 0x08 410 | 411 | /* Filesystem type (FATFS.fs_type) */ 412 | #define FS_FAT12 1 413 | #define FS_FAT16 2 414 | #define FS_FAT32 3 415 | #define FS_EXFAT 4 416 | 417 | /* File attribute bits for directory entry (FILINFO.fattrib) */ 418 | #define AM_RDO 0x01 /* Read only */ 419 | #define AM_HID 0x02 /* Hidden */ 420 | #define AM_SYS 0x04 /* System */ 421 | #define AM_DIR 0x10 /* Directory */ 422 | #define AM_ARC 0x20 /* Archive */ 423 | 424 | 425 | #ifdef __cplusplus 426 | } 427 | #endif 428 | 429 | #endif /* FF_DEFINED */ 430 | -------------------------------------------------------------------------------- /src/ff_gen_drv.c: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file ff_gen_drv.c 4 | * @author MCD Application Team 5 | * @brief FatFs generic low level driver. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2023 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the st_license.txt 13 | * file in the root directory of this software component. 14 | * If no st_license.txt file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Includes ------------------------------------------------------------------*/ 20 | #include "ff_gen_drv.h" 21 | 22 | /* Private typedef -----------------------------------------------------------*/ 23 | /* Private define ------------------------------------------------------------*/ 24 | /* Private variables ---------------------------------------------------------*/ 25 | Disk_drvTypeDef disk = {{0},{0},{0},0}; 26 | 27 | /* Private function prototypes -----------------------------------------------*/ 28 | /* Private functions ---------------------------------------------------------*/ 29 | 30 | /** 31 | * @brief Links a compatible diskio driver/lun id and increments the number of active 32 | * linked drivers. 33 | * @note The number of linked drivers (volumes) is up to 10 due to FatFs limits. 34 | * @param drv: pointer to the disk IO Driver structure 35 | * @param path: pointer to the logical drive path 36 | * @param lun : only used for USB Key Disk to add multi-lun management 37 | else the parameter must be equal to 0 38 | * @retval Returns 0 in case of success, otherwise 1. 39 | */ 40 | uint8_t FATFS_LinkDriverEx(const Diskio_drvTypeDef *drv, char *path, uint8_t lun) 41 | { 42 | uint8_t ret = 1; 43 | uint8_t DiskNum = 0; 44 | 45 | if(disk.nbr < FF_VOLUMES) 46 | { 47 | disk.is_initialized[disk.nbr] = 0; 48 | disk.drv[disk.nbr] = drv; 49 | disk.lun[disk.nbr] = lun; 50 | DiskNum = disk.nbr++; 51 | path[0] = DiskNum + '0'; 52 | path[1] = ':'; 53 | path[2] = '/'; 54 | path[3] = 0; 55 | ret = 0; 56 | } 57 | 58 | return ret; 59 | } 60 | 61 | /** 62 | * @brief Links a compatible diskio driver and increments the number of active 63 | * linked drivers. 64 | * @note The number of linked drivers (volumes) is up to 10 due to FatFs limits 65 | * @param drv: pointer to the disk IO Driver structure 66 | * @param path: pointer to the logical drive path 67 | * @retval Returns 0 in case of success, otherwise 1. 68 | */ 69 | uint8_t FATFS_LinkDriver(const Diskio_drvTypeDef *drv, char *path) 70 | { 71 | return FATFS_LinkDriverEx(drv, path, 0); 72 | } 73 | 74 | /** 75 | * @brief Unlinks a diskio driver and decrements the number of active linked 76 | * drivers. 77 | * @param path: pointer to the logical drive path 78 | * @param lun : not used 79 | * @retval Returns 0 in case of success, otherwise 1. 80 | */ 81 | uint8_t FATFS_UnLinkDriverEx(char *path, uint8_t lun) 82 | { 83 | (void)lun; 84 | uint8_t DiskNum = 0; 85 | uint8_t ret = 1; 86 | 87 | if(disk.nbr >= 1) 88 | { 89 | DiskNum = path[0] - '0'; 90 | if(disk.drv[DiskNum] != 0) 91 | { 92 | disk.drv[DiskNum] = 0; 93 | disk.lun[DiskNum] = 0; 94 | disk.nbr--; 95 | ret = 0; 96 | } 97 | } 98 | 99 | return ret; 100 | } 101 | 102 | /** 103 | * @brief Unlinks a diskio driver and decrements the number of active linked 104 | * drivers. 105 | * @param path: pointer to the logical drive path 106 | * @retval Returns 0 in case of success, otherwise 1. 107 | */ 108 | uint8_t FATFS_UnLinkDriver(char *path) 109 | { 110 | return FATFS_UnLinkDriverEx(path, 0); 111 | } 112 | 113 | /** 114 | * @brief Gets number of linked drivers to the FatFs module. 115 | * @param None 116 | * @retval Number of attached drivers. 117 | */ 118 | uint8_t FATFS_GetAttachedDriversNbr(void) 119 | { 120 | return disk.nbr; 121 | } 122 | -------------------------------------------------------------------------------- /src/ff_gen_drv.h: -------------------------------------------------------------------------------- 1 | /** 2 | ****************************************************************************** 3 | * @file ff_gen_drv.h 4 | * @author MCD Application Team 5 | * @brief Header for ff_gen_drv.c module. 6 | ****************************************************************************** 7 | * @attention 8 | * 9 | * Copyright (c) 2023 STMicroelectronics. 10 | * All rights reserved. 11 | * 12 | * This software is licensed under terms that can be found in the st_license.txt 13 | * file in the root directory of this software component. 14 | * If no st_license.txt file comes with this software, it is provided AS-IS. 15 | * 16 | ****************************************************************************** 17 | */ 18 | 19 | /* Define to prevent recursive inclusion -------------------------------------*/ 20 | #ifndef __FF_GEN_DRV_H 21 | #define __FF_GEN_DRV_H 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /* Includes ------------------------------------------------------------------*/ 28 | #include "diskio.h" 29 | #include "ff.h" 30 | #include "stdint.h" 31 | 32 | 33 | /* Exported types ------------------------------------------------------------*/ 34 | 35 | /** 36 | * @brief Disk IO Driver structure definition 37 | */ 38 | typedef struct 39 | { 40 | DSTATUS (*disk_initialize) (BYTE); /*!< Initialize Disk Drive*/ 41 | DSTATUS (*disk_status) (BYTE); /*!< Get Disk Status*/ 42 | DRESULT (*disk_read) (BYTE, BYTE*, DWORD, UINT); /*!< Read Sector(s)*/ 43 | DRESULT (*disk_write) (BYTE, const BYTE*, DWORD, UINT); /*!< Write Sector(s)*/ 44 | DRESULT (*disk_ioctl) (BYTE, BYTE, void*); /*!< I/O control operation*/ 45 | }Diskio_drvTypeDef; 46 | 47 | /** 48 | * @brief Global Disk IO Drivers structure definition 49 | */ 50 | typedef struct 51 | { 52 | uint8_t is_initialized[FF_VOLUMES]; 53 | const Diskio_drvTypeDef *drv[FF_VOLUMES]; 54 | uint8_t lun[FF_VOLUMES]; 55 | volatile uint8_t nbr; 56 | 57 | }Disk_drvTypeDef; 58 | 59 | /* Exported constants --------------------------------------------------------*/ 60 | /* Exported macro ------------------------------------------------------------*/ 61 | /* Exported functions ------------------------------------------------------- */ 62 | uint8_t FATFS_LinkDriver(const Diskio_drvTypeDef *drv, char *path); 63 | uint8_t FATFS_UnLinkDriver(char *path); 64 | uint8_t FATFS_LinkDriverEx(const Diskio_drvTypeDef *drv, char *path, BYTE lun); 65 | uint8_t FATFS_UnLinkDriverEx(char *path, BYTE lun); 66 | uint8_t FATFS_GetAttachedDriversNbr(void); 67 | 68 | #ifdef __cplusplus 69 | } 70 | #endif 71 | 72 | #endif /* __FF_GEN_DRV_H */ 73 | -------------------------------------------------------------------------------- /src/ffconf_template.h: -------------------------------------------------------------------------------- 1 | /*---------------------------------------------------------------------------/ 2 | / Configurations of FatFs Module 3 | /---------------------------------------------------------------------------*/ 4 | 5 | #define FFCONF_DEF 80286 /* Revision ID */ 6 | 7 | /*---------------------------------------------------------------------------/ 8 | / Function Configurations 9 | /---------------------------------------------------------------------------*/ 10 | 11 | #define FF_FS_READONLY 0 12 | /* This option switches read-only configuration. (0:Read/Write or 1:Read-only) 13 | / Read-only configuration removes writing API functions, f_write(), f_sync(), 14 | / f_unlink(), f_mkdir(), f_chmod(), f_rename(), f_truncate(), f_getfree() 15 | / and optional writing functions as well. */ 16 | 17 | 18 | #define FF_FS_MINIMIZE 0 19 | /* This option defines minimization level to remove some basic API functions. 20 | / 21 | / 0: Basic functions are fully enabled. 22 | / 1: f_stat(), f_getfree(), f_unlink(), f_mkdir(), f_truncate() and f_rename() 23 | / are removed. 24 | / 2: f_opendir(), f_readdir() and f_closedir() are removed in addition to 1. 25 | / 3: f_lseek() function is removed in addition to 2. */ 26 | 27 | 28 | #define FF_USE_FIND 0 29 | /* This option switches filtered directory read functions, f_findfirst() and 30 | / f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */ 31 | 32 | 33 | #define FF_USE_MKFS 0 34 | /* This option switches f_mkfs() function. (0:Disable or 1:Enable) */ 35 | 36 | 37 | #define FF_USE_FASTSEEK 0 38 | /* This option switches fast seek function. (0:Disable or 1:Enable) */ 39 | 40 | 41 | #define FF_USE_EXPAND 0 42 | /* This option switches f_expand function. (0:Disable or 1:Enable) */ 43 | 44 | 45 | #define FF_USE_CHMOD 0 46 | /* This option switches attribute manipulation functions, f_chmod() and f_utime(). 47 | / (0:Disable or 1:Enable) Also FF_FS_READONLY needs to be 0 to enable this option. */ 48 | 49 | 50 | #define FF_USE_LABEL 0 51 | /* This option switches volume label functions, f_getlabel() and f_setlabel(). 52 | / (0:Disable or 1:Enable) */ 53 | 54 | 55 | #define FF_USE_FORWARD 0 56 | /* This option switches f_forward() function. (0:Disable or 1:Enable) */ 57 | 58 | 59 | #define FF_USE_STRFUNC 0 60 | #define FF_PRINT_LLI 1 61 | #define FF_PRINT_FLOAT 1 62 | #define FF_STRF_ENCODE 3 63 | /* FF_USE_STRFUNC switches string functions, f_gets(), f_putc(), f_puts() and 64 | / f_printf(). 65 | / 66 | / 0: Disable. FF_PRINT_LLI, FF_PRINT_FLOAT and FF_STRF_ENCODE have no effect. 67 | / 1: Enable without LF-CRLF conversion. 68 | / 2: Enable with LF-CRLF conversion. 69 | / 70 | / FF_PRINT_LLI = 1 makes f_printf() support long long argument and FF_PRINT_FLOAT = 1/2 71 | / makes f_printf() support floating point argument. These features want C99 or later. 72 | / When FF_LFN_UNICODE >= 1 with LFN enabled, string functions convert the character 73 | / encoding in it. FF_STRF_ENCODE selects assumption of character encoding ON THE FILE 74 | / to be read/written via those functions. 75 | / 76 | / 0: ANSI/OEM in current CP 77 | / 1: Unicode in UTF-16LE 78 | / 2: Unicode in UTF-16BE 79 | / 3: Unicode in UTF-8 80 | */ 81 | 82 | 83 | /*---------------------------------------------------------------------------/ 84 | / Locale and Namespace Configurations 85 | /---------------------------------------------------------------------------*/ 86 | 87 | #define FF_CODE_PAGE 932 88 | /* This option specifies the OEM code page to be used on the target system. 89 | / Incorrect code page setting can cause a file open failure. 90 | / 91 | / 437 - U.S. 92 | / 720 - Arabic 93 | / 737 - Greek 94 | / 771 - KBL 95 | / 775 - Baltic 96 | / 850 - Latin 1 97 | / 852 - Latin 2 98 | / 855 - Cyrillic 99 | / 857 - Turkish 100 | / 860 - Portuguese 101 | / 861 - Icelandic 102 | / 862 - Hebrew 103 | / 863 - Canadian French 104 | / 864 - Arabic 105 | / 865 - Nordic 106 | / 866 - Russian 107 | / 869 - Greek 2 108 | / 932 - Japanese (DBCS) 109 | / 936 - Simplified Chinese (DBCS) 110 | / 949 - Korean (DBCS) 111 | / 950 - Traditional Chinese (DBCS) 112 | / 0 - Include all code pages above and configured by f_setcp() 113 | */ 114 | 115 | 116 | #define FF_USE_LFN 0 117 | #define FF_MAX_LFN 255 118 | /* The FF_USE_LFN switches the support for LFN (long file name). 119 | / 120 | / 0: Disable LFN. FF_MAX_LFN has no effect. 121 | / 1: Enable LFN with static working buffer on the BSS. Always NOT thread-safe. 122 | / 2: Enable LFN with dynamic working buffer on the STACK. 123 | / 3: Enable LFN with dynamic working buffer on the HEAP. 124 | / 125 | / To enable the LFN, ffunicode.c needs to be added to the project. The LFN function 126 | / requiers certain internal working buffer occupies (FF_MAX_LFN + 1) * 2 bytes and 127 | / additional (FF_MAX_LFN + 44) / 15 * 32 bytes when exFAT is enabled. 128 | / The FF_MAX_LFN defines size of the working buffer in UTF-16 code unit and it can 129 | / be in range of 12 to 255. It is recommended to be set it 255 to fully support LFN 130 | / specification. 131 | / When use stack for the working buffer, take care on stack overflow. When use heap 132 | / memory for the working buffer, memory management functions, ff_memalloc() and 133 | / ff_memfree() exemplified in ffsystem.c, need to be added to the project. */ 134 | 135 | 136 | #define FF_LFN_UNICODE 0 137 | /* This option switches the character encoding on the API when LFN is enabled. 138 | / 139 | / 0: ANSI/OEM in current CP (TCHAR = char) 140 | / 1: Unicode in UTF-16 (TCHAR = WCHAR) 141 | / 2: Unicode in UTF-8 (TCHAR = char) 142 | / 3: Unicode in UTF-32 (TCHAR = DWORD) 143 | / 144 | / Also behavior of string I/O functions will be affected by this option. 145 | / When LFN is not enabled, this option has no effect. */ 146 | 147 | 148 | #define FF_LFN_BUF 255 149 | #define FF_SFN_BUF 12 150 | /* This set of options defines size of file name members in the FILINFO structure 151 | / which is used to read out directory items. These values should be suffcient for 152 | / the file names to read. The maximum possible length of the read file name depends 153 | / on character encoding. When LFN is not enabled, these options have no effect. */ 154 | 155 | 156 | #define FF_FS_RPATH 0 157 | /* This option configures support for relative path. 158 | / 159 | / 0: Disable relative path and remove related functions. 160 | / 1: Enable relative path. f_chdir() and f_chdrive() are available. 161 | / 2: f_getcwd() function is available in addition to 1. 162 | */ 163 | 164 | 165 | /*---------------------------------------------------------------------------/ 166 | / Drive/Volume Configurations 167 | /---------------------------------------------------------------------------*/ 168 | 169 | #define FF_VOLUMES 1 170 | /* Number of volumes (logical drives) to be used. (1-10) */ 171 | 172 | 173 | #define FF_STR_VOLUME_ID 0 174 | #define FF_VOLUME_STRS "RAM","NAND","CF","SD","SD2","USB","USB2","USB3" 175 | /* FF_STR_VOLUME_ID switches support for volume ID in arbitrary strings. 176 | / When FF_STR_VOLUME_ID is set to 1 or 2, arbitrary strings can be used as drive 177 | / number in the path name. FF_VOLUME_STRS defines the volume ID strings for each 178 | / logical drives. Number of items must not be less than FF_VOLUMES. Valid 179 | / characters for the volume ID strings are A-Z, a-z and 0-9, however, they are 180 | / compared in case-insensitive. If FF_STR_VOLUME_ID >= 1 and FF_VOLUME_STRS is 181 | / not defined, a user defined volume string table is needed as: 182 | / 183 | / const char* VolumeStr[FF_VOLUMES] = {"ram","flash","sd","usb",... 184 | */ 185 | 186 | 187 | #define FF_MULTI_PARTITION 0 188 | /* This option switches support for multiple volumes on the physical drive. 189 | / By default (0), each logical drive number is bound to the same physical drive 190 | / number and only an FAT volume found on the physical drive will be mounted. 191 | / When this function is enabled (1), each logical drive number can be bound to 192 | / arbitrary physical drive and partition listed in the VolToPart[]. Also f_fdisk() 193 | / function will be available. */ 194 | 195 | 196 | #define FF_MIN_SS 512 197 | #define FF_MAX_SS 512 198 | /* This set of options configures the range of sector size to be supported. (512, 199 | / 1024, 2048 or 4096) Always set both 512 for most systems, generic memory card and 200 | / harddisk, but a larger value may be required for on-board flash memory and some 201 | / type of optical media. When FF_MAX_SS is larger than FF_MIN_SS, FatFs is configured 202 | / for variable sector size mode and disk_ioctl() function needs to implement 203 | / GET_SECTOR_SIZE command. */ 204 | 205 | 206 | #define FF_LBA64 0 207 | /* This option switches support for 64-bit LBA. (0:Disable or 1:Enable) 208 | / To enable the 64-bit LBA, also exFAT needs to be enabled. (FF_FS_EXFAT == 1) */ 209 | 210 | 211 | #define FF_MIN_GPT 0x10000000 212 | /* Minimum number of sectors to switch GPT as partitioning format in f_mkfs and 213 | / f_fdisk function. 0x100000000 max. This option has no effect when FF_LBA64 == 0. */ 214 | 215 | 216 | #define FF_USE_TRIM 0 217 | /* This option switches support for ATA-TRIM. (0:Disable or 1:Enable) 218 | / To enable Trim function, also CTRL_TRIM command should be implemented to the 219 | / disk_ioctl() function. */ 220 | 221 | 222 | 223 | /*---------------------------------------------------------------------------/ 224 | / System Configurations 225 | /---------------------------------------------------------------------------*/ 226 | 227 | #define FF_FS_TINY 0 228 | /* This option switches tiny buffer configuration. (0:Normal or 1:Tiny) 229 | / At the tiny configuration, size of file object (FIL) is shrinked FF_MAX_SS bytes. 230 | / Instead of private sector buffer eliminated from the file object, common sector 231 | / buffer in the filesystem object (FATFS) is used for the file data transfer. */ 232 | 233 | 234 | #define FF_FS_EXFAT 0 235 | /* This option switches support for exFAT filesystem. (0:Disable or 1:Enable) 236 | / To enable exFAT, also LFN needs to be enabled. (FF_USE_LFN >= 1) 237 | / Note that enabling exFAT discards ANSI C (C89) compatibility. */ 238 | 239 | 240 | #define FF_FS_NORTC 0 241 | #define FF_NORTC_MON 1 242 | #define FF_NORTC_MDAY 1 243 | #define FF_NORTC_YEAR 2022 244 | /* The option FF_FS_NORTC switches timestamp feature. If the system does not have 245 | / an RTC or valid timestamp is not needed, set FF_FS_NORTC = 1 to disable the 246 | / timestamp feature. Every object modified by FatFs will have a fixed timestamp 247 | / defined by FF_NORTC_MON, FF_NORTC_MDAY and FF_NORTC_YEAR in local time. 248 | / To enable timestamp function (FF_FS_NORTC = 0), get_fattime() function need to be 249 | / added to the project to read current time form real-time clock. FF_NORTC_MON, 250 | / FF_NORTC_MDAY and FF_NORTC_YEAR have no effect. 251 | / These options have no effect in read-only configuration (FF_FS_READONLY = 1). */ 252 | 253 | 254 | #define FF_FS_NOFSINFO 0 255 | /* If you need to know correct free space on the FAT32 volume, set bit 0 of this 256 | / option, and f_getfree() function at the first time after volume mount will force 257 | / a full FAT scan. Bit 1 controls the use of last allocated cluster number. 258 | / 259 | / bit0=0: Use free cluster count in the FSINFO if available. 260 | / bit0=1: Do not trust free cluster count in the FSINFO. 261 | / bit1=0: Use last allocated cluster number in the FSINFO if available. 262 | / bit1=1: Do not trust last allocated cluster number in the FSINFO. 263 | */ 264 | 265 | 266 | #define FF_FS_LOCK 0 267 | /* The option FF_FS_LOCK switches file lock function to control duplicated file open 268 | / and illegal operation to open objects. This option must be 0 when FF_FS_READONLY 269 | / is 1. 270 | / 271 | / 0: Disable file lock function. To avoid volume corruption, application program 272 | / should avoid illegal open, remove and rename to the open objects. 273 | / >0: Enable file lock function. The value defines how many files/sub-directories 274 | / can be opened simultaneously under file lock control. Note that the file 275 | / lock control is independent of re-entrancy. */ 276 | 277 | 278 | #define FF_FS_REENTRANT 0 279 | #define FF_FS_TIMEOUT 1000 280 | /* The option FF_FS_REENTRANT switches the re-entrancy (thread safe) of the FatFs 281 | / module itself. Note that regardless of this option, file access to different 282 | / volume is always re-entrant and volume control functions, f_mount(), f_mkfs() 283 | / and f_fdisk() function, are always not re-entrant. Only file/directory access 284 | / to the same volume is under control of this featuer. 285 | / 286 | / 0: Disable re-entrancy. FF_FS_TIMEOUT have no effect. 287 | / 1: Enable re-entrancy. Also user provided synchronization handlers, 288 | / ff_mutex_create(), ff_mutex_delete(), ff_mutex_take() and ff_mutex_give() 289 | / function, must be added to the project. Samples are available in ffsystem.c. 290 | / 291 | / The FF_FS_TIMEOUT defines timeout period in unit of O/S time tick. 292 | */ 293 | 294 | 295 | 296 | /*--- End of configuration options ---*/ 297 | -------------------------------------------------------------------------------- /src/ffsystem.c: -------------------------------------------------------------------------------- 1 | #ifndef _FFSYSTEM_H_ 2 | #define _FFSYSTEM_H_ 3 | 4 | #if defined(USE_FREERTOS) 5 | #include "../ffsystem/ffsystem_cmsis_os.c" 6 | #else 7 | #include "../ffsystem/ffsystem_baremetal.c" 8 | #endif 9 | 10 | #endif /* _FFSYSTEM_H_ */ -------------------------------------------------------------------------------- /src/integer.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------*/ 2 | /* Integer type definitions for FatFs module */ 3 | /*-------------------------------------------*/ 4 | 5 | #ifndef _FF_INTEGER 6 | #define _FF_INTEGER 7 | 8 | #ifdef _WIN32 /* FatFs development platform */ 9 | 10 | #include 11 | #include 12 | typedef unsigned __int64 QWORD; 13 | 14 | 15 | #else /* Embedded platform */ 16 | 17 | /* These types MUST be 16-bit or 32-bit */ 18 | typedef int INT; 19 | typedef unsigned int UINT; 20 | 21 | /* This type MUST be 8-bit */ 22 | typedef unsigned char BYTE; 23 | 24 | /* These types MUST be 16-bit */ 25 | typedef short SHORT; 26 | typedef unsigned short WORD; 27 | typedef unsigned short WCHAR; 28 | 29 | /* These types MUST be 32-bit */ 30 | typedef long LONG; 31 | typedef unsigned long DWORD; 32 | 33 | /* This type MUST be 64-bit (Remove this for ANSI C (C89) compatibility) */ 34 | typedef unsigned long long QWORD; 35 | 36 | #endif 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/st_readme.txt: -------------------------------------------------------------------------------- 1 | @verbatim 2 | ****************************************************************************** 3 | * @file st_readme.txt 4 | * @author MCD Application Team 5 | * @brief This file lists the main modification done by STMicroelectronics on 6 | * FatFs for integration with STM32Cube solution. 7 | * For more details on FatFs implementation on STM32Cube, please refer 8 | * to UM1721 "Developing Applications on STM32Cube with FatFs" 9 | ****************************************************************************** 10 | * @attention 11 | * 12 | * Copyright (c) 2017 STMicroelectronics. All rights reserved. 13 | * 14 | * This software component is licensed by ST under BSD 3-Clause license, 15 | * the "License"; You may not use this file except in compliance with the 16 | * License. You may obtain a copy of the License at: 17 | * opensource.org/licenses/BSD-3-Clause 18 | * 19 | ****************************************************************************** 20 | @endverbatim 21 | 22 | ### V4.0.1/18-08-2023 ### 23 | ============================ 24 | + Add LICENSE.md file at the root directory. 25 | 26 | ### V4.0.0/05-06-2023 ### 27 | ============================ 28 | + Update to FatFs R0.15 version 29 | 30 | + Rename ff_conf.h to ff_conf_template.h 31 | 32 | + Update the license of fatfs and drivers files 33 | 34 | + Rename ffsystem.c to ffsystem_template.c 35 | - Add ffsystem_baremetal.c and ffsystem_cmsis_os.c implmentations 36 | 37 | + Remove diskio drivers templates that use BSP APIs. 38 | 39 | + Add template folder containing template files 40 | - drivers/template/user_diskio.h/.c : User diskio driver 41 | - drivers/template/sd_diskio_config.h : uSD diskio configuration file 42 | - drivers/template/sram_diskio_config.h : sram diskio configuration file 43 | - drivers/template/usbh_diskio_config.h : usb host diskio configuration file 44 | 45 | + Rework sd diskio drivers to use HAL API 46 | - drivers/sd/sd_diskio.h/.c : sd driver using polling API 47 | - drivers/sd/sd_diskio_dma_standalone.h/.c : sd driver using DMA API in baremetal mode 48 | - drivers/sd/sd_diskio_dma_rtos.h/.c : sd driver using DMA API in RTOS mode 49 | - support unaligned access by default in sd_diskio_dma_rtos.c and sd_diskio_dma_standalone.c drivers 50 | 51 | + Add internal sram diskio driver 52 | - drivers/sram/sram_diskio.h/.c : sram driver 53 | 54 | + Rework usb host diskio driver to use HAL API 55 | - drivers/usb_host/usbh_diskio.h/.c : usbh driver 56 | 57 | + Update inclusion model for diskio drivers 58 | 59 | ### V3.0.0/20-04-2020 ### 60 | ============================ 61 | + update to the FatFs r0.14, that introduces compatibility break with the previous versions 62 | 63 | + apply patches to fix minor bugs in the r.014 release 64 | - ff.c 65 | 66 | + remove unneeded flags "_USE_WRITE" & "_USE_IOCTL" and use correct config flags as newly defined in the FatFs 0.14 release 67 | - diskio.c 68 | - diskio.h 69 | - ff_gen_drv.c 70 | - ff_gen_drv.h 71 | - ffconf_template.h 72 | - drivers/ppp_diskio_template.c 73 | - drivers/sd_diskio_dma_rtos_template_bspv1.c 74 | - drivers/sd_diskio_dma_rtos_template_bspv2.c 75 | - drivers/sd_diskio_dma_template_bspv1.c 76 | - drivers/sd_diskio_dma_template_bspv2.c 77 | - drivers/sd_diskio_template_bspv1.c 78 | - drivers/sd_diskio_template_bspv2.c 79 | - drivers/sdram_diskio_template_bspv1.c 80 | - drivers/sdram_diskio_template_bspv2.c 81 | - drivers/sram_diskio_template.c 82 | - drivers/usbh_diskio_dma_template.c 83 | - drivers/usbh_diskio_template.c 84 | 85 | + add new patterns file to provide different implmentations for the "ffsystem" API 86 | - patterns/ffsystem_baremetal.c 87 | - patterns/ffsystem_freertos.c 88 | - patterns/ffsystem_cmsis_os.c 89 | 90 | 91 | 92 | ### V2.1.4/11-10-2019 ### 93 | ============================ 94 | + Fix wrong usage of the "memcpy" in the SD_Write() function 95 | - drivers/sd_diskio_dma_template_bspv1.c 96 | - drivers/sd_diskio_dma_template_bspv2.c 97 | - drivers/sd_diskio_dma_rtos_template_bspv1.c 98 | - drivers/sd_diskio_dma_rtos_template_bspv2.c 99 | 100 | + correct the usage of the "_USE_MUTEX" config flag 101 | - syscall.c 102 | 103 | ### V2.1.3/26-07-2019 ### 104 | ============================ 105 | + add new BSPv2 templates: 106 | - drivers/sd_diskio_dma_rtos_template_bspv2.c 107 | - drivers/sd_diskio_dma_template_bspv2.c 108 | - drivers/sd_diskio_template_bspv2.c 109 | - drivers/sdram_diskio_template_bspv2.c 110 | 111 | + rename old template to "xxxx_diskio_template_bspv1.c": 112 | - drivers/sd_diskio_dma_rtos_template_bspv1.c 113 | - drivers/sd_diskio_dma_template_bspv1.c 114 | - drivers/sd_diskio_template_bspv1.c 115 | - drivers/sdram_diskio_template_bspv1.c 116 | 117 | + Add CMSIS-OSv2 support in templates, syscall.c and ff_conf_template.h 118 | - syscall.c 119 | - ff_conf_template.h 120 | - drivers/sd_diskio_dma_rtos_template_bspv2.c 121 | 122 | + support usage of "osMutex" alongside "osSemaphore" as _SYNC_t type in fatfs 123 | - syscall.c 124 | - ff_conf_template.h 125 | 126 | 127 | ### V2.1.2/29-03-2019 ### 128 | ============================ 129 | + add st_license.txt in the root directory 130 | + src/drivers/xxx_diskio_template.[c/h], src/ff_gen_drv.[c/h], src/option/syscall.c: update the license terms to BSD-3-Clause 131 | 132 | ### V2.1.1/25-01-2019 ### 133 | ============================ 134 | + sd_diskio_dma_rtos_template.c 135 | - Fix memory leak in the SD_Initialize() 136 | - Disable the ENABLE_SD_DMA_CACHE_MAINTENANCE flag by default to fix a build error for CM4 137 | - include correct diskio header file 138 | 139 | + sd_diskio_dma_template.c 140 | - Correct the SD_read() function when enabling the ENABLE_SCRATCH_BUFFER flag 141 | 142 | + sd_diskio_dma_rtos_template.c sd_diskio_dma_template.c 143 | - fix potential overflow when using SysTick. 144 | 145 | 146 | ### V2.1.0/21-09-2018 ### 147 | ============================ 148 | + ff.c 149 | - back-port a fix from 0.13, to correct an issue when using multi-threading 150 | access in the same device due to a missing semaphore lock when calling 151 | disk_status() API. 152 | 153 | + sd_diskio_dma_rtos_template.c 154 | - Add support to CMSIS-RTOS V2 API 155 | 156 | + sd_diskio_dma_rtos_template.c sd_diskio_dma_template.c 157 | - Add a compile flag "ENABLE_SCRATCH_BUFFER" to avoid misaligned access 158 | caused buffer alignment constraint in some DMA versions. 159 | - Add BSP_SD_ErrorCallback() and BSP_SD_AbortCallback() template functions. 160 | 161 | ### V2.0.2/17-November-2017 ### 162 | ============================ 163 | + sdram_diskio_template.c sram_diskio_template.c 164 | Fix wrong buffer size in the (SRAM/SDRAM)DISK_read(), (SRAM/SDRAM)DISK_write() 165 | 166 | + sd_diskio_template.c 167 | - define a generic 'SD_TIMEOUT' based on the BSP drivers defines. This fixes 168 | a build issue when using this driver with the Adafruit shield. 169 | 170 | + sd_diskio_dma_rtos_template.c 171 | - add a check via osKernelRunning(), to avoid runtime errors due to 172 | osMessageXXX calls that needs the "osKernelStart()" call done first. 173 | 174 | + sd_diskio_dma_template.c, sd_diskio_dma_rtos_template.c 175 | - fix wrong address alignment when calling SCB_InvalidateDCache_by_Addr() and 176 | SCB_CleanDCache_by_Addr(), the address has to be 32-Byte and not 177 | 32-bit aligned. 178 | 179 | - fix BSP_SD_ReadCpltCallback() and BSP_SD_WriteCpltCallback() prototypes by 180 | adding 'void' as argument to avoid IAR compiler errors 181 | 182 | 183 | + sd_diskio_template.c sd_diskio_dma_template.c, sd_diskio_dma_rtos_template.c 184 | - add the flag "DISABLE_SD_INIT" to give the user the choice to initialize the SD 185 | either in the application or in the FatFs diskio driver. 186 | 187 | + all xxx_diskio_template.c 188 | - fix GET_BLOCK_SIZE ioctl call; the return value is in unit of sectors. 189 | 190 | 191 | ### V2.0.1/10-July-2017 ### 192 | ============================ 193 | + sd_diskio_dma_template.c, sd_diskio_dma_rtos_template.c 194 | - add the flag "ENABLE_SD_DMA_CACHE_MAINTENANCE", to enable cache maintenance at each read write operation. 195 | This is useful for STM32F7/STM32H7 based platforms when using a cachable memory region. 196 | - add timeout checks in SD_Read() and SD_Write() to give the control back to the application to decide in case of errors. 197 | 198 | + ff_gen_drv.c: fix a wrong check that causes an out of bound array access. 199 | 200 | 201 | ### V2.0.0/07-March-2017 ### 202 | ============================ 203 | + Upgrade to use FatFS R0.12c. The R0.12c breaks the API compatibility with R0.11b. 204 | - f_mkfs() API has a new signature. 205 | - The _CODE_PAGE got new values. 206 | - For more details check the files (doc/updates.txt) and the following urls: 207 | http://elm-chan.org/fsw/ff/en/mkfs.html 208 | http://elm-chan.org/fsw/ff/en/config.html 209 | 210 | + Add USB, RAMDISK and uSD template drivers under src/drivers. 211 | - The diskio drivers aren't part of fatfs anymore, they are just templates instead. 212 | - User has to copy the suitable template .c/.h file under the project, rename them by 213 | removing the "_template" suffix then link them into the final application. 214 | - The diskio driver .c/.h files have to be edited according to the used platform. 215 | 216 | + Define the macros "ff_malloc" and "ff_free" in the ff_conf_template.h and use 217 | them in the syscall.c instead of direct calls to stdlib malloc and free functions. 218 | + Define the "__weak" attribute in diskio.c for the GNU GCC compiler 219 | 220 | 221 | ### V1.4.0/09-September-2016 ### 222 | ================================ 223 | + Upgrade to use FatFs R0.12b. 224 | + ff_conf.h: remove the use of define "_USE_BUFF_WO_ALIGNMENT". 225 | 226 | 227 | ### V1.3.0/08-May-2015 ### 228 | ========================== 229 | + Upgrade to use FatFs R0.11. 230 | + Add new APIs FATFS_LinkDriverEx() and FATFS_UnLinkDriverEx() to manage USB Key Disk having 231 | multi-lun capability. These APIs are equivalent to FATFS_LinkDriver() and FATFS_UnLinkDriver() 232 | with "lun" parameter set to 0. 233 | + ff_conf.h: add new define "_USE_BUFF_WO_ALIGNMENT". 234 | This option is available only for usbh diskio interface and allow to disable 235 | the management of the unaligned buffer. 236 | When STM32 USB OTG HS or FS IP is used with internal DMA enabled, this define 237 | must be set to 0 to align data into 32bits through an internal scratch buffer 238 | before being processed by the DMA . Otherwise (DMA not used), this define must 239 | be set to 1 to avoid Data alignment and improve the performance. 240 | Please note that if _USE_BUFF_WO_ALIGNMENT is set to 1 and an unaligned 32bits 241 | buffer is forwarded to the FatFs Write/Read functions, an error will be returned. 242 | (0: default value or 1: unaligned buffer return an error). 243 | 244 | 245 | + Important note: 246 | For application code based on previous FatFs version; when moving to R0.11 247 | the changes that need to be done is to update ffconf.h file, taking 248 | ffconf_template.h file as reference. 249 | 250 | 251 | ### V1.2.1/20-November-2014 ### 252 | =============================== 253 | + Disk I/O drivers; change count argument type from BYTE to UINT 254 | 255 | + Important note: 256 | For application code based on previous FatFs version; when moving to R0.10b 257 | the only change that need to be done is to update ffconf.h file, taking 258 | ffconf_template.h file as reference. 259 | 260 | 261 | ### V1.2.0/04-November-2014 ### 262 | =============================== 263 | + Upgrade to use FatFs R0.10b. 264 | + diskio.c: update disk_read() and disk_write() argument's type. 265 | 266 | + Important note: 267 | For application code based on previous FatFs version; when moving to R0.10b 268 | the only change that need to be done is to update ffconf.h file, taking 269 | ffconf_template.h file as reference. 270 | 271 | 272 | ### V1.1.1/12-September-2014 ### 273 | ================================ 274 | + ff_gen_drv.c: Update the Disk_drvTypeDef disk variable initialization to avoid 275 | warnings detected with Atollic TrueSTUDIO Complier. 276 | 277 | 278 | ### V1.1.0/22-April-2014 ### 279 | ============================ 280 | + Update sd_diskio to use SD BSP in polling mode instead of DMA mode (the scratch 281 | buffer needed for DMA alignment is removed as well). 282 | + diskio.c and ff_gen_drv.c/.h: update to prevent multiple initialization. 283 | 284 | 285 | ### V1.0.0/18-February-2014 ### 286 | =============================== 287 | + First R0.10 customized version for STM32Cube solution. 288 | 289 | 290 | *

© COPYRIGHT STMicroelectronics

291 | */ 292 | -------------------------------------------------------------------------------- /st_license.txt: -------------------------------------------------------------------------------- 1 | This software component is provided to you as part of a software package and 2 | applicable license terms are in the Package_license file. If you received this 3 | software component outside of a package or without applicable license terms, 4 | the terms of the BSD-3-Clause license shall apply. 5 | You may obtain a copy of the BSD-3-Clause at: 6 | https://opensource.org/licenses/BSD-3-Clause 7 | --------------------------------------------------------------------------------