nandps
Vitis Drivers API Documentation
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
xnandps_example.c File Reference

Overview

This file contains a design example using the NAND driver (XNandPs).

This example tests the block erase, block read and block write features. The flash blocks are erased and written. The data is read back and compared with the data written for correctness. The bad blocks are not erased/programmed.

Note

None.

MODIFICATION HISTORY:
Ver   Who  Date        Changes


1.00 nm 12/10/2010 First release. 1.01a nm 28/02/2012 Modified the test offsets. ms 04/10/17 Modified Comment lines to follow doxygen rules 2.8 akm 07/06/23 Add support for system device-tree flow. 2.11 vlt 12/14/25 Update Doxygen comments to include SDT flow details.

#include <stdio.h>
#include <stdlib.h>
#include <xil_types.h>
#include <xil_printf.h>
#include <xparameters.h>
#include <xnandps.h>
#include <xnandps_bbm.h>

Macros

#define NAND_TEST_START_BLOCK   64
 Starting block to test. More...
 
#define NAND_TEST_NUM_BLOCKS   16
 Number of blocks to test. More...
 
#define NAND_TEST_BLOCK_SIZE   0x20000
 Test Block Size, must be same as the flash block size. More...
 

Functions

int NandReadWriteExample (UINTPTR BaseAddress)
 This function runs a test on the NAND flash device using the basic driver functions. More...
 
int main (void)
 Main function to execute the Nand Flash read write example. More...
 

Variables

u8 ReadBuffer [NAND_TEST_BLOCK_SIZE]
 Block sized Read buffer. More...
 
u8 WriteBuffer [NAND_TEST_BLOCK_SIZE]
 Block sized write buffer. More...
 

Macro Definition Documentation

#define NAND_TEST_BLOCK_SIZE   0x20000

Test Block Size, must be same as the flash block size.

Referenced by NandReadWriteExample().

#define NAND_TEST_NUM_BLOCKS   16

Number of blocks to test.

Referenced by NandReadWriteExample().

#define NAND_TEST_START_BLOCK   64

Starting block to test.

Referenced by NandReadWriteExample().

Function Documentation

int main ( void  )

Main function to execute the Nand Flash read write example.

Returns
  • XST_SUCCESS if the example has completed successfully.
  • XST_FAILURE if the example has failed.
Note
None.

References NandReadWriteExample().

int NandReadWriteExample ( UINTPTR  BaseAddress)

This function runs a test on the NAND flash device using the basic driver functions.

The function does the following tasks:

  • Initialize the driver.
  • Erase the blocks.
  • Write in to all the blocks.
  • Read back the data from the blocks.
  • Compare the data read against the data Written.
Parameters
BaseAddresscontains the base address of the device
Returns
  • XST_SUCCESS if successful.
  • XST_FAILURE if failed.
Note
-In XSCT/classic flow, DeviceId is used to look up the device configuration. -When bad blocks are encountered, they are not erased and programmed.

References XNandPs_Geometry::BlockSize, XNandPs_Config::FlashBase, XNandPsTag::Geometry, NAND_TEST_BLOCK_SIZE, NAND_TEST_NUM_BLOCKS, NAND_TEST_START_BLOCK, ReadBuffer, XNandPs_Config::SmcBase, WriteBuffer, XNandPs_CfgInitialize(), XNandPs_EraseBlock(), XNandPs_IsBlockBad(), XNandPs_LookupConfig(), XNandPs_Read(), and XNandPs_Write().

Referenced by main().

Variable Documentation

u8 ReadBuffer[NAND_TEST_BLOCK_SIZE]

Block sized Read buffer.

u8 WriteBuffer[NAND_TEST_BLOCK_SIZE]

Block sized write buffer.