s3c2440对K9F2G08UOB Nand Flash的简单操作函数
时间:11-10
来源:互联网
点击:
功能:先擦除一块nand flash地址,然后往里面写一字符串,最后再读出来
实现,擦除、写、读功能。 芯片型号:K9F2G08UOB
/****************************************************
擦除nand flash 0x500000 地址
主函数:erase.c
****************************************************/
#define NFCONF *(volatile unsigned long *)0x4E000000
#define NFCONT *(volatile unsigned long *)0x4E000004
#define NFCMMD *(volatile unsigned long *)0x4E000008
#define NFADDR *(volatile unsigned long *)0x4E00000C
#define NFDATA *(volatile unsigned char *)0x4E000010
#define NFSTAT *(volatile unsigned long *)0x4E000020
void (*printf)(char *, ...) = 0x33f9291C;
void erase_nand(unsigned long addr);
void _start(void)
{
//configure for nand flash controller
NFCONF = (0x2 < 12) | (0x7 < 8) | (0x1 < 4);
//control
//NAND flash 开始工作
NFCONT = 1;
//设置擦除地址
erase_nand(0x500000);
}
//------发送地址参照K9F2G08UOA数据手册第9页--------
void send_addr(unsigned long addr)
{
NFADDR = (addr >> 11) & 0xff;
NFADDR = (addr >> 19) & 0xff;
NFADDR = (addr >> 27) & 0x1;
}
/*****************************************
块擦除
对照K9F2G08UOA手册第28页
******************************************/
void erase_nand(unsigned long addr)
{
unsigned int stat;
//发送指令60h块擦除设置指令
NFCMMD = 0x60;
//发送三次行地址
send_addr(addr);
//nandflash ready
//发送d0擦除指令
NFCMMD = 0xd0;
//等待忙状态
while(!(NFSTAT & 0x1))
;
// 发送70h读状态指令
NFCMMD = 0x70;
//读取数据
stat = NFDATA;
//最后一位判断成功与否
if(stat & 0x1){
printf("erase nand flash device err\n");
return ;
}
printf("erase nand flash device success\n");
}
/****************************************************
写nand flash 0x500000 地址 一个字符串
主函数:write.c
****************************************************/
#define NFCONF *(volatile unsigned long *)0x4E000000
#define NFCONT *(volatile unsigned long *)0x4E000004
#define NFCMMD *(volatile unsigned long *)0x4E000008
#define NFADDR *(volatile unsigned long *)0x4E00000C
#define NFDATA *(volatile unsigned char *)0x4E000010
#define NFSTAT *(volatile unsigned long *)0x4E000020
void (*printf)(char *, ...) = 0x33f9291C;
void write_nand(char *buf, unsigned long addr, int size);
char buf[11];
void _start(void)
{
int i;
//configure for nand flash controller
NFCONF = (0x2 < 12) | (0x7 < 8) | (0x1 < 4);
//control
NFCONT = 1;
//准备一个全写a的数组
for(i = 0; i < 11; i++)
{
buf= a;
}
//往0x500000写字符串buf 11个字节
write_nand(buf, 0x500000, 11);
}
//------发送地址参照K9F2G08UOA数据手册第9页--------
void send_addr(unsigned long addr)
{
NFADDR = addr & 0xff;
NFADDR = (addr >> 8) & 0x7;
NFADDR = (addr >> 11) & 0xff;
NFADDR = (addr >> 19) & 0xff;
NFADDR = (addr >> 27) & 0x1;
}
/*****************************************
写数据
对照K9F2G08UOA手册第25页
******************************************/
void write_nand(char *buf, unsigned long addr, int size)
{
int i;
unsigned int stat;
//发80h串口数据输入指令
NFCMMD = 0x80;
//发送两次列地址,三次行地址
send_addr(addr);
//nandflash 数据准备
for(i = 0; i < (size); i++)
{
NFDATA = buf;
}
//发送10h写指令
NFCMMD = 0x10;
//等待忙状态
while(!(NFSTAT & 0x1))
;
// 发送70h读状态指令
NFCMMD = 0x70;
stat = NFDATA;
//最后一位判断成功与否
if(stat & 0x1){
printf("write nand flash device err\n");
return ;
}
printf("write nand flash device success\n");
}
/****************************************************
读nand flash 0x500000 地址 10个字节
主函数:read.c
****************************************************/
#define NFCONF *(volatile unsigned long *)0x4E000000
#define NFCONT *(volatile unsigned long *)0x4E000004
#define NFCMMD *(volatile unsigned long *)0x4E000008
#define NFADDR *(volatile unsigned long *)0x4E00000C
#define NFDATA *(volatile unsigned char *)0x4E000010
#define NFSTAT *(volatile unsigned long *)0x4E000020
void (*printf)(char *, ...) = 0x33f9291C;
void read_nand(char *buf, unsigned long addr, int size);
void _start(void)
{
char buf[11];
//configure for nand flash controller
NFCONF = (0x2 < 12) | (0x7 < 8) | (0x1 < 4);
//control
NFCONT = 1;
//往0x500000读数据
read_nand(buf, 0x500000, 10);
buf[11] = 0;
printf("read from nandflash: %s\n", buf);
}
//------发送地址参照K9F2G08UOA数据手册第9页--------
void send_addr(unsigned long addr)
{
NFADDR = addr & 0xff;
NFADDR = (addr >> 8) & 0x7;
NFADDR = (addr >> 11) & 0xff;
NFADDR = (addr >> 19) & 0xff;
NFADDR = (addr >> 27) & 0x1;
}
/*****************************************
读数据
对照K9F2G08UOA手册第23页
******************************************/
void read_nand(char *buf, unsigned long addr, int size)
{
int i;
NFCMMD = 0x00;
send_addr(addr);
NFCMMD = 0x30;
while(!(NFSTAT & 0x1 ))
;
//nandflash ready
for(i = 0; i < (size); i++)
{
buf= NFDATA;
}
}
实现,擦除、写、读功能。 芯片型号:K9F2G08UOB
/****************************************************
擦除nand flash 0x500000 地址
主函数:erase.c
****************************************************/
#define NFCONF *(volatile unsigned long *)0x4E000000
#define NFCONT *(volatile unsigned long *)0x4E000004
#define NFCMMD *(volatile unsigned long *)0x4E000008
#define NFADDR *(volatile unsigned long *)0x4E00000C
#define NFDATA *(volatile unsigned char *)0x4E000010
#define NFSTAT *(volatile unsigned long *)0x4E000020
void (*printf)(char *, ...) = 0x33f9291C;
void erase_nand(unsigned long addr);
void _start(void)
{
//configure for nand flash controller
NFCONF = (0x2 < 12) | (0x7 < 8) | (0x1 < 4);
//control
//NAND flash 开始工作
NFCONT = 1;
//设置擦除地址
erase_nand(0x500000);
}
//------发送地址参照K9F2G08UOA数据手册第9页--------
void send_addr(unsigned long addr)
{
NFADDR = (addr >> 11) & 0xff;
NFADDR = (addr >> 19) & 0xff;
NFADDR = (addr >> 27) & 0x1;
}
/*****************************************
块擦除
对照K9F2G08UOA手册第28页
******************************************/
void erase_nand(unsigned long addr)
{
unsigned int stat;
//发送指令60h块擦除设置指令
NFCMMD = 0x60;
//发送三次行地址
send_addr(addr);
//nandflash ready
//发送d0擦除指令
NFCMMD = 0xd0;
//等待忙状态
while(!(NFSTAT & 0x1))
;
// 发送70h读状态指令
NFCMMD = 0x70;
//读取数据
stat = NFDATA;
//最后一位判断成功与否
if(stat & 0x1){
printf("erase nand flash device err\n");
return ;
}
printf("erase nand flash device success\n");
}
/****************************************************
写nand flash 0x500000 地址 一个字符串
主函数:write.c
****************************************************/
#define NFCONF *(volatile unsigned long *)0x4E000000
#define NFCONT *(volatile unsigned long *)0x4E000004
#define NFCMMD *(volatile unsigned long *)0x4E000008
#define NFADDR *(volatile unsigned long *)0x4E00000C
#define NFDATA *(volatile unsigned char *)0x4E000010
#define NFSTAT *(volatile unsigned long *)0x4E000020
void (*printf)(char *, ...) = 0x33f9291C;
void write_nand(char *buf, unsigned long addr, int size);
char buf[11];
void _start(void)
{
int i;
//configure for nand flash controller
NFCONF = (0x2 < 12) | (0x7 < 8) | (0x1 < 4);
//control
NFCONT = 1;
//准备一个全写a的数组
for(i = 0; i < 11; i++)
{
buf= a;
}
//往0x500000写字符串buf 11个字节
write_nand(buf, 0x500000, 11);
}
//------发送地址参照K9F2G08UOA数据手册第9页--------
void send_addr(unsigned long addr)
{
NFADDR = addr & 0xff;
NFADDR = (addr >> 8) & 0x7;
NFADDR = (addr >> 11) & 0xff;
NFADDR = (addr >> 19) & 0xff;
NFADDR = (addr >> 27) & 0x1;
}
/*****************************************
写数据
对照K9F2G08UOA手册第25页
******************************************/
void write_nand(char *buf, unsigned long addr, int size)
{
int i;
unsigned int stat;
//发80h串口数据输入指令
NFCMMD = 0x80;
//发送两次列地址,三次行地址
send_addr(addr);
//nandflash 数据准备
for(i = 0; i < (size); i++)
{
NFDATA = buf;
}
//发送10h写指令
NFCMMD = 0x10;
//等待忙状态
while(!(NFSTAT & 0x1))
;
// 发送70h读状态指令
NFCMMD = 0x70;
stat = NFDATA;
//最后一位判断成功与否
if(stat & 0x1){
printf("write nand flash device err\n");
return ;
}
printf("write nand flash device success\n");
}
/****************************************************
读nand flash 0x500000 地址 10个字节
主函数:read.c
****************************************************/
#define NFCONF *(volatile unsigned long *)0x4E000000
#define NFCONT *(volatile unsigned long *)0x4E000004
#define NFCMMD *(volatile unsigned long *)0x4E000008
#define NFADDR *(volatile unsigned long *)0x4E00000C
#define NFDATA *(volatile unsigned char *)0x4E000010
#define NFSTAT *(volatile unsigned long *)0x4E000020
void (*printf)(char *, ...) = 0x33f9291C;
void read_nand(char *buf, unsigned long addr, int size);
void _start(void)
{
char buf[11];
//configure for nand flash controller
NFCONF = (0x2 < 12) | (0x7 < 8) | (0x1 < 4);
//control
NFCONT = 1;
//往0x500000读数据
read_nand(buf, 0x500000, 10);
buf[11] = 0;
printf("read from nandflash: %s\n", buf);
}
//------发送地址参照K9F2G08UOA数据手册第9页--------
void send_addr(unsigned long addr)
{
NFADDR = addr & 0xff;
NFADDR = (addr >> 8) & 0x7;
NFADDR = (addr >> 11) & 0xff;
NFADDR = (addr >> 19) & 0xff;
NFADDR = (addr >> 27) & 0x1;
}
/*****************************************
读数据
对照K9F2G08UOA手册第23页
******************************************/
void read_nand(char *buf, unsigned long addr, int size)
{
int i;
NFCMMD = 0x00;
send_addr(addr);
NFCMMD = 0x30;
while(!(NFSTAT & 0x1 ))
;
//nandflash ready
for(i = 0; i < (size); i++)
{
buf= NFDATA;
}
}
s3c2440K9F2G08UOBNandFlash操作函 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)