📄 nand_test.c
字号:
#include "lpc2468.h"
#include "type.h"
#include "target.h"
#include "uart0.h"
#include "k9f2g8.h"
BYTE ReadBuf[NF_PAGE_SIZE], WriteBuf[NF_PAGE_SIZE];
extern BYTE InvalidBlockTable[K9F2G08_BLOCKNUM];
int main()
{
DWORD FlashID;
DWORD i;
TargetResetInit();
UART0Init(9600);
/* NAND初始化 */
NF_Init();
NF_Reset();
/* ID 校验 */
FlashID = NF_ReadID();
if ( (FlashID & 0xFFFF0000) != (K9F2G08_ID &0xFFFF0000))
{
UART0_puts("NAND Flash ID error!\r\n");
while( 1 );
}
/* NAND Flash 擦除 */
for ( i = 0; i < 1; i++ )
{
if ( NF_EraseBlock( i ) == FALSE )
{
UART0_puts("NAND Flash block erase error!\r\n");
while( 1 );
}
}
/* For the test program, the pattern for the whole page 2048 bytes
is organized as: 0x0, 0x1, ... 0xFF, 0x0, 0x01...... */
for ( i = 0; i < NF_PAGE_SIZE; i++ )
{
ReadBuf[i] = 0;
WriteBuf[i] = i;
}
if ( NF_CheckValidBlock() == FALSE )
{
UART0_puts("NAND Flash valid block check error!\r\n");
while ( 1 );
}
/* If it's a valid block, program all the pages of this block,
read back, and finally validate. */
/* simple program to program the block 0 and page 0 */
if ( InvalidBlockTable[0] == 0 )
{
if ( NF_PageProgram( 0, 0, &WriteBuf[0] ) == FALSE )
{
UART0_puts("NAND Flash page program error!\r\n");
while ( 1 );
}
if ( NF_PageRead( 0, 0, &ReadBuf[0] ) == FALSE )
{
UART0_puts("NAND Flash page read error!\r\n");
while ( 1 );
}
/* Comparison read and write buffer */
for ( i = 0; i < NF_RW_PAGE_SIZE; i++ )
{
if ( ReadBuf[i] != WriteBuf[i] )
{
UART0_puts("NAND Flash Read/Write error!\r\n");
while ( 1 );
}
}
}
UART0_puts("NAND Flash test successed!\r\n");
while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -