硬汉嵌入式论坛

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

[RL-FlashFS] RL-FLASHFS驱动w25n01gvze1g型号nandflash,spi接口

[复制链接]

1

主题

2

回帖

1

积分

新手上路

积分
1
发表于 2016-11-5 15:42:04 | 显示全部楼层 |阅读模式
使用w25n01gvze1g型号nandflash,spi接口,cortexM4F内核,裸机移植rl-flashfs系统。


参考f429驱动的例子,
低级格式化完成...
挂载文件系统失败,返回码2.
底层的读写和块擦除函数都测试通过没问题,flash的硬件ecc使能,还应该查哪里呢 ??求高手指点!
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
106726
QQ
发表于 2016-11-6 10:17:12 | 显示全部楼层
返回2表示:卷错误,挂载失败,对于FAT文件系统意味着无效的MBR,启动记录或者非FAT格式

应该是你的底层读写函数还是有问题。
回复

使用道具 举报

1

主题

2

回帖

1

积分

新手上路

积分
1
 楼主| 发表于 2016-11-7 09:53:58 | 显示全部楼层
测试时连续读写了16个块,验证了每页2048个数据没有错。64B spare area各位含义如下图:



以下初始化、读写函数:

static U32 Init (NAND_DRV_CFG *cfg) {
   
  /* Define spare area layout */
  
   cfg-&gtgLay-&gtos_LSN = 4;
  cfg-&gtgLay-&gtos_COR = 2;
  cfg-&gtgLay-&gtos_BBM = 0;
  cfg-&gtgLay-&gtos_ECC = 8;

  /* Define page organization */
  cfg-&gtgLay->SectInc  =  512;
  cfg-&gtgLay->SpareOfs =  2048;
  cfg->PgLay->SpareInc =  16;
   
  NAND_Init();
  return RTV_NOERR;
}

/*-----------------------------------------------------------------------------
*      Read page
*  row  = Page address
*  *buf = Pointer to data buffer
*  *cfg = Pointer to configuration structure
*
*  Return: RTV_NOERR         - Page read successful
*          ERR_NAND_HW_TOUT  - Hardware transfer timeout
*          ERR_ECC_COR       - ECC corrected the data within page
*          ERR_ECC_UNCOR     - ECC was not able to correct the data
*----------------------------------------------------------------------------*/
static U32 PageRead (U32 row, U8 *buf, NAND_DRV_CFG *cfg) {
   U8 Status;
   
   Status = NAND_ReadPage(buf, row, 0, NAND_PAGE_TOTAL_SIZE);
   return Status;
}

static U32 PageWrite (U32 row, U8 *buf, NAND_DRV_CFG *cfg) {
   U8 Status;

   Status = NAND_WritePage(buf, row, 0, NAND_PAGE_TOTAL_SIZE);
   return Status;
}
底层检读取态寄存器返回ECC校验结果等
9E}0G(WM_`23X$%D9K0CV(F.png




uint8_t FSMC_NAND_ReadPage(uint8_t *_pBuffer, uint32_t _ulPageNo, uint16_t _usAddrInPage, uint16_t _usByteCount)
{
    unsigned int au32SourceData;
    unsigned int au32DestinationData;
    unsigned int counter;
    unsigned char eccresult;

        //2Îêy′íÎó
    if(_usByteCount > (2112-_usAddrInPage))
        return ERR_NAND_HW_TOUT;
    // /CS: active
    SPI_SET_SS_LOW(SPI2);

    // configure transaction length as 8 bits
    SPI_SET_DATA_WIDTH(SPI2, 8);

    // send Command: 0x03, Read data
    au32SourceData = 0x13;
    SPI_WRITE_TX(SPI2, au32SourceData);
    while(SPI_IS_BUSY(SPI2));

    au32SourceData = 0;
    SPI_WRITE_TX(SPI2, au32SourceData);
    while(SPI_IS_BUSY(SPI2));
   
    SPI_SET_DATA_WIDTH(SPI2, 16);
    // send 16-bit start address
    au32SourceData = _ulPageNo&0xffff;
    SPI_WRITE_TX(SPI2, au32SourceData);
    while(SPI_IS_BUSY(SPI2));

        SPI_SET_SS_HIGH(SPI2);
        //μè′yÖ¸¶¨ò3êy¾Yìî3ädata bufferíê3é
        for(counter = 6; counter >0; counter--)
        {
                if(NAND_IsReady() == 0)
                        break;
                SysTickDelay(10);
        }
        if(counter == 0)
                return ERR_NAND_HW_TOUT;
        
        SPI_SET_SS_LOW(SPI2);
    // configure transaction length as 8 bits
    SPI_SET_DATA_WIDTH(SPI2, 8);

        au32SourceData = 0x03;
        SPI_WRITE_TX(SPI2, au32SourceData);   
        while(SPI_IS_BUSY(SPI2));
        
        SPI_SET_DATA_WIDTH(SPI2, 24);
        
        // send 24-bit start address
        au32SourceData = _usAddrInPage;
        au32SourceData <<= 8;
        SPI_WRITE_TX(SPI2, au32SourceData);   
        while(SPI_IS_BUSY(SPI2));
        
        SPI_SET_DATA_WIDTH(SPI2, 8);
        
    I2S_CLR_RX_FIFO(SPI2);

    for(counter = 0; counter < _usByteCount; counter++)
    {
        // receive
        au32SourceData = 0x0;
        SPI_WRITE_TX(SPI2, au32SourceData);
        while(SPI_IS_BUSY(SPI2));

        // dump Rx register
        au32DestinationData = SPI_READ_RX(SPI2);
        _pBuffer[counter] = (unsigned char) au32DestinationData;
    }

    // /CS: de-active
    SPI_SET_SS_HIGH(SPI2);
        
        eccresult = (NAND_ReadStatusReg(0xc0)&0x30)>>4;
        if(eccresult == 0)
                return RTV_NOERR;
        else if(eccresult == 1)
                return ERR_ECC_COR;
        else
                return ERR_ECC_UNCOR;
}

不知道还有哪里有问题???或者除了验证2048字节数据读写正确,还需要测什么?
回复

使用道具 举报

1

主题

2

回帖

1

积分

新手上路

积分
1
 楼主| 发表于 2016-11-7 09:55:55 | 显示全部楼层
4[)JRNL]QJKWVV}}GMK66.png

补上图
回复

使用道具 举报

4

主题

10

回帖

22

积分

新手上路

积分
22
发表于 2019-2-26 13:44:57 | 显示全部楼层
LZ;驱动demo能分享一份么?
回复

使用道具 举报

0

主题

1

回帖

1

积分

新手上路

积分
1
发表于 2020-10-31 10:39:07 | 显示全部楼层
hi
i have same problem, could you solve this problem?
i got format failt and fint error code 2
but all low level spi nand flash work correctly
tnx
回复

使用道具 举报

7

主题

25

回帖

46

积分

新手上路

积分
46
发表于 2023-7-18 20:07:47 | 显示全部楼层
楼主,你好,问题解决了没
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-2 10:38 , Processed in 0.304135 second(s), 34 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

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