( 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 */
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

3. Close the file

( 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

©2020 ioDraw All rights reserved
vue Mobile end head assembly Python Romantic confession source code ( With detailed tutorial ) There's rubbish in the veins Regular infusion is necessary ? You didn't discuss it Tiktok Java Three aspects of post technology sharing :Java Basics + network HashMap+JVM+ database stay SpringBoot Use in MongoDb Code for unit testing C/C++ String formatting be based on php Snowflake algorithm based on (snowflake) unicorn 9000 It's finally released , It's a pity that it's a generation behind Wechat applet custom wave component Javascript Entry stage ——if sentence