1.设置NFCONF, NFCONT
NFCONF = 0x300, 设置时序
NFCONT = (1 << 4) | (1 << 1) | (1 << 0)
2.发出片选信号.
NFCONT &= ~(1 << 11)
第一次操作nand flash前,通常复位 nand flash
NFCMMD = 0xff (reset 命令)
3.发出读命令
NFCMMD = 0 (读命令)
4.发出地址信号
volatile unsigned char *p = (volatile unsigned char *)&s3c2440nand->NFADDR;
*p = addr & 0xff;
*p = (addr >> 9) & 0xff;
*p = (addr >> 17) & 0xff;
*p = (addr >> 25) & 0xff;
5.循环查询NFSTAT 位0, 直到它等于1.
6.连续读NFDATA寄存器512次,得到一页数据(512字节)
循环执行 3,4,5,6
7.禁止nand flash 的片选信号.
NFCONT |= (1<<1)
以下为一个例子:
void nand_read(unsigned char *buf, unsigned long start_addr, int size)
{
int i, j;
if ((start_addr & NAND_BLOCK_MASK) || (size & NAND_BLOCK_MASK)) {
return ; /* 地址或长度不对齐 */
}
/* 选中芯片 */
nand_select_chip();
for(i=start_addr; i < (start_addr + size);) {
/* 发出READ0命令 */
write_cmd(0);
/* Write Address */
write_addr(i);
wait_idle();
for(j=0; j < NAND_SECTOR_SIZE; j++, i++) {
*buf = read_data();
buf++;
}
}
/* 取消片选信号 */
nand_deselect_chip();
return ;
}
阅读(1371) | 评论(0) | 转发(0) |