我在LPC2478芯片上实现NAND FLASH的读写。我现在已经可以将ID读出来,可是读写FLASH内的数据都是错的,不知道是哪里错了,还请高手帮忙解决 static U32 NFWaitBusy( void ) { U8 stat;
NFWrCmd(QUERYCMD) ; do { stat = NFRdDat(); } while ( !( stat & 0x40 ) ) ;
NFWrCmd(READCMD0) ; return stat & 1 ; }
static U32 NFReadID( void ) { U32 id, loop = 0; NFChipEn(); NFWrCmd( RESETCMD ); NFWrAddr( 0 ); Delay( 2 ); NFWrCmd( READIDCMD ); NFWrAddr( 0 ); while ( ( NFIsBusy() ) && ( loop < 10000 ) ) loop++; if ( loop >= 10000 ) return 0; id = NFRdDat() << 8; id |= NFRdDat(); NFChipDs();
return id; }
U32 NFEraseBlock( U32 addr ) { U8 stat;
addr &= NAND_BLOCK_MASK;
NFChipEn(); NFWrCmd( ERASECMD0 ); NFWrAddr( addr ); NFWrAddr( addr >> 8 ); if ( NandAddr ) NFWrAddr( addr >> 16 ); NFWrCmd( ERASECMD1 ); stat = NFWaitBusy(); NFChipDs();
//printf( "Erase block 0x%08x %s
" , addr , stat ? "fail" : "ok" );
return stat; }
//addr = page address void NFReadPage( U32 addr , U8* buf ) { U16 i; NFChipEn(); NFWrCmd( READCMD0 ); NFWrAddr( 0 ); NFWrAddr( addr ); NFWrAddr( addr >> 8 ); if ( NandAddr ) NFWrAddr( addr >> 16 ); // InitEcc(); NFWaitBusy(); for ( i = 0; i < NAND_SECTOR_LEN; i++ ) buf = NFRdDat(); NFChipDs(); } //addr = page address U32 NFWritePage( U32 addr , U8* buf ) { U32 i = NAND_SECTOR_LEN, stat; while (NFIsBusy()); NFChipEn(); NFWrCmd( READCMD0 ); NFWrCmd( PROGCMD0 ); NFWrAddr( 0 ); NFWrAddr( addr ); NFWrAddr( addr >> 8 ); if ( NandAddr ) NFWrAddr( addr >> 16 ); // InitEcc(); while(i--) NFWrDat( *buf++ );
NFWrCmd( PROGCMD1 ); stat = NFWaitBusy(); NFChipDs(); return stat; }
|