I want to use a nand flash ic with part number of K9F1G08U0C and connect it to a stm32f429igt6 microcontroller.
Although I can read the ID of this nand successfully but the written data and read back, are not the same.- I just read 0x31 -
I can also see the control signals with my logic analyzer and they are all acting as the datasheet says.
here is my test codes:
{
static NAND_AddressTypeDef WriteReadAddr;
static NAND_IDTypeDef NAND_ID;
static uint8_t TxBuffer [2048];
static uint8_t RxBuffer [2048];
HAL_NAND_Reset(&hnand1);
HAL_Delay(100);
/* Read the NAND memory ID */
HAL_NAND_Read_ID(&hnand1, &NAND_ID);
HAL_Delay(100);
/* Fill the buffer to send */
for (int i = 0; i < 2048; i++ )
{
RxBuffer[i] = 0;
}
/* Fill the buffer to send */
for (int i = 0; i < 2048; i++ )
{
TxBuffer[i] = i;
}
/* NAND memory address to write to */
WriteReadAddr.Plane = 0;
WriteReadAddr.Block = 2;
WriteReadAddr.Page = 0;
/* Erase the NAND first Block */
if( HAL_NAND_Erase_Block(&hnand1, &WriteReadAddr) != HAL_OK)
{
while(1);
}
HAL_Delay(100);
/* Write data to FMC NAND memory */
if(HAL_NAND_Write_Page(&hnand1, &WriteReadAddr, TxBuffer, 1) != HAL_OK)
{
while(1);
}
HAL_Delay(100);
/* Read data from FMC NAND memory */
if(HAL_NAND_Read_Page(&hnand1, &WriteReadAddr, RxBuffer, 1) != HAL_OK)
{
while(1);
}
/* check date */
if(memcmp(TxBuffer,RxBuffer,sizeof(TxBuffer)) == 0 )
printf("\r\n\r\n NandFlash Read Write Test OK\r\n");
else
{
printf("\r\n\r\n NandFlash Read Write False\r\n");
while(1);
}
}
and as you can see I use the hal nand flash library.
Here is how I init fmc peripheral:
static void MX_FMC_Init(void)
{
FMC_NAND_PCC_TimingTypeDef ComSpaceTiming;
FMC_NAND_PCC_TimingTypeDef AttSpaceTiming;
/** Perform the NAND2 memory initialization sequence
*/
hnand2.Instance = FMC_NAND_DEVICE;
/* hnand2.Init */
hnand2.Init.NandBank = FMC_NAND_BANK2;
hnand2.Init.Waitfeature = FMC_NAND_PCC_WAIT_FEATURE_ENABLE;
hnand2.Init.MemoryDataWidth = FMC_NAND_PCC_MEM_BUS_WIDTH_8;
hnand2.Init.EccComputation = FMC_NAND_ECC_DISABLE;
hnand2.Init.ECCPageSize = FMC_NAND_ECC_PAGE_SIZE_256BYTE;
hnand2.Init.TCLRSetupTime = 8;
hnand2.Init.TARSetupTime = 8;
/* hnand2.Config */
hnand2.Config.PageSize = 2048;
hnand2.Config.SpareAreaSize = 64;
hnand2.Config.BlockSize = 64;
hnand2.Config.BlockNbr = 1024;
hnand2.Config.PlaneNbr = 1;
hnand2.Config.PlaneSize = 1024;
hnand2.Config.ExtraCommandEnable = DISABLE;
/* ComSpaceTiming */
ComSpaceTiming.SetupTime = 0xF5;
ComSpaceTiming.WaitSetupTime = 0xF3;
ComSpaceTiming.HoldSetupTime = 0xF2;
ComSpaceTiming.HiZSetupTime = 0xF5;
/* AttSpaceTiming */
AttSpaceTiming.SetupTime = 0xF5;
AttSpaceTiming.WaitSetupTime = 0xF3;
AttSpaceTiming.HoldSetupTime = 0xF2;
AttSpaceTiming.HiZSetupTime = 0xF5;
if (HAL_NAND_Init(&hnand2, &ComSpaceTiming, &AttSpaceTiming) != HAL_OK)
{
Error_Handler( );
}
}
And if you need furthur information you can download the whole project here: https://www.dropbox.com/s/ro2nl2sssghympi/test_nand_flash.rar?dl=0