#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "led.h"
#include "sdram.h"
#include "mpu.h"
#include "malloc.h"
#include "nand.h"
#include "ftl.h"
#include "ff.h"
#include "exfuns.h"
#include "string.h"
FRESULT scan_files (char* path)
{
FRESULT res;
DIR dir;
UINT i;
static FILINFO fno;
static u8 layerDeeph=0;
u8 j;
res = f_opendir(&dir, path);
if (res == FR_OK)
{
layerDeeph+=4;
for (;;)
{
res = f_readdir(&dir, &fno);
if (res != FR_OK || fno.fname[0] == 0)
break;
if (fno.fattrib & AM_DIR)
{
i = strlen(path);
sprintf(&path[i], "/%s", fno.fname);
for(j=0;j<layerDeeph;j++)
printf(" ");
printf("%s%s%s%s%s%s\r\n", "\033[","33;","22m",fno.fname," <DIR>","\033[0m");
res = scan_files(path);
if (res != FR_OK) break;
path[i] = 0;
}
else
{
for(j=0;j<layerDeeph;j++)
printf(" ");
printf("%s%s%s%s%s\r\n","\033[","32;","22m",fno.fname,"\033[0m");
}
}
f_closedir(&dir);
layerDeeph-=4;
}
return res;
}
int main(void)
{
char buff[256];
u8 t=0;
u8 res=0;
FIL file;
Cache_Enable(); //打开L1-Cache
HAL_Init(); //初始化HAL库
Stm32_Clock_Init(160,5,2,4); //设置时钟,400Mhz
delay_init(400); //延时初始化
uart_init(115200); //串口初始化
LED_Init(); //初始化LED
SDRAM_Init(); //初始化SDRAM
my_mem_init(SRAMIN); //初始化内部内存池(AXI)
my_mem_init(SRAMEX); //初始化外部内存池(SDRAM)
my_mem_init(SRAM12); //初始化SRAM12内存池(SRAM1+SRAM2)
my_mem_init(SRAM4); //初始化SRAM4内存池(SRAM4)
my_mem_init(SRAMDTCM); //初始化DTCM内存池(DTCM)
my_mem_init(SRAMITCM); //初始化ITCM内存池(ITCM)
FTL_Init();
exfuns_init(); //为fatfs相关变量申请内存
res=f_mount(fs[0],"0:",1); //挂载NAND FLASH.
if(res==0X0D) //NAND FLASH磁盘,FAT文件系统错误,重新格式化NAND FLASH
{
printf("NAND Disk Formatting...\r\n");//格式化NAND
res=f_mkfs("0:",FM_ANY,0,fatbuf,FF_MAX_SS); //格式化NAND FLASH,1:,盘符;FM_ANY,自动选择文件系统类型,0,自动选择簇大小
if(res==0)
{
f_setlabel((const TCHAR *)"0:NANDDISK");//设置Flash磁盘的名字为:NANDDISK
printf("NAND Disk Format Finish\r\n"); //格式化完成
}
else
printf("NAND Disk Format Error\r\n"); //格式化失败
delay_ms(1000);
}
printf("*********************************\r\n");
f_mkdir("/HDC");
f_open(&file,"/HDC/1.txt",FA_OPEN_ALWAYS|FA_WRITE);
f_close(&file);
f_open(&file,"/HDC/2.txt",FA_OPEN_ALWAYS|FA_WRITE);
f_close(&file);
f_mkdir("/HDC/A");
f_open(&file,"/HDC/A/A1.txt",FA_OPEN_ALWAYS|FA_WRITE);
f_close(&file);
f_open(&file,"/HDC/A/A2.txt",FA_OPEN_ALWAYS|FA_WRITE);
f_close(&file);
f_open(&file,"/HDC/A/A3.txt",FA_OPEN_ALWAYS|FA_WRITE);
f_close(&file);
f_mkdir("/HDC/B");
f_open(&file,"/HDC/B/B1.txt",FA_OPEN_ALWAYS|FA_WRITE);
f_close(&file);
f_open(&file,"/HDC/B/B2.txt",FA_OPEN_ALWAYS|FA_WRITE);
f_close(&file);
f_open(&file,"/HDC/B/B3.txt",FA_OPEN_ALWAYS|FA_WRITE);
f_close(&file);
f_mkdir("/HDC/C");
f_open(&file,"/HDC/C/C1.txt",FA_OPEN_ALWAYS|FA_WRITE);
f_close(&file);
f_open(&file,"/HDC/C/C2.txt",FA_OPEN_ALWAYS|FA_WRITE);
f_close(&file);
f_open(&file,"/HDC/C/C3.txt",FA_OPEN_ALWAYS|FA_WRITE);
f_close(&file);
strcpy(buff, "/");
res = scan_files(buff);
while(1)
{
t++;
delay_ms(200);
LED0_Toggle;//DS0闪烁
}
}
|
|