FATFS文件系统中f_lseek函数的使用
标签:
fatfssdstm32 |
分类: 技术类 |
FATFS文件系统中f_lseek函数的使用
BY:T7
Date:20171212
At:YSU_B307
开发环境:
uVision : V5.12.0.0 STM32F103V8T6
库版本 : STM32F10x_StdPeriph_Lib_V3.5.0
FATSF :
ff13a
下载地址:http://elm-chan.org/fsw/ff/00index_e.html
工程功能:分两次在同一个文件中写入两句话
第一次写入“This is the FATFS System!\r\n”
第二次在同一个文件中,第一句的后面写入:“************************\r\n"”
一、官方给出的解释
f_lseek
The f_lseek function moves the file read/write pointer of an
open file object. It can also be used to expand the file size
(cluster pre-allocation).
FRESULT f_lseek (
);
Parameters
fp
Pointer to the open file object.
ofs
Byte offset from top of the file to set read/write pointer.
The data type FSIZE_t is an alias of either DWORD(32-bit) or
QWORD(64-bit) depends on the configuration option
FF_FS_EXFAT.
二、主函数源码:后面附上整个工程的百度云链接
#include "main.h"
#define ONE_BLOCK
512
#define TWO_BLOCK
1024
FIL *FilPtr,FileSystemDst; //文件系统结构体,包含文件指针等成员
UINT br,bw; //Fil R/W count
BYTE FileRxBuffer[4096]; //FILE COPY BUFFER
BYTE TxFileBuffer[] = "This is the FATFS System!\r\n";
BYTE TxFileBuffer1[] = "************************\r\n";
int main(void)
{
FATFS fs; //记录文件系统盘符信息的结构体
LED_Init();
USARTx_Init();
FilPtr = &FileSystemDst;
f_mount(&fs, "0:", 1 );
f_open( FilPtr , "0:/Demo0.TXT", FA_OPEN_ALWAYS | FA_WRITE);
f_lseek(FilPtr,f_size(FilPtr)); //第一次该函数实际并没有发挥威力
f_write( FilPtr , TxFileBuffer
, sizeof(TxFileBuffer) ,
&bw);
f_close(FilPtr);
f_open( FilPtr , "0:/Demo0.TXT", FA_OPEN_ALWAYS |
FA_WRITE);
f_lseek(FilPtr,f_size(FilPtr));
f_write( FilPtr , TxFileBuffer1
, sizeof(TxFileBuffer1) , &bw);
f_close(FilPtr);
while(1)
}
STM32上电四次,用读卡器打开SD卡的Demo.TXT文件,如下:
百度云链接:链接:https://pan.baidu.com/s/1bpxx4eF 密码:47vn

加载中…