请选择 进入手机版 | 继续访问电脑版

硬汉嵌入式论坛

 找回密码
 立即注册
查看: 1235|回复: 5
收起左侧

[FileX] 求助-FileX+LeveX 基于SPI nand flash 在根目录创建多个文件 都显示成功创建,但之后操作打开只有最后创建的一个文件可以正常...

[复制链接]

1

主题

3

回帖

6

积分

新手上路

积分
6
发表于 2022-4-6 10:32:45 | 显示全部楼层 |阅读模式
如题,FileX+LeveX 基于SPI nand flash ,写好代码后,运行官方的DEMO例程——创建文件 写文件和读文件,都操作正常。但后来测试,在根目录创建多个文件,也 都显示成功创建,但之后操作打开之前创建的文件,只有最后创建的一个文件可以正常打开。其他的文件都是找达不到。感觉是文件系统的指针问题,貌似是没存上。不知道各位是否遇到类似的问题?是驱动问题?还是配置问题?
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
105917
QQ
发表于 2022-4-6 10:48:25 | 显示全部楼层
方便的话,贴下操作代码,先看下这部分有问题没。
回复

使用道具 举报

1

主题

3

回帖

6

积分

新手上路

积分
6
 楼主| 发表于 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  ,路径非法!


        感觉 创建的文件好像没保存!!                       
回复

使用道具 举报

1

主题

3

回帖

6

积分

新手上路

积分
6
 楼主| 发表于 2022-4-6 13:36:57 | 显示全部楼层
补充,将lx_nand_flash_simulator.c里面的NAND FLASH的实际驱动,改回原来例程里的基于RAM的虚拟底层驱动,就没问题了。应该是lx底层操作nandflash驱动的问题,但不好定位。
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
105917
QQ
发表于 2022-4-7 10:43:13 | 显示全部楼层
jnwt 发表于 2022-4-6 11:41
感谢回复,具体的信息如下
1、SPI nand flash 型号 华邦的 W25N01GV
——128MB NAND FLASH,1024块*64页* ...

这问题好像之前一个坛友遇到了类似的问题,你现在用的是最新版6.1.10吧、

别的问题不太清楚了。
回复

使用道具 举报

1

主题

3

回帖

6

积分

新手上路

积分
6
 楼主| 发表于 2022-4-8 21:45:36 | 显示全部楼层
eric2013 发表于 2022-4-7 10:43
这问题好像之前一个坛友遇到了类似的问题,你现在用的是最新版6.1.10吧、

别的问题不太清楚了。

是的 是用的6.1.10版本
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-3-29 07:02 , Processed in 0.231983 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表