EFSL File System Migration record

Source: Internet
Author: User

The use of the SD card in the process of using the file system, here selected EFSL, and did the appropriate porting and verification.

EFSL all called the embeded file system library, is an open source SD card file system, occupying less memory space, easy to transplant, suitable for small and medium-sized single-chip microcomputer. EFSL is compatible with FAT12/16/32 and supports multi-device and multi-file operation. For each device driver, you only need to provide sector write and sector read two functions.

The structure of the EFSL is

It has a direct hierarchical structure that makes it look very simple. When a file operation is performed, it calls the file system filesystem, the file system calls the partition object partition has finished allocating a single, relative address to the file, and then the partition table is associated with the cache manager IOMan through the disc object. It is possible to operate the underlying sector via an interface. What we need to do is to complete the docking of the filesystem with the underlying interface.

The hardware layer consists of three basic functions: 1. Initialize the hardware. 2, read a sector (512bytes) from SD card. 3. Write a sector (512bytes) to the SD card. As long as these functions are implemented, the rest of the work of porting EFSL will be very simple.

First, download the source code, join the project

Download the source code on the http://efsl.be/, (I do not know why not now download), in order to manage the project to facilitate the establishment of EFSL_INC and efsl_src two folders, add the corresponding files, such as:

Second, add a # define HW_ENDPOINT_STM32F103RB_SD to Config.h to add a macro definition that is related to your own hardware.

Third, modify the data type according to the type of MCU. Add a new definition to the Inc/types.h

Four, in inc/interface.h add SD card Driver interface function declaration file,

#if defined (HW_ENDPOINT_STM32F103RB_SD)
#include "Interfaces/stm32f103rb.h"

#endif

It contains a basic data structure and a declaration of the underlying three basic functions of the hardware:

struct hwinterface{
/*file *imagefile;*/
Eint32 Sectorcount;
};
typedef struct HWINTERFACE hwinterface;

extern esint8 If_initinterface (hwinterface* file,eint8* opts);
extern esint8 if_readbuf (hwinterface* file,euint32 address,euint8* buf);
extern esint8 if_writebuf (hwinterface* file,euint32 address,euint8* buf);
extern esint8 If_setpos (hwinterface* file,euint32 address);

When using a different microcontroller, you can copy the program to the past, change the. h and. C filenames so that you can call the STM32F103RB.C file.

Five, modify the specific implementation of declaring the function in STM32F103RB.h:

/*****************************************************************************/

Esint8 if_initinterface (hwinterface* file, eint8* opts)
{
Euint8 temp = 0;

temp = Sd_init ();//initialize the SD card
file->sectorcount=4;
if (temp = = 0)
return (0);
Else
Return (-1);
}
/*****************************************************************************/

Esint8 if_readbuf (hwinterface* file,euint32 address,euint8* buf)
{
Return (Sd_readsingleblock (address, buf));
}
/*****************************************************************************/

Esint8 if_writebuf (hwinterface* file,euint32 address,euint8* buf)
{
Return (Sd_writesingleblock (address, buf));
}
/*****************************************************************************/

Esint8 If_setpos (hwinterface* file,euint32 address)
{
return (0);
}
/*****************************************************************************/

Six, configure EFSL

EFSL the default settings to do all the work normally, the SD card on the PC format as FAT32, FAT16 or FAT12, EFSL can be automatically recognized, no need for additional action.

In addition, the main file contains the correct path, set correctly before you can compile the pass.

Seven, using

You need to define data variables, initialize the file system, and read and write files when you use them.

Embeddedfilesystem EFS;
Embeddedfile file;
Eint8 filename[15];

if (Efs_init (&efs,0)! = 0) {

return-1;

}

File_fopen (&file,&efs.myfs,filename, ' w '));

File_read (&file,3000,sdreadbuffer);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.