Skip to main content
Visitor II
March 31, 2021
Question

Problem with invalid read/write with STM32F7 FMC NAND Flash memory

  • March 31, 2021
  • 2 replies
  • 1858 views

Hi,

I am working with a custom board using the STM32F765VGT6 which is connected to a NAND flash chip, the WN29N02GV, via the FMC peripheral.

I have been able to read the flash ID correctly, but am having issues with the reading and writing data.

I wrote a simple program, to write data to a page, and then read back the data and compare. The problem is that the data read in, does not match the data that was written. The program is shown below:

void vTestMemory(void * pvParams){
 
	//Write Protect Pin should be high.
	HAL_GPIO_WritePin(FLASH_WP_GPIO_Port, FLASH_WP_Pin, 1);
	HAL_NAND_Reset(&hnand1);
 
	NAND_IDTypeDef nandInfo;
 
	//For reference, the W29N02GV id:
//	nandInfo.Device_Id = 0xDA;
//	nandInfo.Maker_Id = 0xEF;
//	nandInfo.Third_Id=90;
//	nandInfo.Fourth_Id =95;
 
 NAND_AddressTypeDef addr;
 addr.Block = 0;
 addr.Page = 0;
 addr.Plane = 0;
 
	HAL_NAND_Erase_Block(&hnand1, &addr);
	HAL_StatusTypeDef res = HAL_NAND_Read_ID(&hnand1,&nandInfo);
 
	uint8_t testBuff [hnand1.Config.PageSize];
	uint8_t testBuffRx [hnand1.Config.PageSize];
 
 
 
 
 
	while(1){
 
		 for(int i=0; i< hnand1.Config.PageSize; i++){
 
		 	testBuff[i] = i%256;
		 	testBuffRx[i]= 0 ;
		 }
 
 
 
 
		 HAL_NAND_Read_Page_8b(&hnand1, &addr, testBuffRx, 1);
		 HAL_NAND_Write_Page_8b(&hnand1, &addr, testBuff, 1);
		 HAL_NAND_Read_Page_8b(&hnand1, &addr, testBuffRx, 1);
 
 
		 uint16_t good = 0;
		 for(int i=0; i<hnand1.Config.PageSize; i++){
 
		 	if(testBuffRx[i] != testBuff[i]){
		 		good ++;
 
		 	}
 
		 }
		 HAL_NAND_Address_Inc(&hnand1, &addr);
		 if(addr.Block == 2048 && addr.Page == 64){
		 	uint8_t a = 0;//End of memory, breakpoint here...
		 }
		vTaskDelay(pdMS_TO_TICKS(5));
	}
}

Specifically, the data that is read in should be a repeating sequence of bytes counting from 0 to 255, but the actual data read in seems to miss the last bytes, and at some point(s) in the page, it looks like a value is skipped, or a byte was missed. The point at which the first error appears changes and doesn't appear to have a pattern.

I'm not sure whether the issue is with the read or the write, and the issue is consistenly happening, after the first time I ran the code, when it seemed to work fine.

Does anyone have any suggestions for what the error might be or any solution for getting valid data ?

I have setup the flash memory using STM32CubeMX, and the following initialization function was generated:

void MX_FMC_Init(void)
{
 /* USER CODE BEGIN FMC_Init 0 */
 
 /* USER CODE END FMC_Init 0 */
 
 FMC_NAND_PCC_TimingTypeDef ComSpaceTiming = {0};
 FMC_NAND_PCC_TimingTypeDef AttSpaceTiming = {0};
 
 /* USER CODE BEGIN FMC_Init 1 */
 
 /* USER CODE END FMC_Init 1 */
 
 /** Perform the NAND1 memory initialization sequence
 */
 hnand1.Instance = FMC_NAND_DEVICE;
 /* hnand1.Init */
 hnand1.Init.NandBank = FMC_NAND_BANK3;
 hnand1.Init.Waitfeature = FMC_NAND_WAIT_FEATURE_ENABLE;
 hnand1.Init.MemoryDataWidth = FMC_NAND_MEM_BUS_WIDTH_8;
 hnand1.Init.EccComputation = FMC_NAND_ECC_ENABLE;
 hnand1.Init.ECCPageSize = FMC_NAND_ECC_PAGE_SIZE_2048BYTE;
 hnand1.Init.TCLRSetupTime = 0;
 hnand1.Init.TARSetupTime = 0;
 /* hnand1.Config */
 hnand1.Config.PageSize = 2048;
 hnand1.Config.SpareAreaSize = 64;
 hnand1.Config.BlockSize = 64;
 hnand1.Config.BlockNbr = 2048;
 hnand1.Config.PlaneNbr = 2;
 hnand1.Config.PlaneSize = 1024;
 hnand1.Config.ExtraCommandEnable = DISABLE;
 /* ComSpaceTiming */
 ComSpaceTiming.SetupTime = 40;
 ComSpaceTiming.WaitSetupTime = 120;
 ComSpaceTiming.HoldSetupTime = 120;
 ComSpaceTiming.HiZSetupTime = 40;
 /* AttSpaceTiming */
 AttSpaceTiming.SetupTime = 40;
 AttSpaceTiming.WaitSetupTime = 120;
 AttSpaceTiming.HoldSetupTime = 120;
 AttSpaceTiming.HiZSetupTime = 40;
 
 if (HAL_NAND_Init(&hnand1, &ComSpaceTiming, &AttSpaceTiming) != HAL_OK)
 {
 Error_Handler( );
 }
 
 /* USER CODE BEGIN FMC_Init 2 */
 
 /* USER CODE END FMC_Init 2 */
}

I have tried changing the timing parameters, which doesn't fix the issues.

I'm running the memory test as a FreeRTOS task, but I have tried without FreeRTOS and the issue was still happening.

I have the MPU disabled, and all the caching turned off.

    This topic has been closed for replies.

    2 replies

    Visitor II
    December 5, 2022

    Hi,

    I feel like I observe the same problem using the FMC bus of a Nucleo-F746ZG and a MT29F8G08ABABA in asynchronous mode. I also replicated the problem on a STM32F745 and a MT29F8G08ABBCA. I was wondering if you found the solution or if anyone from ST reached out to you. Explanation of the problem :

    When following the same procedure as described above, at least 1 byte gets skipped during a page read/write. Example : testBuffRx[0] = 0, testBuffRx[1] = 1, testBuffRx[2] = 3, testBuffRx[3] = 4... On my side, the failing testBuffRx index looks somewhat repeatable. Changing the FMC bus timings increments or decrements the failing index.

    Best regards.

    Explorer
    April 8, 2024

    I was encountering a similar issue. The cause of the issue was that Write Protection pin was not pulled High.