本文主要是介绍S3C2440裸机------NandFlash编程_擦除与烧写,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
目录
1.擦除
2.烧写
1.擦除
NandFlash是以块为单位进行擦除的,一个块是128K,从上面的时序图我们可以看到,首先我们要发出60命令,然后发出三个行地址,然后发送D0H,然后等待擦除结束。
int nand_erase(unsigned int addr, unsigned int len)
{int page = addr / 2048;if (addr & (0x1FFFF)){printf("nand_erase err, addr is not block align\n\r");return -1;}if (len & (0x1FFFF)){printf("nand_erase err, len is not block align\n\r");return -1;}nand_select(); while (1){page = addr / 2048;nand_cmd(0x60);/* row/page addr */nand_addr_byte(page & 0xff);nand_addr_byte((page>>8) & 0xff);nand_addr_byte((page>>16) & 0xff);nand_cmd(0xD0);wait_ready();len -= (128*1024);if (len == 0)break;addr += (128*1024);}nand_deselect(); return 0;
}
2.烧写
从上面的时序图可以看到,要想烧写NandFlash,我们首先发出80命令,然后发出五个地址,然后开始写数据,数据写完之后发出10命令,然后开始等待烧写完成。
void nand_write(unsigned int addr, unsigned char *buf, unsigned int len)
{int page = addr / 2048;int col = addr & (2048 - 1);int i = 0;nand_select(); while (1){nand_cmd(0x80);/* 发出地址 *//* col addr */nand_addr_byte(col & 0xff);nand_addr_byte((col>>8) & 0xff);/* row/page addr */nand_addr_byte(page & 0xff);nand_addr_byte((page>>8) & 0xff);nand_addr_byte((page>>16) & 0xff);/* 发出数据 */for (; (col < 2048) && (i < len); ){nand_w_data(buf[i++]);}nand_cmd(0x10);wait_ready();if (i == len)break;else{/* 开始下一个循环page */col = 0;page++;}}nand_deselect();
}
这篇关于S3C2440裸机------NandFlash编程_擦除与烧写的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!