20240909-DXSPX-emb/RTCGet(重写一版)/Src/Usr/ThirdParty/fatfs/usr_file.c
2024-09-13 16:57:53 +08:00

40 lines
1.0 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "usr_file.h"
#include "usr_drv_uart.h"
#include "ff.h"
#include "string.h"
FATFS g_usr_fs; // 逻辑磁盘工作区
int8_t usr_file_init(void)
{
FRESULT res;
DIR dir_init;
/* 挂载文件文件系统挂载时会SPI设备初始化 */
res = f_mount(&g_usr_fs, USR_DISK_PATH, 1);
if (res == FR_NO_FILESYSTEM) {
res = f_mkfs(USR_DISK_PATH, 0, 0, FF_MAX_SS);
if (res == FR_OK) {
/* 格式化后,先取消挂载 */
res = f_mount(NULL, USR_DISK_PATH, 1);
/* 重新挂载 */
res = f_mount(&g_usr_fs, USR_DISK_PATH, 1);
}
} else if (res == FR_OK) {
}
res = f_opendir(&dir_init, "ZTT");
/* 增加2s的延迟 */
OSTimeDly(2000);
if (res == FR_NO_PATH) {
res = f_mkdir("ZTT");
if (res == FR_OK) {
usr_drv_printf((uint8_t *)"ZTT create path success!!\n", strlen("ZTT create path success!!\n"));
} else {
usr_drv_printf((uint8_t *)"ZTT create path err!!\n", strlen("ZTT create path err!!\n"));
}
}
return 0;
}