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!
Hello Shadow3d,
Thanks for using the Keil tools.
The documents you mentioned are for NOR flash; NAND flash is more complicated to setup.
We do have NAND flash examples.
But first... you will have to install the Arm7, Arm9, Cortex-R legacy pack into your C:\keil_v5 folder. You can find this download and install this pack from https://developer.arm.com/documentation/101407/0539/Creating-Applications/Tips-and-Tricks/Use-MDK-Version-4-Projects
Once you have that pack installed, look at the uvproj files in:
C:\Keil_v5\ARM\Flash\LPC3000_NAND_SP\C:\Keil_v5\ARM\Flash\S3C2440_NAND_SP\C:\Keil_v5\ARM\Flash\LPC31xx_NAND_LP\C:\Keil_v5\ARM\Flash\iMX27_NAND_SP\
One of the reasons this takes more steps for NAND flash is the NAND flash translation layer. See:
https://www.keil.com/pack/doc/mw/FileSystem/html/nand_flash__t_l.html
See also:
https://community.arm.com/support-forums/f/keil-forum/36034/external-flash-algorithm
Hope these examples help. Good luck