MCU-based file system implementation

Source: Internet
Author: User

First, I declare that I only implement some of the functions, and none of the functions that are not mentioned are implemented by default.

Achieve: Get SD information, get the total partition information, get the information of a partition, read the FAT partition table function.

The function is used to list all files in the root directory, find whether a file exists, display the content of a file, and delete a file.

Only operations in the root directory are allowed, and the file name format must be 8.3.

As required by the instructor, the content of all files cannot be listed. The header files are listed for your reference.

/*************************************** * ********************* Underlying SD card driver **~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~ ** File name: SD. H * dependency: none * processor: c8051f410 * Compiler: Keil 3 * Unit: Ningxia University ** history: * <author> <time> <version> <description> * Li juqiang 2011/11/11 V1.0: Create the original document ******************* **************************************** * ** program copyright notice ** this program is a free program, you can freely use it for personal or commercial activities. * Program code can be published, but no fees are charged and cannot be modified. ** The copyright of this program belongs to Li juqiang of Ningxia University. ** In accordance with the practice, free software will not be liable for any losses caused by the use of the software. Please be careful! ** For more information, visit my blog: http://blog.csdn.net/lineter?*the ultimate Interpretation Right of this program is Li juqiang. **************************************** * ******************/# Ifndef sd_h # define sd_h # include ".. \ include \ complier. H "# include ".. \ include \ typedefs. H "# include ".. \ include \ SPI. H "typedef Enum // sd_errorlist {sd_reset_ OK = 0x00, // SD card restart successful sd_reset_timeout = 0x01, // SD card restart timeout (possibly no card) sd_active_timeout = 0x02, // SD card initialization failed sd_no_spi = 0x03, // SD card does not support SPI mode (greater than 2g) sd_write_block_error = 0x04, // cannot be set to write Block Mode sd_write_block_timeout = 0x05, // set block write timeout sd_write_not_accept = 0x06, // block write does not accept sd_write_save_timeout = 0x07, // block write save timeout sd_write_block_ OK = 0x08, // block write success sd_read_block_timeout = 0x09, // set block read timeout sd_read_respond_timeout = 0x0a, // block read response timeout sd_read_block_ OK = 0x0b, // block read success = 0x0c, // set read CID timeout sd_cid_not_respond = 0x0d, // read CID not responding sd_get_cid_ OK = 0x0e, // CID read success sd_get_csd_timeout = 0x0f, // set the CSD read timeout sd_csd_not_respond = 0x10, // read CSD not responding sd_get_csd_ OK = 0x11, // sd_other_error = 0xfe, sd_timeout_error = 0xff} sd_errorlist; typedef Enum // commandlist {sd_cammand = 0x40, // sd_reset = 0x00, // SD card restart: 0 sd_recognition = 0x37, // SD card recognition: 55 sd_active = 0x01, // SD card activation: 1 sd_write_block = 0x18, // SD card write data block: 24 sd_read_block = 0x11, // SD card read data block: 17 sd_get_cid = 0x0a, // get SD card CID: 10 sd_get_csd = 0x09, // obtain the SD card CSD: 9} commandlist; byte sd_write_command (byte command, DWORD date, byte CRC); sd_errorlist sd_reset (void); sd_errorlist sd_init (void ); sd_errorlist sd_write_sector (byte * buffer, DWORD address); sd_errorlist sd_read_sector (byte * buffer, DWORD address); Word sd_get_capaity (void); # endif

Be sure to note that the SD card in SPI mode supports a maximum of 2 GB of cards, and the above cannot be used. I am wasting most of my time here. Generally, as long as the program is correct, it can be called soon, And the read/write sector function is well implemented.

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.