Home
AN10916 - Element14
Contents
1. This code should bring the hardware in a ready to use state Optionally but recommended the sectorCount filed in the structure hwlInterface should be filled in esint if initInterfaceijhwInterface file eint8 opts Kt if SD Init SD FALSE return 1 if SD ReadConfiguration SD FALSE return z file secrorcCount CardContig sectorent return 0 Fig 6 Implementation of if_initinterface If readBuf This function is used to read a sector from the disc and store it in a user supplied buffer Be very careful to respect the boundaries of the buffers since it will usually be lOMan calling this function If there is a buffer overflow corruption of the cache of the next buffer may occur which in turn may produce extremely rare and impossible to retrace behavior All information provided in this document is subject to legal disclaimers NXP B V 2011 All rights reserved Application note Rev 3 1 May 2011 7 of 21 NXP Semiconductors AN1 091 6 FAT library EFSL and FatFs port on NXP LPC1700 esinta if readBufihwInterface file euint3z address euint5o hut t if SD PeadSector address buf 1 SD TRUE return CU else return i 1 j Fig 7 Implementation of if readBuf The address is a LBA address relative to the beginning of the disc If accessing an old hard disc or a device which uses some other form of addressing to the address it will have
2. Edit Setup Control Window Help o iui 10240000 bytes written with 1146 kB sec fw 10240000 2 10240000 bytes written with 1154 kB sec c rc U FR Dk fo 14 10240000 bytes read with 1729 kB sec sfr 10240000 10240000 bytes read with 1732 kB sec 2t 2010 171 00 05 54 h Fig 22 File read and write speed test output AN10916 All information provided in this document is subject to legal disclaimers NXP B V 2011 All rights reserved Application note Rev 3 1 May 2011 18 of 21 NXP Semiconductors AN1 091 6 FAT library EFSL and FatFs port on NXP LPC1700 5 References 1 NXP LPC17xx User Manual UM10360 Rev 2 NXP Semiconductors Aug 18 2010 2 Embedded Filesystems Library EFSL Lennart Yseboodt amp Michael De Nil http efsl be 3 FatFs Generic FAT File System Chan http elm chan org fsw ff OO0index e html 4 Embedded Filesystem Library for ARM controllers with interfaces for LPC2000 SPI and AT91SAM7S SPI Martin THOMAS http www siwawi arubi uni kl de avr projects arm projects arm memcards index htmlztefsl arm 5 ChaN s FAT Module with LPC17xx SPI SSP and USB MSD Martin THOMAS http www siwawi arubi uni kl de avr projects arm projects arm memcards index htmlzzchanfat lpc cm3 AN10916 All information provided in this document is subject to legal disclaimers NXP B V 2011 All rights reserved Application note Rev 3 1 May 2011 19 of 21 NXP
3. Semiconductors AN10916 6 Legal information 6 1 Definitions Draft The document is a draft version only The content is still under internal review and subject to formal approval which may result in modifications or additions NXP Semiconductors does not give any representations or warranties as to the accuracy or completeness of information included herein and shall have no liability for the consequences of use of such information 6 2 Disclaimers Limited warranty and liability Information in this document is believed to be accurate and reliable However NXP Semiconductors does not give any representations or warranties expressed or implied as to the accuracy or completeness of such information and shall have no liability for the consequences of use of such information In no event shall NXP Semiconductors be liable for any indirect incidental punitive special or consequential damages including without limitation lost profits lost savings business interruption costs related to the removal or replacement of any products or rework charges whether or not such damages are based on tort including negligence warranty breach of contract or any other legal theory Notwithstanding any damages that customer might incur for any reason whatsoever NXP Semiconductors aggregate and cumulative liability towards customer for the products described herein shall be limited in accordance with the Terms and conditions of
4. commercial sale of NXP Semiconductors Right to make changes NXP Semiconductors reserves the right to make changes to information published in this document including without limitation specifications and product descriptions at any time and without notice This document supersedes and replaces all information supplied prior to the publication hereof Suitability for use NXP Semiconductors products are not designed authorized or warranted to be suitable for use in life support life critical or safety critical systems or equipment nor in applications where failure or malfunction of an NXP Semiconductors product can reasonably be expected to result in personal injury death or severe property or environmental damage NXP Semiconductors accepts no liability for inclusion and or use of NXP Semiconductors products in such equipment or applications and therefore such inclusion and or use is at the customer s own risk Applications Applications that are described herein for any of these products are for illustrative purposes only NXP Semiconductors makes no representation or warranty that such applications will be suitable for the specified use without further testing or modification Customers are responsible for the design and operation of their applications and products using NXP Semiconductors products and NXP Semiconductors accepts no liability for any assistance with applications or AN10916 All information provided in th
5. for loss of business business interruption loss of use loss of data or information and the like arising out the use of or inability to use the product whether or not based on tort including negligence strict liability breach of contract breach of warranty or any other theory even if advised of the possibility of such damages Notwithstanding any damages that customer might incur for any reason whatsoever including without limitation all damages referenced above and all direct or general damages the entire liability of NXP Semiconductors its affiliates and their suppliers and customer s exclusive remedy for all of the foregoing shall be limited to actual damages incurred by customer based on reasonable reliance up to the greater of the amount actually paid by customer for the product or five dollars US 5 00 The foregoing limitations exclusions and disclaimers shall apply to the maximum extent permitted by applicable law even if any remedy fails of its essential purpose 6 3 Trademarks Notice All referenced brands product names service names and trademarks are property of their respective owners NXP B V 2011 All rights reserved Application note Rev 3 1 May 2011 20 of 21 NXP Semiconductors AN10916 2 1 2 2 2 3 3 1 3 2 3 2 1 3 2 2 3 2 3 3 2 4 3 2 5 3 3 3 3 1 3 3 2 3 3 3 3 3 4 3 4 4 1 4 2 4 3 4 3 1 4 3 2 4 4 1 4 4 2 4 4 3 4 4 4 4 4 5 4 4 6 4 5 5 6 1 6 2
6. the drive into the DWORD variable pointed by Buffer This command is used in only f mkfs function GET BLOCK SIZE Returns erase block size of the memory array in unit of sector into the DWORD variable pointed by Buffer This command is used in only f mkfs function Device dependent MMC GET TYPE Get card type flags 1 byte MMC GET CSD Receive CSD as a data block 16 bytes MMC GET CID Receive CID as a data block 16 bytes MMC GET OCR Receive OCR as an R3 response 4 bytes MMC GET SDSTAT Receive SD status as a data block 64 bytes Please refer to the software example for the detailed implementation of these functions All information provided in this document is subject to legal disclaimers NXP B V 2011 All rights reserved Application note Rev 3 1 May 2011 15 of 21 NXP Semiconductors AN1 091 6 AN10916 FAT library EFSL and FatFs port on NXP LPC1700 4 4 6 get fattime The get_fattime function gets current time which is not required in read only configuration ri E E EN E EE E E E E User Provided RTC Function for FatFs module it ee eee This is a real time clock service to be called from FatFs module Any valid time must be returned even if the system does not support an RTC wf This function is not required in read only cfg DWORD get fattime i RTCTime rtc Get local time rtc gettime amp rtc Pac
7. to be recalculated based on the chosen addressing scheme Please note that there is no support for sectors that are not 512 bytes in size 3 3 4 If writeBuf The function works exactly the same as its reading variant esinto if readBufihwInterface file euint3z address euinto buf Ik if SD ReadSector address but 1 SD TRUE return CU else return 1 Fig 8 Implementation of if_writeBuf 3 4 Demo Create a Keil uVision4 project and add all related source files Main c is the test file It will list all files in the root directory write and read specified length of data from to a file The R W speed will also be calculated This demo is tested on the KEIL MCB1700 evaluation board For more information about MCB1700 please refer to http www keil com mcb1700 Tera Term or a similar tool is used for serial communication between PC terminal and MCB1700 and configured at 115200 baud 8 bits no parity 1 stop bit XON XOFF 2 4 8 GB SanDisk Micro SD SDHC cards are used for the test AN10916 All information provided in this document is subject to legal disclaimers NXP B V 2011 All rights reserved Application note Rev 3 1 May 2011 8 of 21 NXP Semiconductors AN10916 AN10916 FAT library EFSL and FatFs port on NXP LPC1700 3 MCB1700 RAM Eq LPC1700 MET startup LPCT17xx s t system LPCI7xx c iF Ipci7xx c Ipci xx spi c amp Ipcizxx sd c
8. transfer Function and Buffer Configurations _FS_TINY 0 define FS READONLY 0 Enable both read and write functions define FS MINIMIZE 0 Enable full function define USE STRFUNCO Disable string functions define USE MKFS 1 Enable f mkfs function define USE FORWARD 0 Disable f forward function Locale and define CODE PAGE 850 OEM code page Multilingual Latin 1 Namespace will be used on the target system Configurations define USE LFN 1 Enable LFN define MAX LFN 255 Maximum LFN length to handle define LFN UNICODE 0 Disable Unicode define FS RPATH 1 Enable the relative path feature and f chdir and f_chdrive function are available Physical Drive Configurations define DRIVES 1 Only 1 physical driver is allowed define MAX SS 512 Maximum sector size to be handled define MULTI PARTITION O A Each volume is bound to the same physical drive number and can mount only first primary partition System Configurations define WORD ACCESS 0 Enable the Byte by byte access define FS REENTRANT 0 Disable reentrancy USE LFN The FatFs module supports Long File Name LFN in revision 0 07e The two different file names SFN and LFN of a file are transparent in the file functions except for f readdir function To enable LFN feature set USE LFN to 1 or 2 and add a Unicode code conversion function ff convert and ff wtoupper to the p
9. written with 257 kB sec File read test pen file efzltsti txt OK Heading 4184304 bytes 4184304 bytes read with 1007 kB sec EFSL test complete Fig 11 COM output Remark since EFSL does not support long file name LFN file efsllfntst txt is displayed as efsllf 2 txt AN10916 All information provided in this document is subject to legal disclaimers NXP B V 2011 All rights reserved Application note Rev 3 1 May 2011 10 of 21 NXP Semiconductors AN10916 FAT library EFSL and FatFs port on NXP LPC1700 4 FatFs port on LPC1700 4 1 FatFs structure 4 2 AN10916 The FatFs structure is shown below Application Low level disk I O SD ATA USB NAND Fig 12 FatFs structure 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 in compliance with ANSI C Low level disk I O module is used to read write the physical disk An RTC module is used to get the current time The Low level disk I O and 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 The rest of this section will describe step by step how to port FatFs revision 0 08a to LPC1700 Define the size of integer types The
10. 1 Compiler armcc V4 0 0 Optimization O3 4 4 Implement low level functions 4 4 1 Since the FatFs module is completely separated from disk I O and RTC module it requires the following functions to read write the physical disk and to get the current time Because the low level disk I O and RTC module are not a part of the FatFs module they must be provided by the user disk initialize The disk initialize function initializes a physical drive This function is called from the volume mount process in the FatFs module to manage the media change The application program must not call this function while the FatFs module is active as this may cause the FAT structure on the volume to collapse To re initialize the file system use f mount function Sc e m n e o etg nm DSTATUS disk initialize BYTE drv Physical drive number 0 m if drv return STA NOINIT Supports only single drive ff aif Stat amp STA NODISK return Stat No card in the socket if SD Init amp amp SD ReadConfiguration Stat amp ST NOINIT return Stat Fig 14 Implementation of disk initialize All information provided in this document is subject to legal disclaimers NXP B V 2011 All rights reserved Application note Rev 3 1 May 2011 13 of 21 NXP Semiconductors AN1 091 6 FAT library EFSL and FatFs port on NXP LPC1700 4 4 2 disk status The disk status function return
11. 53 55 30 34 47 80 00 84 O7 2F 00 2B 05 SDSUD4G 7 9 OCR OOO00000 CO FF 80 00 So Status OOOO0000 QU OO OO OO 00 DO OO OO 00 OO DO OO OO OU 00 OO OOOO00TN d DO OO OO 00 00 OO OO 00 OO DO OO OO OU Q DU OOOO0020 OU 00 OO OO 00 00 OO OO OU OO DO OO OO OU 00 OO o OO 00 00 OO DO DO OO OO OO OO OO OU OO DO OO OO File Edit Setup Control Window Help DIR start lba clustor 2 Data start lba 16984 Fc hb FR_NOGLPATH 1980 00 00 00 136 EFSLTST1 TXT 1980 00 00 00 1048576 FILEUZ TXT A 2010 01 01 00 10240000 8 2010 01 01 00 o120000 7 1980 00 00 00 4134304 TESTIS TAT 1960 00 00 00 4134304 TESTUA TRT 1380 00 00 00 4134304 TESTS TAT 1980 00 00 00 amp aneb S TESTOR TAT 1980 00 00 00 12582312 TESTO Z TET 2010 11 12 17 1123743 1 mp3 2010 11 10 15 43 eae ae A 2010 07 30 11 328 20100F 1 THT 20100730 meeting minute 2005 10 01 15 4415785 2 wma 4 2008 05 31 10327325 D 2010 12 13 16 14 File s 66437074 bytes total Diriz 9281223680 bytes free Fig 21 File commands fi fs fl test output txt AN10916 All information provided in this document is subject to legal disclaimers NXP B V 2011 All rights reserved Application note Rev 3 1 May 2011 17 of 21 NXP Semiconductors AN1 091 6 FAT library EFSL and FatFs port on NXP LPC1700 W Tera Term COM1 VT File
12. 6 HGIOrGne CS unncaiicniei ix CUu Rice QVE EE Legi Fred eR 19 Legal information 20 DEMONS RERO RE 20 DISOlaltTie S cseosmdore Pales cse dub sida TAa ES wERA pL ADI Fe vu 20 Tadom TT 20 CONTENTS sah PD 21 FAT library EFSL and FatFs port on NXP LPC1700 Please be aware that important notices concerning this document and the product s described herein have been included in the section Legal information NXP B V 2011 All rights reserved For more information please visit http www nxp com For sales office addresses please send an please send an email to salesaddresses nxp com Date of release 1 May 2011 Document identifier AN10916
13. 6 3 Contents HEUTE O GUC TION m reteset es 3 EFSL and FatFs introduction 3 lee dgiuMe e 3 ADOUEEI S Dene nee ee eee er ene tiu 3 About FatF Sesars 4 EFSL port on LPC1700 4 POL SUUCIUNS Sosscc cshscctcdcneccdesaotesiaccneeedetebteciaccs 4 Setup basic framework sssesee 5 Define a name for the endpoint 5 Define the sizes of integer types 5 Add an endpoint to interface 5 Configure EFSL cccccceseccceceeseeesseeeeeeeeeeeeees 6 Create source files eeeeeseeeeesssees 7 Implement low level functions 7 A di iare 7 If initlnterface cseeeseeeen 7 R22 0 10 RR 7 M WEBU essiensa a i 8 DE a T 8 FatFs port on LPC1700 11 GUIS SWUCUING E 11 Define the size of integer types 11 Configure the FatFs module 12 B SEIS 12 CODE PAQE spur ERR S ree CE 13 Implement low level functions 13 disk initialize eeeeenn 13 disk status eseeseeenm en 14 e E OA RR PRA 14 disk Write iei ensi Denssdus ase ian cesis veteri uti eniai 14 diok IOCU MR RERO 15 get_fattime Pe 16 B qu POTRETE 1
14. AN10916 FAT library EFSL and FatFs port on NXP LPC1700 Rev 3 1 May 2011 Application note Document information Info Content Keywords LPC1700 Cortex M3 File system EFSL FatFs SDHC Abstract EFSL and FatFs are two widely used FAT libraries for developing small embedded systems This application note describes how to port these two FAT libraries to NXP Cortex M3 LPC1700 devices External SDC MMC connected to LPC1700 SPI SSPO will be used as physical disk SDHC is also supported NXP Semiconductors AN10916 Revision history FAT library EFSL and FatFs port on NXP LPC1700 Rev Date Description 3 20110501 2 20100706 1 20100304 Removed section Access SDC MMC via SPI on LPC1700 since it is described in AN11070 Modified some test results since FatFs was updated from 0 07e to 0 08a and added support for SDHC Added text and applicable licenses and or copyrights to sentence regarding URLs for FAT EFSL and FatFs Initial version Contact information For additional information please visit http www nxp com For sales office addresses please send an email to salesaddresses nxp com AN10916 All information provided in this document is subject to legal disclaimers NXP B V 2011 All rights reserved Application note Rev 3 1 May 2011 2 of 21 NXP Semiconductors AN1 091 6 FAT library EFSL and FatFs port on NXP LPC1700 1 Introduction EFSL and Fat
15. FatFs module assumes that the size of char short long are 8 16 32 bit and int is 16 bit or 32 bit These correspondences are defined in integer h This will not be a problem on most compilers Any conflict with existing definitions must be resolved carefully These types must be 16 bit 32 bit or larger integer typedef int INT tvpedef unsigned int UINT These types must be 8 bit integer typedef signed char CHAR tvpedef unsigned char UCHAR typedef unsigned char BYTE These types must be 16 bit integer tvpedef short SHORT typedef unsigned short USHORT tvpedef unsigned short WORD typedef unsigned short WCHAR These types must be 32 bit integer tvpedef long LONG tvpedef unsigned long ULONG tvpedef unsigned long DWORD Fig 13 Integer types definitions for FatFs module All information provided in this document is subject to legal disclaimers NXP B V 2011 All rights reserved Application note Rev 3 1 May 2011 11 of 21 NXP Semiconductors AN10916 AN10916 FAT library EFSL and FatFs port on NXP LPC1700 4 3 Configure the FatFs module 4 3 1 All of the configurations and detailed descriptions can be found in ffconf h for FatFs revision 0 08a The configurations used in this project are listed below Table 2 Item Configurations of FatFs module in this project Configuration Description define Use the sector buffer in the individual file data
16. Fs are two widely used FAT libraries for developing small embedded system nowadays This application note describes how to port these two FAT libraries to NXP Cortex M3 LPC1700 devices A set of easy to use SPI and SDC MMC API functions is also provided to access SDC MMC conveniently as a physical disk This application note describes how to port EFSL and FatFs to LPC1700 in a step by step manner The sample software is tested on Keil s MCB1700 evaluation board LPC1768 with 2 4 8 GB SanDisk Micro SDC SDHC cards 2 EFSL and FatFs introduction AN10916 2 1 2 2 About FAT The FAT File Allocation Table also known as FAT12 FAT16 and FAT32 file system was developed by Bill Gates and Marc McDonald It is the primary file system architecture now widely used on most operating systems and memory cards FAT was created for managing disks efficiently The name originates from the usage of a table which centralizes the information about which areas belong to files are free or possibly unusable and where each file is stored on the disk To limit the size of the table disk space is allocated to files in contiguous groups of hardware sectors called clusters As disk drives have evolved the maximum number of clusters has dramatically increased and so the number of bits used to identify each cluster has grown The successive major versions of the FAT format are named after the number of table element bits 12 16 and 32 The FAT standard
17. NDPOINT DSP Tie 13 SD H include interfaces dape 7xx h elif definediHW ENDPOINT LPezoo0 SP Herror NO INTERFACE DEFINED see interface h 3 2 4 Configure EFSL The configuration file efsl conf contig h defines the behavior of the library In the configuration files there are many settings most of which default to safe or standard compliant settings The configurations used in this project are listed below Table 1 Configurations of EFSL in this project Item Configuration Hardware target define HW ENDPOINT LPC17xx SD Description Access SDC MMC via LPC17xx SSPO Memory define BYTE ALIGNMENT Specify that the MCU can not access memory byte oriented Cache define IOMAN NUMBUFFER 6 6x512byte 3kB RAM used for define IOMAN NUMITERATIONS 3 cache define IOMAN DO MEMALLOC Cluster pre define CLUSTER PREALLOC FILE2 The number of clusters pre allocation define allocated when writing files CLUSTER PREALLOC DIRECTORY 0 Endianess define LITTLE ENDIAN All FAT structures are stored in intel little endian order Date and Time support define DATE TIME SUPPORT Disable date and time support Error reporting define FULL ERROR SUPPORT Enable error recording for all support object List options define LIST MAXLENFILENAME 12 Configure what kind of data returned from directory listing requests Debugging define DEBUG Disable debugging behavior 1 Being commen
18. has also been expanded in other ways while preserving backward compatibility with existing software For more information about FAT and applicable licenses and or copyrights please go to http www microsoft com whdc system plattorm firmware fatgen mspx About EFSL The Embedded File Systems Library EFSL project aims to create a library for file systems to be used on various embedded systems Currently EFSL supports the Microsoft FAT file system family It is EFSL s intent to create pure ANSI C code that compiles on anything that bears the name C compiler Adding code for specific hardware is straightforward just add code that fetches or writes a 512 byte sector and the library will do the rest For example it supports secure digital cards in SPI mode This project is released under the regular Public License with an exception clause This clause states that users are allowed to statically link against the library without having to license proprietary code as GPL as well For more information about EFSL please refer to http efsl be All information provided in this document is subject to legal disclaimers NXP B V 2011 All rights reserved Application note Rev 3 1 May 2011 3 of 21 NXP Semiconductors AN1 091 6 FAT library EFSL and FatFs port on NXP LPC1700 2 3 About FatFs FatFs is a generic FAT file system module for small embedded systems The FatFs is written in compliance with ANSI C and co
19. is document is subject to legal disclaimers FAT library EFSL and FatFs port on NXP LPC1700 customer product design It is customer s sole responsibility to determine whether the NXP Semiconductors product is suitable and fit for the customer s applications and products planned as well as for the planned application and use of customer s third party customer s Customers should provide appropriate design and operating safeguards to minimize the risks associated with their applications and products NXP Semiconductors does not accept any liability related to any default damage costs or problem which is based on any weakness or default in the customer s applications or products or the application or use by customer s third party customer s Customer is responsible for doing all necessary testing for the customer s applications and products using NXP Semiconductors products in order to avoid a default of the applications and the products or of the application or use by customer s third party customer s NXP does not accept any liability in this respect Export control This document as well as the item s described herein may be subject to export control regulations Export might require a prior authorization from national authorities In no event shall NXP Semiconductors its affiliates or their suppliers be liable to customer for any special indirect consequential punitive or incidental damages including without limitation damages
20. k date and time into a DWORD variable return DWORD rtc RTC Year 1980 lt lt 25 DUVORD rtc RTC Mon lt lt 21 DWORD rtc RTC Mday lt lt 16 DUVORD rtc RTC Hour lt lt 11 DWORD rtc RTC Min lt lt 5 DWORD rtc RTC Sec gt gt 1 Fig 18 Implementation of get fattime 4 Demo This demo was also tested on Keil s MCB1700 evaluation board with the same 2 4 8 GB SanDisk Micro SD SDHC cards and COM configuration MCB1768 Flash Fy LPC17D0 startup LPC17xx s system LPCI7 xx c Ipc17xx uart c Ipci7xx rkc c Ipci7xx spi c 3 ed c 24 FatFs FF or A ccsbcs c E1423 Main AEA main c DAEA monitor c E Documentation BE Fig 19 Source files of the project All information provided in this document is subject to legal disclaimers NXP B V 2011 All rights reserved Application note Rev 3 1 May 2011 16 of 21 NXP Semiconductors AN10916 FAT library EFSL and FatFs port on NXP LPC1700 Below is the COM output 2 Tera Term COM1 VT File Edit Setup Control Window Help FatFs module test monitor far LPCi xx 15 11 13 Dec 14 2010 LFN Enabled Code page 850 2di rc l rds Drive size 7744512 sectors sector size 612 Erase block 8132 sectors Card type 4 CSD OO000000 40 QE 00 32 5B 59 00 DU 1D 84 7F 80 O4 40 40 BS B 2 Y B CID OO000000 03 53 44
21. mpletely separated from the disk I O layer Therefore it is independent of hardware architecture It can be incorporated into low cost microcontrollers such as AVH 8051 PIC ARM Z80 etc without any change The FatFs has the following features e Windows compatible FAT12 16 32 file system e Platform independent Easy to port e Very small footprint for code and work area e Various configuration options Multiple volumes physical drives and partitions Multiple OEM code pages including DBCS Long file name LFN support in OEM code or Unicode RTOS support Multiple sector size support Read only minimized API I O buffer and etc The FatFs module is free software opened for education research and development It is ok to modify and or redistribute it for personal non profit use or commercial products without any restriction For more information about FatFs please refer to http elm chan org fsw ff OOindex e html 3 EFSL port on LPC1700 AN10916 3 1 EFSL structure The EFSL internal structure is shown below Fig 1 EFSL structure EFSL has created a linear object model that is quite simple The Filesystem object deals with handling the file system specific stuff The Partition object is responsible for translating partition relative addressing into disc based LBA addressing The Disc object holds the partition table and has a direct link to a cache manager lOMan In JOMan all re
22. quests for disc sectors come together lOMan will perform checks to see if sectors have to be read from disc or from memory or written back to disc In the latter case reading or writing to disc a request is made to the hardware layer The hardware interface has three responsibilities 1 Initialize the hardware 2 Read sectors from disc 3 Write sectors to disc All information provided in this document is subject to legal disclaimers NXP B V 2011 All rights reserved Application note Rev 3 1 May 2011 4 of 21 NXP Semiconductors AN10916 FAT library EFSL and FatFs port on NXP LPC1700 All requests are sector based A sector is a 512 byte piece from the disc which is aligned to a 512 byte boundary EFSL port on LPC1700 is rather straightforward just adding code that fetches or writes a 512 byte sector and the library will do the rest The rest of this section will describe step by step how to port EFSL revision 0 2 8 to LPC1700 3 2 Setup basic framework 3 2 1 Define a name for the endpoint The endpoint name is needed to create the required defines in the source code In this project the name is HW ENDPOINT LPC17xx SD which is defined in config h device gi Fig 2 Name definition for LPC17xx Here you will define for what hardware endpoint EFSL should be compiled Look in interfaces h to see what systems are supported and add your own there if you need to write your own dri
23. roject This function is available in option cc c Note that the LFN feature on the FAT file system is a patent of Microsoft Corporation When enabled on commercial products a license from Microsoft may be required depending on the final destination All information provided in this document is subject to legal disclaimers NXP B V 2011 All rights reserved Application note Rev 3 1 May 2011 12 of 21 NXP Semiconductors AN10916 AN10916 FAT library EFSL and FatFs port on NXP LPC1700 4 3 2 CODE PAGE The CODE PAGE specifies the OEM code page to be used on the target system Incorrect setting of the code page can cause a file open failure When the LFN feature is enabled the module size will be increased depending on the selected code page Table 3 shows the difference in module size when LFN is enabled with some code pages The Chinese and Korean language have tens of thousands of characters and require a huge OEM Unicode bidirectional conversion table therefore the module size will be drastically increased as shown in Table 3 As a result the FatFs with LFN will not be able to be implemented in some microcontrollers with limited ROM size Table 3 ROM size increase for different code pages on Cortex M3 Code page ROM size increase byte SBSC 2796 CP932 Japanese Shift JIS 61656 CP936 Simplified Chinese GBK 176856 CP949 Korean 138912 CP950 Traditional Chinese Big5 110544
24. s the current disk status which is a combination of the following flags e STA NOINIT Indicates that the disk drive has not been initialized e STA NODISK Indicates that no medium is in the drive e STA PROTECTED Indicates that the medium is write protected Since the MCB1700 board does not provide card detection and write protection we will neglect these two flags STA NODISK and STA PROTECTED lI c a a Get Disk Status rr M c M DSTATUS disk status BYTE drv Physical drive number 0 i if drv return STA NOINIT Supports only single drive return Stat Fig 15 Implementation of disk status 4 4 3 disk read The disk read function reads one or more sectors from the disk drive DRESULT disk read BYTE drv Physical drive number 0 BYTE huff Pointer to the data buffer to store read data DWORD sector Start sector number LB BYTE caunt Sector count 11 4255 i if idrv count return RES PARERR if stat amp STA NOINIT return RES NOTRDY it SD Readsector sector buff count SD TRUE return RES OF else return RES ERROR Fig 16 Implementation of disk_read 4 4 4 disk write The disk write writes one or more sectors to the disk This function is not required in read only configuration AN10916 All information provided in this documen
25. t Ipci7xx uart c ERSE ls c E mkfs c t partition c amp plibe c A time c 2 ui c 2 debug c amp dir c disc c efs c a extract c a Fat c 3 File c a s c 4 ioman c Bey Main f monitor c EE Documentation Fig 9 Source files of the project Below is the file structure in root directory of a 4 GB Micro SDHC card File Folder C efaldirz File Folder efsllfntst Ext ORB Text Document efsltst1 txt ORB Text Document B efslEsE2 Ext ORB Text Document Fig 10 Files on root directory Below is the COM output of the demo with the 4 GB Micro SDHC card All information provided in this document is subject to legal disclaimers NXP B V 2011 All rights reserved Application note Rev 3 1 May 2011 9 of 21 NXP Semiconductors AN1 091 6 FAT library EFSL and FatFs port on NXP LPC1700 Gi Tera Term COM1 VT File Edit Setup Control Window Help HHCY SD Card Filesystem Test P LPC1 68 L EFSL CARD init ok Card type Version 2 0 or later Hizh eXtended Capacity SD card sector size 612 bytes sector count 7744517 Block size 81372 sectors Card capacity 378 MByte Directory of root EFSLDIRI Uxl bytes EFSLDIR x bytes EFSLTSTITAT Ox0 bytes EFSLTSTZTAT Oxll bytes EFSLLF 2TXT 0x0 bytes File write test pen file efzltsti txt OK Writing 4134304 bytes 4184304 bytes
26. t is subject to legal disclaimers NXP B V 2011 All rights reserved Application note Rev 3 1 May 2011 14 of 21 NXP Semiconductors AN10916 AN10916 FAT library EFSL and FatFs port on NXP LPC1700 else 8 if READONLY DRESULT disk write BYTE drv Physical drive number 0 const BYTE huff Pointer to the data to be written DWORD sector Start sector number LB BYTE count j Bector count DIl 255 7 ia if dry count return RES PARERE if Stat amp STA NOINIT return RES NOTRDY py 22 atat amp STA PROTECT return RES NWEPRII if SD Writesector sector buff count sD TRUE return RES OE return RES ERROR endit READONLY 0 77 Fig 17 Implementation of disk_write 4 4 5 disk ioctl The disk ioctl function controls device specified features and miscellaneous functions other than disk read write Table 4 Supported commands in disk ioctl functions Command Device independent Description CTRL SYNC Ensures that the disk drive has finished pending write process When the disk I O module has a write back cache flush the dirty sector immediately This command is not required in read only configuration GET SECTOR SIZE Returns sector size of the drive into the WORD variable pointed by Buffer This command is not required in single sector size configuration MAX SSis 512 GET SECTOR COUNT Returns total sectors on
27. ted out means the macro is not defined AN10916 All information provided in this document is subject to legal disclaimers NXP B V 2011 All rights reserved Application note Rev 3 1 May 2011 6 of 21 NXP Semiconductors AN1 091 6 AN10916 3 2 5 3 3 3 3 1 3 3 2 3 3 3 FAT library EFSL and FatFs port on NXP LPC1700 Create source files Create header files in inc interfaces and source files in src interfaces In this project the fileslpc17xx spi h lpc17xx sd h Ipc17xx spi c and lpc17xx sd c are used Lpc17xx spi c h includes APIs to communicate via SSPO on the LPC1700 Lpc17xx sd c h includes APIs to access SDC MMC via SSPO on the LPC1700 Implement low level functions hwinterface This structure represents the underlying hardware There are some fields that are required to be present because EFSL uses them As always in embedded design it is recommended to keep this structure as small as possible KONCRCECKCh Ck KOH Ch kCH Hh Ch CK HC Ch KOH Ck KCKCh Ck Ch hCh Ck KCh Ch EE EERE EAE EEA Ch h Ck KCh h kCh ch h ck hh AEE kW hwlInterface long sector ount Number GE se tors Un the file K O a a a a a a a a a AEE e a a EERE AAA EEE e a hc h ch ck a a 6 struct hwInterfacei euint3z SectorCount te typedef struct hwinterface hwInterface Fig 5 Definition of structure hwinterface If initlnterface This function will be called one time when the hardware object is initialized by efs init
28. ver Then define the name you selected for your hardware there here Make sure that you only select one define HW ENDPOINT LINUX Hdefine HW ENDPOINT ATMEGA128 SD define HW ENDPOINT LPCZODO0 SD defines the interface for LPC213x O SPIO 1 SPI1 define HW ENDPOINT LPCZOO0 SPINUM 0 Hdefine HW ENDPOINT LPC2000 SPINUM 1 define HW ENDPOINT DSP TI6713 SD define the interface for LPC17xx SSPO define HW ENDPOINT LPC1 xx SD 3 2 2 Define the sizes of integer types Open inc types h and create a new entry typedef typedef typedef typedef typedef typedef typedef typedef typedef char eint signed char ezsinta unsigned char euint short inti signed short esinti unsigned short e amp euintisb5 int eint3z signed int ezsint32 unsigned int euint3z Fig 3 Integer types definitions for EFSL 3 2 3 Add an endpoint to interface h Add the new entry in inc interface h AN10916 All information provided in this document is subject to legal disclaimers NXP B V 2011 All rights reserved Application note Rev 3 1 May 2011 5 of 21 NXP Semiconductors AN10916 FAT library EFSL and FatFs port on NXP LPC1700 fendif Fig 4 Add endpoint in interface h if definediHW ENDPOINT LINUX defined HW ENDPOINT LINUs 64 Hinclude interfaces linuxfile h elitf definediHW ENDPOINT ATMEGALZS SD Hinclude interfaces atmegalz3 h Selif defined HW E
Download Pdf Manuals
Related Search
Related Contents
F305 Manual do usuário Epson 811P Projector User Manual Netopia 3347-02 Network Router User Manual SteppIR Antennas Viewsonic 30" LCD TV 30" Dining Room Service Outline 弟施工説明書 Giovanna Rosa Identità di una metropoli La letteratura Manual de Instrucciones Registrador de Copyright © All rights reserved.
Failed to retrieve file