Efsl file system migration record

Source: Internet
Author: User

The file system is used in the process of using the SD card. efsl is selected here, and corresponding transplantation and verification are performed.

Efsl is called embeded file system library. It is an open-source SD card file system that occupies less memory and is easy to transplant. It is suitable for single-chip microcomputer with small and medium capacity. Efsl is compatible with fat12/16/32 and supports multi-device and multi-file operations. For the driver of each device, you only need to provide two functions: Sector write and sector read.

The structure of efsl is

Its direct layered structure makes it very simple. When a file operation is executed, it calls the file system filesystem, and the file system calls the partition object partition, which has already become the relative address of the file allocation, then, the partition table is associated with the cache manager ioman through the disc object, and the underlying sector can be operated through the interface. What we need to do is to connect the file system to the underlying interface.

The underlying hardware includes three basic functions: 1. initialize the hardware. 2. Read a sector (512 bytes) from the SD card ). 3. Write a sector (512 bytes) to the SD card ). As long as these functions are implemented, the rest of efsl porting will be very simple.

1. Download the source code and add it to the Project

Download the efsldownload source code at http://efsl.be/( I don't know why I can't download it now). In order to facilitate management, create efsl_inc and efsl_src folders in the project and add the corresponding files, for example:

2. Add # define hw_endpoint_stm32f103rb_sd in config. h to add macro definitions related to your hardware.

3. Modify the data type based on the microcontroller type. Add a new definition to INC/types. h.

4. Add the SD card driver interface function declaration file to INC/interface. h,

# If defined (hw_endpoint_stm32f103rb_sd)
# Include "interfaces/stm32f103rb. H"

# Endif

The statement contains the basic data structure and three basic functions at the underlying hardware layer:

Struct hwinterface {
/* File * imagefile ;*/
Eint32 sectorcount;
};
Typedef struct 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 different single-chip microcomputer, you can copy this program and change the. h and. c file names. In this way, you can call the file stm32f103rb. C.

5. Modify the declaration function implementation 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 );
}
/*************************************** **************************************/

6. Configure efsl

By default, efsl can complete all work normally. After the SD card is formatted as FAT32, fat16, or fat12 on a PC, efsl can be automatically recognized without additional operations.

In addition, whether the inclusion path of the main files is correct can be compiled only after being set correctly.

7. Use

During use, you need to define data variables and initialize the file system before you can read and write files.

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.