1. Nand Flash reading steps
- Read from main memory to Cache
- Read data from Cache
2. Read from main memory to Cache
2.1 Read process under standard spi interface
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 hwecc
the bit, and judge whether it exceeds ecc
the 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)
- Send read command and address:
- Check register bits
OIP
, readflash
status, wait for main memory readcache
operation to complete
OIP
bit to 0, the main memory readcache
operation is complete
- The whole process takes time
3. Read data from Cache
3.1 Reading process in standard spi interface
发送Read From Cache command(03H)
发送page地址 24位
发送数据
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: