nand flash的读写测试和挂载文件系统的SD卡已经调试成功,因为SD卡读写速度太慢,导致图片解码程序的显示速度太慢,明显下一张图片慢慢刷新。现在想要将nand flash作为存储器来存储图片,然后解码显示。可是问题出现了,将文件系统FATFS移植到nandflash后,调用格式化函数
f_mkfs(0,1,4096) 时,一直返回“格式化失败”。
- void test_fatfs(void)
- {
- FATFS fs;
- FIL fl;
- FATFS *pfs;
- DWORD clust;
- unsigned int r,w,i;
- FRESULT res;
- // NF_CHKDSK(0,1024);
- display_page(0,0);
-
- // for mount挂载
- res=f_mount(0,&fs);
- printf("f_mount=%x
",res);
-
- // for format格式化
- res=f_mkfs(0,1,4096); //新NANDFLASH必须格式化 !!!
- printf("f_mkfs=%x
",res);
- // for
- pfs=&fs;
- res = f_getfree("/", &clust, &pfs);
- // res = f_getfree("", &clust, &pfs);
- printf("f_getfree=%x
",res);
- printf("
%lu MB total drive space."
- "
%lu MB available.
",
- (DWORD)(pfs->max_clust - 2) * pfs->csize /2/1024,
- clust * pfs->csize /2/1024);
-
- // for read
- res=f_open(&fl,"/test2.dat",FA_OPEN_EXISTING | FA_READ);
- // res=f_open(&fl,"test.txt",FA_OPEN_EXISTING | FA_READ);
- printf("f_open=%x
",res);
- for(i=0;i<2;i++)
- {
- for(r = 0; r < NAND_PAGE_SIZE; r++)
- {
- RxBuffer[r]= 0xff;
- }
-
- res=f_read(&fl,RxBuffer,NAND_PAGE_SIZE,&r);
- printf("f_read=%x
",res);
- if(res || r == 0)break;
- for(r = 0; r < NAND_PAGE_SIZE; r++)
- {
- printf("D[%08x]=%02x ",(i*NAND_PAGE_SIZE+r),RxBuffer[r]);
- if((r%8)==7)
- {printf("
");}
- }
-
- }
- f_close(&fl);
- // for write
- res=f_open(&fl,"/test2.dat",FA_CREATE_ALWAYS | FA_WRITE);
- // res=f_open(&fl,"test.txt",FA_CREATE_ALWAYS | FA_WRITE);
- printf("f_open=%x
",res);
- for(i=0;i<2;i++)
- {
- for(w = 0; w < NAND_PAGE_SIZE; w++)
- {
- TxBuffer[w]=((w<<0)&0xff);
- }
- res=f_write(&fl,TxBuffer,NAND_PAGE_SIZE,&w);
- printf("f_write=%x
",res);
- if(res || w
-
- }
- f_close(&fl);
-
- // for umount
- f_mount(0,NULL);
- }
复制代码
此帖出自
小平头技术问答
一周热门 更多>