Home

Developing Applicati..

image

Contents

1. Multiple volumes physical drives and partitions Multiple ANSI OEM code pages including DBCS Long file name support in ANSI OEM or Unicode RTOS support Multiple sector size support Read only minimized API I O buffer and etc FAT sub types FAT12 FAT16 and FAT 32 Number of open files Unlimited depends on available memory Number of volumes Up to 10 File size Depends on FAT specs up to 4G 1 bytes Volume size Depends on FAT specs up to 2T bytes on 512 bytes sector Cluster size Depends on FAT specs up to 64K bytes on 512 bytes sector Sector size Depends on FAT specs up to 4K bytes FatFs architecture FatFs module is a middleware which provides many functions to access the FAT volumes such as f open f close f read f write etc refer to ff c There is no platform dependence in this module as long as the compiler is compliant with ANSI C A low level disk I O module is used to read write the physical drive An RTC module is used to get the current time The low level disk I O and the RTC module are completely separate from the FatFs module They must be provided by the user which is the main task of porting FatFs module to other platforms Figure 3 FatFs architecture Application FatFs Module System Call Low Level Disk I O USD RAM USB FS REENTRANT 1 2 DoclD0258
2. lt 7 UM1721 WI life augmented User manual Developing Applications on STM32CubeF4 with FatFs Introduction The STM32Cube initiative was originated by STMicroelectronics to ease developers life by reducing development efforts time and cost STM32Cube M covers the STM32 portfolio STM32Cube M version 1 x includes e he STM32CubeMNX a graphical software configuration tool that allows to generate C initialization code using graphical wizards e A comprehensive embedded software platform delivered per series namely STM32CubeF4 for STM32F4 series The STM32CubeF4 HAL an STM32 abstraction layer embedded software ensuring maximized portability across STM32 portfolio A consistent set of middleware components such as RTOS USB TCP IP Graphics All embedded software utilities coming with a full set of examples A File System is the way in which files ares named and where they are placed logically for storage and retrieval Its primary objective is to manage access to the data of files and to manage the available space of the device s which contain it Using a file system allows user to ensure reliability and to organize data in an efficient manner This user manual is intended for developers who use STM32CubeF4 firmware on STM32 microcontrollers It provides a full description of how to use the STM32CubeF4 firmware components with a generic FAT File System FatFs this user manual comes also with description of a set of exam
3. f read f write DocID025800 Rev 1 13 26 FatFs File System UM1721 2 7 14 26 FatFs into STM32CubeF4 In the STM32CubeF4 solution an additional interface layer has been added to add remove dynamically physical media to from the FatFs module To link FatFs module with a low level disk I O driver user can use FATFS_LinkDriver and FATFS_UnLinkDriver to add or remove dynamically a disk I O driver the application may need to know the number of current attached disk I O drivers this is done through the FATFS_GetAttachedDriversNbr API Figure 5 FatFs Middleware module architecture Application FatFs Module 5 Low Level Disk I O Drivers Na HAL Drivers The generic low level driver ff gen drv c h is located in the root directory of the FatFs modules Two disk I O driver type definition structures are used to help dynamic management of attached disk drives under the ff gen drv h file as mentioned below Table 2 Diskio drv TypeDef structure Field Description DSTATUS disk anitialize void Initialize Disk Drive DSTATUS disk status void Get Disk Status DRESULT disk read BYTE DWORD BYTE Read Sector s DRESULT disk write const BYTE DWORD Write Sector s BYTE M E should be 0 DRESULT disk ioctl BYTE void I O control operation _USE_IOCTL should be 1 Table 3 Disk drv TypeDef structure EE ee ED Diskio drvTypeDef
4. Link FatFs module to a dummy disk I O driver in RAM and perform mount open write read Close operation through a static buffer Link FatFs module to a USD disk I O driver FatFs on single Logical Unit and perform mount open write read close operations through a static buffer Link FatFs module to USD and RAM disk I O FatFs on Multi Logical Unit driver and perform mount open write read close operations through a static buffer Link FatFs module to USB Host diskl O driver and perform mount open write read close operations through a static buffer FatFs on single Logical Unit RAMDisk Getting started Features FatFs on single Logical Unit Integrated USB Disk The FatFs applications listed above provided within STM32CubeF4 solution are a set of firmware available in two modes e Standalone mode e RTOS mode using FreeRTOS middleware component It is worth noting that user must guarantee appropriate values of stack and heap when using or developing FatFs applications based on ST provided disk I O low level drivers Thus stack value must be incremented by the handled maximum sector size MAX SS value available within ff conf h file when using USB Disk application based on USB Host Mass Storage Class MSC for scratch alignment reasons Heap value must be also adjusted when developing any FatFs application in RTOS mode using FreeRTOS middleware component based on CMSIS OS wrapping layer common APIs HAL
5. 15 26 FatFs File System UM1721 2 7 3 2 8 16 26 disk drv disk nbr 0 ret 0 return ret FATFS GetAttachedDriverNbr This function returns the number of linked drivers to the FatFs module Implementation of FATFS_GetAttachedDriversNbr uint8 t FATFS GetAttachedDriversNbr void return disk nbr Interface your own disk to FatFs If a working storage control module is available it should be attached to the FatFs via a glue function rather than modifying it User can interface any new disk by developing the appropriate disk I O low level driver mynewdisk diskio c h and save these driver files under Middlewares Third_Party FatFs src drivers It is worth noting that the provided FatFs disk I O low level drivers are dependent on the board BSP drivers To remove this BSP dependency the user can just replace BSP APIs calls by his own code ensuring the appropriate functionality To develop a disk I O low level driver from scratch the user can start from the skeleton of glue functions below to attach the existing storage control module to the FatFs with a defined API Low level disk I O module skeleton for FatFs Ms Ep a te a k mynewdisk diskio c Low level disk I O module skeleton for FatFs 8f ascos a dopo x DA Se A SO SA A A A A A mi include lt string h gt include rif gen dryn e Private CI AA AA AA AA i define BLOCK SIZE 512
6. Block Size in Bytes Private variables 5 oe d static volatile DSTATUS Stat STA NOINIT Disk status a Telvate TUON DEODODUDBS 229 oil el DSTATUS mynewdisk initialize void DoclD025800 Rev 1 Ly UM1721 a FatFs File System DSTATUS mynewdisk status void DRESULT mynewdisk read BYTE DWORD BYTE if USE WRITE 1 DRESULT mynewdisk write const BYTE DWORD BYTE endif USE WRITE 1 if USE IOCTL 1 DRESULT mynewdisk ioctl BYTE void tendif USE IOCTL 1 Diskio drvTypeDef mynewdisk Driver mynewdisk initialize mynewdisk status mynewdisk read Hif USE WRITE 1 mynewdisk write endif USE WRITE 1 Saa S Titel d Drive Sasso AASA na DSTATUS mynewdisk initialize void otat SLA NOLNIT write your own code here to initialize the drive otat 87 STA NOINIT return Stats eS cue Cel Push ratas cesse eee Sut DSTATUS mynewdisk status void stat SLA NOLNIT write your own code here return Stat C E Read SEOCLOEQS ny DRESULT mynewdisk read BYTE buff Data buffer to store read data DWORD sector Sector address LBA BYTE count Number of sectors to read 1 128 DRESULT res RES ERROR write your own code here to read sectors from the drive return Tes eae acai ak a he WELLS sectors a Su if USE WRITE 1 DRESULT mynewdisk write const BYTE buff Data t
7. Microsoft Extensible Firmware Initiative FAT32 File System Specification rev 1 03 December 6 2000 is available as an Office Word document 268 kBytes DocID025800 Rev 1 Ly UM1721 3 FAT File System overview The download license agreement allows using the Microsoft EFI FAT32 File System Specification only in connection with a firmware implementation of the Extensible Firmware Initiative Specification v 1 0 If you plan to implement the FAT32 File System specification for other purposes you must obtain an additional license from Microsoft For example you must obtain an additional license in order to create a file system for reading or reading and writing FAT32 in digital cameras recording to Flash media in computer operating systems reading and writing internal external hard disks or Flash media or in set top boxes reading FAT formatted media For more details about FAT and applicable licenses and or copyrights refer to Microsoft web site DocID025800 Rev 1 9 26 FatFs File System UM1721 2 2 1 2 2 10 26 FatFs File System FatFs overview 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 and has the following features e Windows compatible FAT file system e Very small footprint for code and work area e Various configuration options
8. drivers configuration FatFs applications provided within STM32CubeF4 solution is a set of firmware used to interface different physical disk drives uSD RAM Disk USB Disk User needs some HAL drivers which are essential to run the FatFs application The correspond HAL drivers are enabled through the HAL configuration file stm32f4xx hal conf h by uncommenting the right modules used in the HAL driver DocID025800 Rev 1 19 26 FatFs applications UM1721 3 2 3 2 1 3 2 2 20 26 The main difference in HAL configuration files between the supported disk drivers is the definition of the right HAL driver corresponding to the used disk drive The following defines must be available depending on each drive e FatFs USD Fdefine HAL SD MODULE ENABLED e FatFs RAMDisk define HAL SDRAM MODULE ENABLED or define HAL SRAM MODULE ENABLED e FatFs_USBDisk define HAL HCD MODULE ENABLED FatFs File System configuration FatFs module contains various configuration options At this level we provide information to help user select proper options depending on the interfaced physical disk drives his requirement to reach the highest performance Reentrancy Reentrancy is the key difference between the Standalone and the RTOS modes configurations which can be set on FatFs configuration file ffconf h e Reentrancy is disabled in Standalone mode define FS REENTRANT 0 e Reentrancy is enabled in RTOS mode define FS REEN
9. hard disk drive volume Master Boot Record The Master Boot Record MBR is located on one or more sectors at the physical start of the device The boot region of the MBR contains DOS boot loader code which is written when the device is formatted but is not otherwise used by the Dynamic C FAT file system The partition table follows the boot region It contains four 16 byte entries which allow up to four partitions on the device Partition table entries contain some critical information the partition type Dynamic C FAT recognizes FAT 12 and FAT 16 partition types and the partition s starting and ending sector numbers There is also a field denoting the total number of sectors in the partition If this number is zero the corresponding partition is empty and available Figure 1 High level view of an MBR Master Boot Record MBR Entry OxOOO aaa AGA Boot Region Partition O Partition 1 Partition 2 Partition Table Partition 3 Signature DocID025800 Rev 1 7 26 FAT File System overview UM1721 8 26 Some devices are formatted without an MBR and therefore have no partition table This configuration is not currently supported in the Dynamic C FAT file system FAT partitions The first sector of a valid FAT file system partition contains the BIOS Parameter Block BPB followed by the File Allocation Table FAT and then the Root Directory The figure below shows a devic
10. is enabled with some code pages FatFs APIs The FatFs APIs layer implements file system APIs It uses disk I O interface to communicate with the appropriate physical drive The set of APIs is divided into four groups e Group of APIs that operates with logical volume or partition e Group of APIs that operates with directory e Group of APIs that operates with file e Group of APIs that operates with both file and directory The following list describes what FatFs can do to access the FAT volumes e f mount Register Unregister a work area e f open Open Create a file e f close Close a file e f read Read a file e f write Write a file e f Iseek Move read write pointer Expand a file size e f truncate Truncate a file size e f sync Flush cached data e f opendir Open a directory e f readdir Read a directory item e f getfree Get free clusters f stat Check if the object is exist and get status e f mkdir Create a directory DoclD025800 Rev 1 Ly UM1721 2 6 FatFs File System e f unlink Remove a file or directory e f chmod Change an attribute e f utime Change timestamp e f rename Rename Move a file or directory e f chdir Change the current directory e f chdrive Change the current drive M e f getcwd Retrieve the current directory e f getlabel Get volume label e f setlabel Set volume label e f forward Forward file data to th
11. 00 Rev 1 UM1721 FatFs File System 2 3 FatFs license Figure 4 is a copy of the FatFs license document included in the source codes Figure 4 FatFs license C Cha OMS FatFs module is a generic FAT file system module for small embedded systems This is a free software that opened for education research and commercial developments under license policy of following trems Copyright 2013 Chan ati Tight lt eserved The FatFs module is a free software and there is NO WARRANTY NO Eestelection en use You CAN use modastsy ana redistribute 1t Lor personal moa retira Commerce O cuc S UNDER VOU EESEPEONTEPILTDNN Redistributions of source code must retain the above copyright notice Therefore FatFs license is one of the BSD style licenses but there is a big difference Because FatFs is for embedded projects the conditions for redistributions in binary form such as embedded code hex file and binary library are not specified to increase its usability The documentation of the distributions need not include about FatFs and its license document and it may also Of course FatFs is compatible with the projects under GNU GPL When redistribute it with any modification the license can also be changed to GNU GPL or BSD style license 2 4 FatFs features 2 4 1 Duplicate file access FatFs module does not support the sharing controls of duplicated file access in default It is permitted when open
12. 3 1 HAL drivers configuration aaea ea 19 3 2 FatFs File System configuration llle 20 3 2 1 aine epica sao arco da e os KA 20 3 2 2 Long file name rn 20 3 3 FatFs sample application 0 0 aa ee 21 4 Conclusions lsome sauna RE Rn de dee tee ceases 23 2 26 DocID025800 Rev 1 Ly UM1721 3 Contents PAG Ao v 24 REVISION DISIOFV 19g inde der c A a 25 DocID025800 Rev 1 3 26 List of tables UM1721 List of tables Table 1 Table 2 Table 3 Table 4 Table 5 4 26 Acronyms and OSTINIM NS a scecco ciecwnagen a OS REESE a rd ea 6 Diskio drv TypeDef structure o ooooooornon RR RII 14 Disk drv TypeDef structure 0 nananana aana a eens 14 Examples of FatFs middleware utilization 0 0 0 0 cc ee 19 Document revision history DocID025800 Rev 1 Ly UM1721 List of figures List of figures Figure 1 High level view of an MBR o ooococooon eee eens T Figure 2 Two FAT partitions on a device eee 8 Figure 3 FAFS architec ful s x ua doe woe Sa gaia ie E ee wee A S e wide da a 10 Figure 4 Ptr Ss A ee genes tne ews Ge Grae Acre 11 Figure 5 FatFs Middleware module architecture eee 14 Ly DoclD025800 Rev 1 5 26 Acronyms and definitions UM1721 Acronyms and definitions Table 1 Acronyms and definitions 2 6 26 DocID025800 Rev 1 UM1721 1 1 1 3 FAT File System overview FAT File Sys
13. TRANT 1 Once enabled user must provide the OS dependent type of synchronization object define _SYNC_t osSemaphoreld RTOS mode applications projects need to include the syscall c file providing the OS depending functions and found under Middlewares Third_Party FatFs src option Long file name The FatFs module supports long file name LFN and 8 3 format file name SFN Note that the LFN feature on the FAT file system is a patent of Microsoft Corporation This is not the case on FAT32 but most FAT32 drivers include the LFN feature FatFs can switch the LFN feature by configuration option When enable LFN feature on the commercial products a license from Microsoft may be required depends on the final destination The LFN can be used when LFN feature is enabled which can be set on FatFs configuration file ffconf h USE LFN gt 0 within FatFs configuration file ffconf h e LFN feature is disabled define USE LFN 0 e LFN feature is enabled when 32 USE LFN gt Q Once enabled on ffconf h configuration file the application project needs to include the syscall c unicode c files providing memory management functions and found under Middlewares Third_Party FatFs src option DoclD025800 Rev 1 Ly UM1721 3 3 a FatFs applications User can enable LFN feature either on standalone mode applications or in RTOS mode ones FatFs sample application If user has already attached its own disk developing the appropr
14. UITABLE FOR USE IN AEROSPACE BY THE CORRESPONDING GOVERNMENTAL AGENCY Resale of ST products with provisions different from the statements and or technical features set forth in this document shall immediately void any warranty granted by ST for the ST product or service described herein and shall not create or extend in any manner whatsoever any liability of ST ST and the ST logo are trademarks or registered trademarks of ST in various countries Information in this document supersedes and replaces all information previously supplied The ST logo is a registered trademark of STMicroelectronics All other names are the property of their respective owners 2014 STMicroelectronics All rights reserved STMicroelectronics group of companies Australia Belgium Brazil Canada China Czech Republic Finland France Germany Hong Kong India Israel Italy Japan Malaysia Malta Morocco Philippines Singapore Spain Sweden Switzerland United Kingdom United States of America www st com 26 26 DocID025800 Rev 1 Ly
15. clude mynewdisk diskio h 2 22 26 DoclD025800 Rev 1 UM1721 Conclusions 4 Conclusions This User Manual explains how to integrate the FatFs middleware components within the STM32CubeF4 HAL drivers A set of examples have been described to help users who develop applications based on FatFs File System within STM32CubeF4 solution Ly DocID025800 Rev 1 23 26 FAQ 24 26 UM1721 FAQ How to use LFN feature with FatFs The FatFs module supports long file name LFN For more details on how to use LFN feature with FatFs refer to Section 2 4 3 Long file name and Section 3 2 2 Long file name What s the difference between FatFs Multi partitions and Multi drives applications Multi partitions application can use multi logical drivers that can be bound to partitions on the specified physical drive otherwise Multi drives applications use different logical drives at the same time uSD RAMDisk User can choose the number of logical drives volumes to be used through VOLUMES definition within FatFs ffconf h configuration file Can user interface any new Disk to FatFs Yes the user can interface a new disk to FatFs For more details refer to Section 2 8 Interface your own disk to FatFs Does FatFs support Multi instances No it doesn t STM32CubeF4 solution provides the multi instance feature for HAL drivers but concerning FatFs middleware component it cannot really support physical drivers multi instances In
16. cument refers to any third party products or services it shall not be deemed a license grant by ST for the use of such third party products or services or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoever of such third party products or services or any intellectual property contained therein UNLESS OTHERWISE SET FORTH IN ST S TERMS AND CONDITIONS OF SALE ST DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY WITH RESPECT TO THE USE AND OR SALE OF ST PRODUCTS INCLUDING WITHOUT LIMITATION IMPLIED WARRANTIES OF MERCHANTABILITY FITNESS FOR A PARTICULAR PURPOSE AND THEIR EQUIVALENTS UNDER THE LAWS OF ANY JURISDICTION OR INFRINGEMENT OF ANY PATENT COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT ST PRODUCTS ARE NOT DESIGNED OR AUTHORIZED FOR USE IN A SAFETY CRITICAL APPLICATIONS SUCH AS LIFE SUPPORTING ACTIVE IMPLANTED DEVICES OR SYSTEMS WITH PRODUCT FUNCTIONAL SAFETY REQUIREMENTS B AERONAUTIC APPLICATIONS C AUTOMOTIVE APPLICATIONS OR ENVIRONMENTS AND OR D AEROSPACE APPLICATIONS OR ENVIRONMENTS WHERE ST PRODUCTS ARE NOT DESIGNED FOR SUCH USE THE PURCHASER SHALL USE PRODUCTS AT PURCHASER S SOLE RISK EVEN IF ST HAS BEEN INFORMED IN WRITING OF SUCH USAGE UNLESS A PRODUCT IS EXPRESSLY DESIGNATED BY ST AS BEING INTENDED FOR AUTOMOTIVE AUTOMOTIVE SAFETY OR MEDICAL INDUSTRY DOMAINS ACCORDING TO ST PRODUCT DESIGN SPECIFICATIONS PRODUCTS FORMALLY ESCC QML OR JAN QUALIFIED ARE DEEMED S
17. drv VOLUMES Diskio drv TypeDef structure Number of the attached drives 2 DoclD025800 Rev 1 UM1721 2 7 1 Note 2 7 2 3 FatFs File System To link FatFs module with a low level disk I O driver user can use the following APIs e FATFS LinkDriver to add dynamically a disk I O driver e FATFS UnLinkDriver to remove dynamically a disk I O driver e FATFS GetAttachedDriversNbr to know the number of current attached disk I O drivers FATFS_LinkDriver This function links a compatible disk I O driver and increments the number of active linked drivers It returns O in case of success otherwise it returns 1 Due to FatFs limits the MAX number of attached disks VOLUMES is up to 10 Implementation of FATFS_LinkDriver uint8 t FATFS LinkDriver Diskio drvTypeDef drv char path uint8 t ret 1 uint8_t DiskNum 0 if disk nbr lt VOLUMES diskecry disk nbr dev DiskNum disk nbr path 0 DiskNum 0 path 1 tests path 2 path 3 0 ret 0 return ret FATFS UnlinkDriver This function unlinks a disk l O driver and decrements the number of active linked drivers lt returns O in case of success otherwise it returns 1 Implementation of FATFS UnLinkDriver uint8 t FATFS UnLinkDriver char path uint8_t DiskNum 0 nineto ret 1 if disk nbr gt 1 DiskNum path 0 0 if DiskNum lt disk nbr DocID025800 Rev 1
18. e stream directly e f mkfs Create a file system on the drive e f fdisk Devide a physical drive e f gets Read a string e f putc Write a character e f puts Write a string e f printf Write a formatted string e f tell Get the current read write pointer e f eof Test for end of file on a file e f size Get the size of a file e f error Test for an error on a file FatFs low level APIs Since the FatFs module is completely separate from the disk I O and RTC module it requires some low level functions to operate the physical drive read write and get the current time Because the low level disk I O functions and RTC module are not a part of the FatFs module they must be provided by the user The FatFs Middleware solution provides low level disk I O drivers for some supported disk drives RAMDisk uSD USBDisk An additional interface layer diskio c has been added to add remove dynamically link physical media to the FatFs module providing low level disk I O functions as mentioned below e disk initialize Initializes the physical disk drive e disk status Returns the selected physical drive status e disk read Reads sector s from the disk e disk write Writes sector s to the disk e disk ioctl Controls device specified features e get fattime Returns the current time Application program MUST NOT call these functions they are only called by FatFs file system functions such as f mount
19. e with two FAT partitions Figure 2 Two FAT partitions on a device Partition O Partition 1 BPB BPB FAT Data Area FAT Data Area ROOT ROOT tf 14 1 Sector 0 First Sector Start of First Sector Start of of Device of Partition 1 Cluster 2 of Partition 2 Cluster 2 BIOS Parameter Block The fields of the BPB contain information describing the partition e The number of bytes per sector e The number of sectors per cluster e The total count of sectors on the partition e The number of root directory entries FAT Allocation Table The file allocation table is the structure that gives the FAT file system its name The FAT stores information about cluster assignments A cluster is either assigned to a file is available for use or is marked as bad A second copy of the FAT immediately follows the first one Root directory The root directory has a predefined location and size It has 512 entries of 32 bytes each An entry in the root directory is either empty or contains a file or subdirectory name in 8 3 format file size date and time of last revision and the starting cluster number for the file or subdirectory Data area The data area takes up most of the partition It contains file data and subdirectories Note that the data area of a partition must by convention start at cluster 2 For more details refer to the Microsoft EFI FAT32 File System Specification FAT license The
20. iate disk I O low level driver mynewdisk diskio c h refer to Section 2 8 Interface your own disk to FatFs linking this driver to FatFs module and using its logical disk can be done as follows eses AA AA AA e x main c Main program body 7 EEE ae AA x pac des AA AA AA A eee n include main fe Private Verlables O ay FATFS mynewdiskFatFs File system object for User logical drive FIL MyFile File object char mynewdiskPath 4 User logical drive path int main void uint32 t wbytes File write counts uint8 t wtext text to write logical disk File write buffer if FATFS LinkDriver amp mynewdisk Driver mynewdiskPath 0 if f mount mynewdiskFatFs TCHAR const mynewdiskPath 0 FR OK if f open amp MyFile STM32 TXT FA CREATE ALWAYS FA WRITE FR OK if f write amp MyFile wtext sizeof wtext void amp wbytes FR OK f close amp MyFile FATFS UnLinkDriver mynewdiskPath User must include the generic drive ff gen drv h header file and also the disk IO module header file mynewdisk diskio h ee x main hi Header for main c module rd 9 x DocID025800 Rev 1 21 26 FatFs applications UM1721 9 TAI esee EN AAN iA include Fr gen drv h in
21. kfs functions These functions are not reentrant to the same volume When using these functions all other tasks must close the corresponding file on the volume and avoid accessing the volume Note that this section describes the reentrancy of the FatFs module itself but also the low level disk I O layer must be reentrant Long file name The FatFs module has started to support long file name LFN at revision 0 07 The two different file names SFN and LEN of a file is transparent in the file functions except for f readdir function To enable LFN feature set USE LFN to 1 2 or 3 and add a Unicode code conversion function ff convert and ff wtoupper to the project The LFN feature requires a certain working buffer in addition The buffer size can be configured by MAX LFN corresponding to the available memory size The size of long file name will reach up to 255 characters so that the MAX LFN should be set to 255 for full featured LFN operation If the size of working buffer is insufficient for the given file name the file function fails with FR INVALID NAME When enabling the LFN feature with reentrant feature USE LFN must be set to 2 or 3 In this case the file function allocates the working buffer on the stack or heap The working buffer occupies MAX LFN 1 2 bytes When the LFN feature is enabled the module size will be increased depending on the selected code page Right table shows how many bytes increased when LFN feature
22. method to a file is only read mode The duplicated open in write mode to a file is always prohibited and open file must not be renamed deleted or the FAT structure on the volume can be collapsed The file sharing control can also be available when FS LOCK is set to 1 or greater The value specifies the number of files to manage simultaneously In this case if any open rename or remove that violates the file sharing rule that described above is attempted the file function will fail with FR LOCKED If the number of open files gets larger than FS LOCK the f open function will fail with FR TOO MANY OPEN FILES 2 4 2 Reentrancy The file operations to the different volumes are always reentrant and can work simultaneously The file operations to the same volume are not reentrant but it can also be configured to thread safe with FS REENTRANT option In this case also the OS dependent synchronization object control functions ff cre syncobj ff del syncobj ff req grant and ff rel grant must be added to the project When a file function is called while the volume is in use by any other task the file function is suspended until that task leaves file function If the wait time exceeded a period defined by TIMEOUT the file function will abort with FR TIMEOUT The timeout feature might not be supported on some RTOS DocID025800 Rev 1 11 26 FatFs File System UM1721 2 4 3 2 5 12 26 There is an exception on f_mount and f_m
23. o be written DocID025800 Rev 1 17 26 FatFs File System UM1721 18 26 DWORD sector Sector address LBA BYTE count Number of sectors to write 1 128 DRESULT res RES ERROR write your own code here to write sectors to the drive return res endif USE WRITE 1 if USE IOCTL DRESULT mynewdisk ioctl BYTE cmd Control code void buff Buffer to send receive control data DRESULT res RES ERROR write your own code here to control the drive specified features ka CTRL SYNC GET SECTOR SIZE GET SECTOR COUNT GET BLOCK SIZE return res endif USE IOCTL 1 Header Low level disk I O module A mynewdisk diskio h Header for Low level disk I O module un P x e Define LO prevent recursivo INCLUSION el ifndef MYNEWDISK DISKIO H define MYNEWDISK DISKIO H extern Diskio drvTypeDef mynewdisk Driver endif MYNEWDISK DISKIO H 2 DoclD025800 Rev 1 UM1721 3 3 1 3 FatFs applications FatFs applications In the STM32CubeF4 solution many applications are provided based on FatFs middleware The table below gives you insight on how the FatFs middleware component is used in different examples which are classified by complexity and depending on used physical drive interfaced uSD RAMDisk USBDisk Table 4 Examples of FatFs middleware utilization
24. other words the user can t hold an application using more than one instance of a logical drive What FAT sub types does FatFs support FatFs refers to all three major variants of Microsoft FAT sub types FAT12 FAT16 and FAT32 The FAT sub type is determined by number of clusters on the volume and nothing else according to the FAT specification issued by Microsoft Thus which FAT sub type is selected is depends on the volume size and the specified cluster size 2 DoclD025800 Rev 1 UM1721 Revision history 6 Revision history Table 5 Document revision history een anan 04 Mar 2014 Initial release DocID025800 Rev 1 25 26 3 UM1721 Please Read Carefully Information in this document is provided solely in connection with ST products STMicroelectronics NV and its subsidiaries ST reserve the right to make changes corrections modifications or improvements to this document and the products and services described herein at any time without notice All ST products are sold pursuant to ST s terms and conditions of sale Purchasers are solely responsible for the choice selection and use of the ST products and services described herein and ST assumes no liability whatsoever relating to the choice selection or use of the ST products and services described herein No license express or implied by estoppel or otherwise to any intellectual property rights is granted under this document If any part of this do
25. ples based on common FatFs provided APIs Please refer to the release notes of the STM32CubeF4 firmware package to know the version of FatFs firmware component used March 2014 DoclD025800 Rev 1 1 26 www st com Contents UM1721 Contents Acronyms and definitions gt 2coriasrrsa de 45440 bee ebe se Rd D Ex KNA 6 1 FAT File System overview ee 7 1 1 FAIT OVEINIOW usus bha ovv EE eI PEE d UPSSRSEEREEGCMUSRemrpeeS T 1 1 1 Master Boot Record 0 ccc eee 7 1 1 2 FAFpPAUONS o26 24000 daa eee MA a PAA GA eee DB ee oe es 8 1 1 3 FAT v1 Ae 8 2 FatFs File System leeren 10 2 1 FatFs overview umbrae hod qs ra ad 10 2 2 FatFs architecture ss wen cesdrecagem eux dbeues a 10 2 3 FatFs license n6cocebede edhe abba PANAMA ANG qc Won do d Red Re ed md d 11 2 4 FatFs features 0 ee eee eens 11 2 4 1 Duplicate file access elle 11 2 4 2 Reentrancy A 11 2 4 3 Long file name x 2424 occ cicer Ghd seen A es ed o 12 2 5 FARS APIS ass 550008 eh enone eer eeneese CEREREM RRESSS 12 2 6 FatFs low level APIs 2 llle 13 2 7 FatFs into STM32CubeF4 aa 14 2 1 1 FATFS LinkDriver eee 15 2 1 2 FATFS UnlinkDriver llle eee eee 15 2 7 3 FATFS GetAttachedDriverNbr 0 0 ee o 16 2 8 Interface your own disk to FatFS 0 00 eee ees 16 3 FatFs applications aci c8400080 65008 64444 e reer a 19
26. tem overview FAT overview The File Allocation Table FAT file system was developed by Bill Gates and Marc McDonald It is a format and some software which stores and organizes files on a storage device such as a disk drive or a memory device It is used to facilitate access to files and directories The FAT file system provides a way to time stamp when a file is created or changed and provides a way to identify the size of the file This system provides a mechanism to store other attributes of a file such as whether a file is read only whether the file should be hidden in a directory display or whether a file should be archived at the next disk backup The FAT file system is ideal for removable Flash media used in consumer electronic devices such as digital cameras media players and Flash drives The FAT file system can be helpful in the following scenarios e Due to the backward compatibility of the FAT file system users can employ memory stick media or floppy disks to transfer files between a consumer electronic device and a computer that uses an outdated operating system e The FAT file system lets users quickly remove files from electronic devices as in professional broadcast media e The file system versions FAT 16 or FAT32 may be suitable for a hard disk drive volume These versions would also be useful to a user who wants to boot a computer by using a floppy disk to access data typically system recovery tools on a

Download Pdf Manuals

image

Related Search

Related Contents

Trisa Electronics Easy Scale 4.0  Operating Instructions - Support  D.15 Disciplinare opere elettriche  Notice d'utilisation  TARGET2 user Manual v1.3 changes  AT-SPF30 取扱説明書  Code Corporation CR1400  

Copyright © All rights reserved.
Failed to retrieve file