123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- #include "bsp_fatfs.h"
- #include "ext_sram.h"
- #include "interface.h"
- #include "project_var.h"
- #include "stm32f4xx.h"
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- FATFS FatFs[_VOLUMES];
- FIL file_object;
- DWORD get_fattime(void)
- {
- RTC_TimeTypeDef RTC_TimeStruct;
- RTC_DateTypeDef RTC_DateStruct;
- RTC_GetTime(RTC_Format_BIN, &RTC_TimeStruct);
- RTC_GetDate(RTC_Format_BIN, &RTC_DateStruct);
-
- return ((DWORD)(2000 + RTC_DateStruct.RTC_Year - 1980) << 25)
- | ((DWORD)RTC_DateStruct.RTC_Month << 21)
- | ((DWORD)RTC_DateStruct.RTC_Date << 16)
- | ((DWORD)RTC_TimeStruct.RTC_Hours << 11)
- | ((DWORD)RTC_TimeStruct.RTC_Minutes << 5)
- | ((DWORD)RTC_TimeStruct.RTC_Seconds >> 1);
- }
- void fatfs_init(void)
- {
- FRESULT res;
- res = f_mount(&FatFs[0], "0:", 1);
-
- if (res == FR_NO_FILESYSTEM)
- {
- res = f_mkfs("0:", 0, 0);
- if (res == FR_OK)
- {
- DEBUG("TF format ok\r\n");
- res = f_mount(NULL, "0:", 1);
- res = f_mount(&FatFs[0], "0:", 1);
- }
- else
- {
- LED1_RUN_OFF;
- DEBUG("TF format fail\r\n");
- }
- }
- else if (res != FR_OK)
- {
- LED1_RUN_OFF;
- DEBUG("!!!TF mount file system fail (%d)\r\n", res);
- }
- else
- {
- LED1_RUN_ON;
- DEBUG("File system mount ok !\r\n");
- }
- res = f_mount(&FatFs[1], "1:", 1);
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- if (res == FR_NO_FILESYSTEM)
- {
- res = f_mkfs("1:", 0, 0);
- if (res == FR_OK)
- {
- DEBUG("Nand flash format ok\r\n");
- res = f_mount(NULL, "1:", 1);
- res = f_mount(&FatFs[1], "1:", 1);
- }
- else
- {
- LED1_RUN_OFF;
- DEBUG("Nand flash format fail\r\n");
- }
- }
- if (res != FR_OK)
- {
- LED0_RUN_OFF;
- DEBUG("!!!Nand flash mount file system fail (%d)\r\n", res);
- }
- else
- {
- LED0_RUN_ON;
- DEBUG("Nand flash file system mount ok !\r\n");
- }
- }
|