|
楼主 |
发表于 2022-4-6 11:41:56
|
显示全部楼层
感谢回复,具体的信息如下
1、SPI nand flash 型号 华邦的 W25N01GV
——128MB NAND FLASH,1024块*64页*(2048+64)字节。
2、使用FILEX官方提供的三个源文件实现DEMO:
demo_filex_nand_flash.c
fx_nand_flash_simulated_driver.c
lx_nand_flash_simulator.c
3、主要修改:
1)lx_nand_flash_simulator.c里面的虚拟RAM驱动改为NAND FLASH的实际驱动
例如READ函数如下改动如下,其他的函数不一一列出。
#ifndef NO_SIMULATER //原来官方的 虚拟RAM 驱动 读函数
UINT _lx_nand_flash_simulator_read(ULONG block, ULONG page, ULONG *destination, ULONG words)
{
ULONG *flash_address;
LONG i,status=0;
u8 *destination1=(u8*)destination;
/* Pickup the flash address. */
flash_address = &(nand_memory_area[block].physical_pages.memory[0]);
APP_TRACE_INFO("NAND_ReadPage_block, page,status,words:%d,%d,%ld,%d \n",(int)block,(int)page,status,(int)words);
/* Loop to read flash. */
while (words--)
{
/* Copy word. */
*destination++ = *flash_address++;
}
for(i=0;i<260;i++)
{
APP_TRACE_INFO("NAND_ReadPage_destination:%ld,%d \n",i,destination1[i]);
}
return(LX_SUCCESS);
}
#else
//wt 改为NAND FLASH实际的读操作
/* page read function
*input :
*block 0-1023
*page 0-63
*destination data
*words number of words (4 byetes)
*return:
*LX_SUCCESS read ok
*LX_ERROR read error
*/
UINT _lx_nand_flash_simulator_read(ULONG block, ULONG page, ULONG *destination, ULONG words)
{
UCHAR bad_block_byte;
LONG i,status=0;
u8 *destination1=(u8*)destination;
//check input prm
if(block>(TOTAL_BLOCKS-1) || page>(PHYSICAL_PAGES_PER_BLOCK-1) || words>WORDS_PER_PHYSICAL_PAGE)
{
APP_TRACE_INFO("_lx_nand_flash_simulator_read prm err-block, page,words:%d,%d,%d \n",(int)block,(int)page,(int)words);
return(LX_ERROR);
}
status= NAND_ReadPage(block*64+page, 0, destination1, words*4);//2048-->words*4
//debug
APP_TRACE_INFO("NAND_ReadPage_block, page,status,words:%d,%d,%ld,%ld \n",(int)block,(int)page,status,words);
//debug 前4个字节读取
for(i=0;i<4;i++)
{
APP_TRACE_INFO("NAND_ReadPage_test0~3:%ld,%d \n",i,destination1[i]);
}
if(!status)
{
return(LX_SUCCESS);
}
else
{
APP_TRACE_INFO("_lx_nand_flash_simulator_read error \n");
return(LX_ERROR);
}
}
#endif
2)使用demo_filex_nand_flash.c进行测试
格式化NAND FLASH 如下
#if 1
/* Format the NAND disk - the memory for the NAND flash disk is setup in
the NAND simulator. Note that for best performance, the format of the
NAND flash should be less than one full NAND flash block of sectors. */
status = fx_media_format(&nand_disk,
_fx_nand_flash_simulator_driver, // Driver entry
FX_NULL, // Unused
media_memory, // Media buffer pointer
sizeof(media_memory), // Media buffer size
"MY_NAND_DISK", // Volume Name
1, // Number of FATs
32, // Directory Entries
0, // Hidden sectors
1200, // Total sectors //wt
2048, // Sector size
1, // Sectors per cluster
1, // Heads
1); // Sectors per track
#endif
/* Open the NAND disk. */
status = fx_media_open(&nand_disk, "NAND DISK", _fx_nand_flash_simulator_driver, FX_NULL, media_memory, sizeof(media_memory));
/* Check the media open status. */
if (status != FX_SUCCESS)
{
/* Error, break the loop! */
break;
}
status = fx_file_create(&nand_disk, "TEST.TXT");
/* Check the create status. */
if (status != FX_SUCCESS)
{
/* Check for an already created status. This is expected on the
second pass of this loop! */
if (status != FX_ALREADY_CREATED)
{
/* Create error, break the loop. */
break;
}
}
DEBUG_LED_RESET;
/* Open the test file. */
status = fx_file_open(&nand_disk, &my_file, "TEST.TXT", FX_OPEN_FOR_WRITE);
/* Check the file open status. */
if (status != FX_SUCCESS)
{
/* Error opening file, break the loop. */
break;
}
/* Seek to the beginning of the test file. */
status = fx_file_seek(&my_file, 0);
/* Check the file seek status. */
if (status != FX_SUCCESS)
{
/* Error performing file seek, break the loop. */
break;
}
DEBUG_LED_SET;
/* Write a string to the test file. */
status = fx_file_write(&my_file, " ABCDEFGHIJKLMNOPQRSTUVWXYZ\n", 28);
/* Check the file write status. */
if (status != FX_SUCCESS)
{
/* Error writing to a file, break the loop. */
break;
}
/* Seek to the beginning of the test file. */
status = fx_file_seek(&my_file, 0);
/* Check the file seek status. */
if (status != FX_SUCCESS)
{
/* Error performing file seek, break the loop. */
break;
}
DEBUG_LED_RESET;
/* Read the first 28 bytes of the test file. */
status = fx_file_read(&my_file, local_buffer, 28, &actual);
/* Check the file read status. */
if ((status != FX_SUCCESS) || (actual != 28))
{
/* Error reading file, break the loop. */
break;
}
/* Close the test file. */
status = fx_file_close(&my_file);
/* Check the file close status. */
if (status != FX_SUCCESS)
{
/* Error closing the file, break the loop. */
break;
}
/***************上面的代码跟踪 STATUS都是正常*****************************/
/***************之后进行下面的操作测试发现 异常*****************************/
status = fx_directory_create(&nand_disk, "ABC");//创建成功
status = fx_directory_create(&nand_disk, "DEF");//创建成功
status = fx_directory_create(&nand_disk, "GGG");//创建成功
status = fx_directory_create(&nand_disk, "ABC");//仍是创建成功,理论上应该返回FX_ALREADY_CREATED,但返回的是 FX_SUCCESS!!!!!!!!!!!!!!!!!!!!!!!!!!!
status = fx_file_create(&nand_disk, "ABC/TEST.TXT");//返回异常——FX_INVALID_PATH ,路径非法!
status = fx_file_create(&nand_disk, "DEF/TEST.TXT");//返回异常——FX_INVALID_PATH ,路径非法!
status = fx_file_create(&nand_disk, "GGG/TEST.TXT");//返回异常——FX_INVALID_PATH ,路径非法!
感觉 创建的文件好像没保存!! |
|