How to create an FLM for external Nand-Flash by FMC?

Hi there,

I am taking a lot time to try creating an FLM to program some date to the FMC Nand-Flash on my homemade  board.

I already read This Tutorial and this This page, but I am NOT successful.

My MCU is STM32F429BIT6 and my Nand-Flash is H27U1G8F2BTR, I already have a demo to read/write/erase the Flash normally by HAL lib.

The Nand-Flash is 2KBytes * 64Pages * 1024Blocks = 128MBytes, so I config as this:

struct FlashDevice const FlashDevice  =  {
   FLASH_DRV_VERS,             // Driver Version, do not modify!
   "ARMFLY_STM32V6_NandFlash",   // Device Name 
   EXT8BIT,                     // Device Type
   0x70000000,                 // Device Start Address
   0x08000000,                 // Device Size in Bytes (128MB)
   2048,                       // Programming Page Size
   0,                          // Reserved, must be 0
   0xFF,                       // Initial Content of Erased Memory
   6000,                        // Program Page Timeout 100 mSec
   6000,                       // Erase Sector Timeout 3000 mSec

// Specify Size and Address of Sectors
   0x020000, 0x000000,         // Sector Size  128kB (1024 Sectors)
   SECTOR_END
};

and finished FlashPrg.c as below:

#define DEV_ADDR		0x70000000
#define PAGE_SIZE		2048
#define BLOCK_NUM		1024
#define BLOCK_SIZE	(2048 * 64)

int Init (unsigned long adr, unsigned long clk, unsigned long fnc)
{
    HAL_Init();
	SystemClock_Config();
	MX_GPIO_Init();
	MX_FMC_Init();
  return (0);                                  // Finished without Errors
}

int EraseSector (unsigned long adr)
{
	adr -= DEV_ADDR;
	NAND_AddressTypeDef nand_addr = {.Page = 0, .Block = adr / BLOCK_SIZE, .Plane = 0};
	if(HAL_NAND_Erase_Block(&hnand1, &nand_addr)) {
		return 1;
	}
  return (0);                                  // Finished without Errors
}

int ProgramPage (unsigned long adr, unsigned long sz, unsigned char *buf) 
{
	adr -= DEV_ADDR;
	NAND_AddressTypeDef nand_addr = {.Page = adr % BLOCK_SIZE / PAGE_SIZE, .Block = adr / BLOCK_SIZE, .Plane = 0};
	if(HAL_NAND_Write_Page_8b(&hnand1, &nand_addr, buf, 1)) {
		return 1;
	}
  return (0);                                  // Finished without Errors
}

Of cause I rewrite the HAL_GetTick(), HAL_Delay(), and HAL_Inc() functions the same as the tutorial.

But when I load the FLM and try to program the Nand-Flash, the IDE always Programming Failed!

What‘s wrong with my FLM and How to fix it?

Thands to your help!