|
1、使用例子:
http://www.armbbs.cn/forum.php?mod=viewthread&tid=20006
2、函数使用方法:
http://elm-chan.org/fsw/ff/doc/utime.html
3、测试代码:
写入的时间是2018年8月17号,12时12分12秒
- /*
- *********************************************************************************************************
- * 函 数 名: CreateNewFile
- * 功能说明: 在SD卡创建一个新文件,文件内容填写“www.armfly.com”
- * 形 参:无
- * 返 回 值: 无
- *********************************************************************************************************
- */
- FRESULT set_timestamp (
- char *obj, /* Pointer to the file name */
- int year,
- int month,
- int mday,
- int hour,
- int min,
- int sec
- )
- {
- FILINFO fno;
- fno.fdate = (WORD)(((year - 1980) * 512U) | month * 32U | mday);
- fno.ftime = (WORD)(hour * 2048U | min * 32U | sec / 2U);
- return f_utime(obj, &fno);
- }
- static void CreateNewFile(void)
- {
- /* 本函数使用的局部变量占用较多,请修改启动文件,保证堆栈空间够用 */
- FRESULT result;
- FATFS fs;
- FIL file;
- DIR DirInf;
- uint32_t bw;
- /* 挂载文件系统 */
- result = f_mount(&fs, "0:", 0); /* Mount a logical drive */
- if (result != FR_OK)
- {
- printf("挂载文件系统失败 (%d)\r\n", result);
- }
- /* 打开根文件夹 */
- result = f_opendir(&DirInf, "/"); /* 如果不带参数,则从当前目录开始 */
- if (result != FR_OK)
- {
- printf("打开根目录失败 (%d)\r\n", result);
- return;
- }
- /* 打开文件 */
- result = f_open(&file, "armfly.txt", FA_CREATE_ALWAYS | FA_WRITE);
- /* 写一串数据 */
- result = f_write(&file, "FatFS Write Demo \r\n www.armfly.com \r\n", 34, &bw);
- if (result == FR_OK)
- {
- printf("armfly.txt 文件写入成功\r\n");
- }
- else
- {
- printf("armfly.txt 文件写入失败\r\n");
- }
- /* 关闭文件*/
- f_close(&file);
-
- set_timestamp("armfly.txt", 2018, 8, 17, 12, 12, 12);
- /* 卸载文件系统 */
- f_mount(NULL, "0:", 0);
- }
复制代码
4、模拟U盘效果:
|
|