( One ) download FATFS Source code

explain : share 8 Files diskio.c and diskio.h It's the hardware layer ,ff.c and ff.h yes FatFs File system layer and file system API layer ,integer.h Is the definition of the data type used by the file system ,tff.c and tff.h yes Tiny File system layer and file system API layer

( Two ) modify FATFS

It mainly modifies the underlying device driver function :diskio.c
objective : That is to say diskio.c Function interface and SPI Flash
Chip drivers are connected . There are five functions in total , They are device status acquisition (disk_status), Device initialization (disk_initialize), Sector read (disk_read), Sector write (disk_write), Other controls (disk_ioctl).

There are also modifications ffconf.h
objective : Configuration according to requirements ffconf.h Macro definition in

( Three ) Hanging on the file system
1. Create some objects
FATFS fs; /* FatFs File system objects /
FIL fnew; / File object /
FRESULT res_flash; / File operation results /
UINT fnum; / Number of files read and written successfully */

2. File system
// On the outside SPI Flash Mounting a file system , When the file system is mounted, the SPI Device initialization
res_flash = f_mount(&fs,“1:”,1);

If there is no file system, format it to create a file system
/* If there is no file system, create a file system by formatting it /
if(res_flash == FR_NO_FILESYSTEM)
{
/ format */
res_flash=f_mkfs(“1:”,0,0);
if(res_flash == FR_OK) { /* After formatting , Cancel mount first */ res_flash = f_mount(NULL,"1:",1);
/* Re mount */ res_flash = f_mount(&fs,"1:",1); }
}

( Four ) file system : write in
1. Open the file first
res_flash = f_open(&fnew, “1:FatFs Read and write test files .txt”,FA_CREATE_ALWAYS | FA_WRITE );
// Create one if it doesn't exist

2. Write the contents of the store to a file
res_flash=f_write(&fnew,WriteBuffer,sizeof(WriteBuffer),&fnum);

3. Close the file
f_close(&fnew);

( Five ) file system : read out
1. Open the file
res_flash = f_open(&fnew, “1:FatFs Read and write test files .txt”, FA_OPEN_EXISTING | FA_READ);

2. Read the contents of the file into the buffer
res_flash = f_read(&fnew, ReadBuffer, sizeof(ReadBuffer), &fnum);

3. Close the file
f_close(&fnew);

Technology
©2020 ioDraw All rights reserved
Rare expletives in Lei Jun's press conference : this XXX I'm definitely here to make trouble !Python Painting cherry blossoms 《 restructure 》 Excerpts from classic sentences , Programmers will get something after reading it utilize pytorch Training network --- refuse classification ,(resnet18) use python Draw a lovely Pikachu Multiple Vue How to deploy a project to a server 【 skill 】 Simple solutions Mac Insufficient disk space 2.Mysql database —— Insert data into a table This is the most classic outsourcing case in legend ? Don't outsource after watching it Gude Haowen serial - You deserve to be an engineer ( We should work around ourselves )