Analysis of Nand flash read and write process of RT thread

1. Nand Flash reading steps

  1. Read from main memory to Cache
  2. Read data from Cache
    insert image description here

2. Read from main memory to Cache

2.1 Read process under standard spi interface

insert image description here
Send Page Read to Cache command(13H)
Send the 24-bit page address
Check the register bit OIP, read the flash status, wait for the main memory read cache operation to complete
Read hweccthe bit, and judge whether it exceeds eccthe maximum error correction

rt_err_t spinand_read_dataload(struct rt_spi_device *spi,  uint8_t u8Addr2, uint8_t u8Addr1, uint8_t u8Addr0)
{
    
    
    rt_err_t result = RT_EOK;
    uint8_t au8Cmd[4] = {
    
    CMD_PAGE_READ_TO_CACHE, u8Addr2, u8Addr1, u8Addr0};
    uint8_t u8SR;


    if ((result = rt_spi_send(spi, &au8Cmd[0], sizeof(au8Cmd))) == 0)
        goto exit_spinand_read_dataload;

    if (spinand_isbusy(spi))
    {
    
    
        result = -RT_EIO;
        goto exit_spinand_read_dataload;
    }

    u8SR = spinand_hwecc_status_get(spi);
    if ((u8SR != 0x00) && (u8SR != 0x01))
    {
    
    
        result = -RT_MTD_EECC;
        LOG_E("Error ECC status error[0x%x].", u8SR);
    }

exit_spinand_read_dataload:

    return result > 0 ? RT_EOK : -RT_ERROR;
}

2.2 Test timing (SPI frequency 30MHz)

  1. Send read command and address:insert image description here
  2. Check register bits OIP, read flashstatus, wait for main memory read cacheoperation to complete
    insert image description here
  3. OIPbit to 0, the main memory read cacheoperation is complete
    insert image description here
  4. The whole process takes time
    insert image description here

3. Read data from Cache

3.1 Reading process in standard spi interface

发送Read From Cache command(03H)
发送page地址 24位
发送数据

insert image description here

	rt_err_t spinand_normal_read(struct rt_spi_device *spi, uint8_t u8AddrH, uint8_t u8AddrL, uint8_t *pu8Buff, uint32_t u32Count)
	{
    
    
	    uint8_t au8Cmd[4] = {
    
    CMD_READ_FROM_CACHE, u8AddrH, u8AddrL, DUMMY_BYTE};
	
	    return rt_spi_send_then_recv(spi, &au8Cmd[0], sizeof(au8Cmd), pu8Buff, u32Count);
}

test sequence

Send read command and address:insert image description here

Guess you like

Origin blog.csdn.net/qq_44710568/article/details/131896353