前几天那个LPC1788配置XIP[NOR]+SDRAM,在最后已经说了如何配置NAND的初始化,NAND和EEPROM不太一样,和SPI Flash有类似,和TF更类似,都是按块储存的.当然,NAND初始化过程最好读取一下ID,读取ID的方法一般是发0x90命令,然后获取5位.
0xEC是三星的厂商ID,后来就是四位,需要判断,所以我做了这个函数:
uint8_t NandFlash_ReadID( void ) { uint8_t a, b, c, d, e; *NandFlash_CLE = NandFlash_READ_ID; *NandFlash_ALE = 0; a = *NandFlash_DAT; b = *NandFlash_DAT; c = *NandFlash_DAT; d = *NandFlash_DAT; e = *NandFlash_DAT; if(a == 0xEC && b == 0xF1 && c == 0x00 && d == 0x95 && e == 0x40) { return 1; } else { return 0; } }
对了,看到三条线,CLE,ALE,DAT,其中我DAT是挂在0x98000000上的,ALE挂在0x98080000,CLE挂在0x98100000.所以定义:
volatile uint8_t *const NandFlash_CLE = ((volatile uint8_t *)0x98100000); volatile uint8_t *const NandFlash_ALE = ((volatile uint8_t *)0x98080000); volatile uint8_t *const NandFlash_DAT = ((volatile uint8_t *)0x98000000);
然而,其他算法,如检测坏块,这些,大同小异,自己复制抄袭好了.程序打包下载:LPC1788空白工程