fatfs 学习笔记--f_write用法(最新版本R0.13)
来源:互联网 发布:龙虎榜数据每天几点出 编辑:程序博客网 时间:2024/06/05 04:12
f_write
The f_write writes data to a file.
FRESULT f_write ( FIL* fp, /* [IN] Pointer to the file object structure */ const void* buff, /* [IN] Pointer to the data to be written */ UINT btw, /* [IN] Number of bytes to write */ UINT* bw /* [OUT] Pointer to the variable to return number of bytes written */);
Parameters
- fp
- Pointer to the open file object structure.
- buff
- Pointer to the data to be written.
- btw
- Specifies number of bytes to write in range of UINT type.
- bw
- Pointer to the UINT variable to return the number of bytes written. This value is always valid after the function call regardless of the return value.
Return Values
FR_OK, FR_DISK_ERR, FR_INT_ERR, FR_DENIED, FR_INVALID_OBJECT, FR_TIMEOUT
Description
The function starts to write data to the file at the position pointed by the read/write pointer. The read/write pointer advances as number of bytes written. After the function succeeded, *bw should be checked to detect the disk full. In case of *bw < btw, it means the volume got full during the write operation. The function can take a time when the volume is full or close to full.
QuickInfo
Available when FF_FS_READONLY == 0.
1. 在读操作过程中,一旦*br < btr 则读/写指针到达了文件结束位置.
2. 在写操作过程中,一旦*bw < btw,则意味着该卷已满.
函数实例:
/*
*********************************************************************************************************
* 函 数 名: Test_f_readwrite
* 功能说明: f_read和f_write函数测试
* 形 参:无
* 返 回 值: 无
*********************************************************************************************************
*/
uint8_t Test_f_readwrite(void)
{
FRESULT fr, result;
FATFS fs;
FIL fsrc, fdst;
UINT br, bw;
BYTE buffer[4096]; /* File copy buffer */
float FinishPecent;
uint32_t Count = 0;
/* 第1步:先挂载文件系统*********************************************************************/
result = f_mount(&fs, "1:", 1); /* Mount a logical drive */
if (result != FR_OK)
{
printf("挂载文件系统失败 (%s)\r\n", FR_Table[result]);
}
else
{
printf("挂载文件系统成功 (%s)\r\n", FR_Table[result]);
}
/* 第2步:打开两个文件********************************************************************/
fr = f_open(&fsrc, "1:/txt/nel.txt", FA_OPEN_EXISTING | FA_READ);
if (fr != FR_OK)
{
printf("打开失败 (%s)\r\n", FR_Table[fr]);
}
else
{
printf("打开成功 (%s)\r\n", FR_Table[fr]);
}
fr = f_open(&fdst, "1:/txt/nel1.txt", FA_CREATE_ALWAYS | FA_WRITE);
if (fr != FR_OK)
{
printf("打开失败 (%s)\r\n", FR_Table[fr]);
}
else
{
printf("打开成功 (%s)\r\n", FR_Table[fr]);
}
Count = 0;
FinishPecent = 0.0f;
/* 第3步:将文件nel.txt中的内容复制到nel1.txt里面****************************************/
for (;;)
{
fr = f_read(&fsrc, buffer, sizeof buffer, &br); /* 从源文件中读4K数据 */
/* 串口打印复制率 */
Count = Count + 1;
FinishPecent = (float)(Count* 4096) / fsrc.fsize;
printf("错误类型 = %s 当前已经复制%.2f \r", FR_Table[fr], FinishPecent);
if (fr || br == 0) break; /* 出现错误或者已经读完 */
fr = f_write(&fdst, buffer, br, &bw); /* 从源文件读出的内容写入多目的文件中 */
if (fr || bw < br) break; /* 写入出错或者磁盘已满 */
}
printf("\r\n"); /* 换行 */
/* 关闭打开的两个文件 */
f_close(&fsrc);
f_close(&fdst);
/* 最后一步:卸载文件系统 */
result = f_mount(NULL, "1:", 1);
if (result != FR_OK)
{
printf("卸载文件系统失败 (%s)\r\n", FR_Table[result]);
}
else
{
printf("卸载文件系统成功 (%s)\r\n", FR_Table[result]);
}
}
- fatfs 学习笔记--f_write用法(最新版本R0.13)
- fatfs 学习笔记--f_mkfs用法(最新版本R0.13)
- fatfs 学习笔记--f_open用法(最新版本)
- FATFS最新R0.13官方源码下载
- 移植最新版本FATFS R0.13 到STM32F105RB的内部flash diskio.c源码
- fatfs 学习笔记--f_mount用法
- FatFs移植笔记(R0.09)
- FatFs移植笔记(R0.09)
- STM32移植fatfs(R0.10a版本)
- FatFs学习
- FATFS学习
- FastDFS 最新版本 安装笔记
- FatFs之win32用法
- Fatfs f_size()API用法
- Fatfs f_unlink()API用法
- 基于STM32的SD卡FATFS文件系统学习笔记
- STM32学习笔记之fatfs文件系统接口函数使用
- FATFS文件系统+源码分析——学习笔记
- ES6常用语法
- banner轮播图
- [数论]线性求所有逆元的方法
- 慢查询日志详解
- 实现简单的万年历
- fatfs 学习笔记--f_write用法(最新版本R0.13)
- nginx缓存页面+cookie后 串会话问题
- Code[vs] 1506传话(tarjan缩点)
- UVA 116 Unidirectional TSP(动态规划)
- PreparedStatement和Statement的区别
- 什么是jquery
- Bootstrap图标菜单按钮组件
- mysql decimal
- 数据结构实验之排序五:归并求逆序数