EFM32 Wonder Gecko Software Documentation  efm32wg-doc-5.1.2
NandFlash

Detailed Description

Implements a NAND flash device driver. The driver has basic functions to read and write data to a nand flash device.

When writing to the nand flash, an ECC is generated and written in the page spare area. This ECC is checked when the page is read and the data read is corrected when possible. Read and write operations can be done using DMA (configurable) at initialization.

The module is easily adapted to other NAND flash devices.

Data Structures

struct  NANDFLASH_Info_TypeDef
 NANDFLASH device information structure. More...
 

Macros

#define NAND256W3A_SPARESIZE   16
 
#define NAND_SPARE_BADBLOCK_POS   5
 
#define NAND_SPARE_ECC0_POS   6
 
#define NAND_SPARE_ECC1_POS   7
 
#define NAND_SPARE_ECC2_POS   8
 

Enumerations

enum  NANDFLASH_Status_TypeDef {
  NANDFLASH_STATUS_OK = 0,
  NANDFLASH_INVALID_DEVICE = -1,
  NANDFLASH_INVALID_ADDRESS = -2,
  NANDFLASH_WRITE_ERROR = -3,
  NANDFLASH_ECC_ERROR = -4,
  NANDFLASH_ECC_UNCORRECTABLE = -5,
  NANDFLASH_INVALID_SETUP = -6,
  NANDFLASH_NOT_INITIALIZED = -7
}
 NANDFLASH status enumerator. More...
 

Functions

bool NANDFLASH_AddressValid (uint32_t addr)
 Check if an address is valid for the nand flash device. More...
 
int NANDFLASH_CopyPage (uint32_t dstAddr, uint32_t srcAddr)
 Copy a page within the device to a new location. More...
 
NANDFLASH_Info_TypeDefNANDFLASH_DeviceInfo (void)
 Return a pointer to a NANDFLASH_Info_TypeDef structure, which contain vital nand flash device information. More...
 
int NANDFLASH_EccCorrect (uint32_t generatedEcc, uint32_t readEcc, uint8_t *data)
 Check generated ECC against ECC read from device and correct data if possible. More...
 
int NANDFLASH_EraseBlock (uint32_t address)
 Erase a block in the nand flash. More...
 
int NANDFLASH_Init (int dmaCh)
 Initialize the NANDFLASH module. More...
 
int NANDFLASH_MarkBadBlock (uint32_t address)
 Mark a block as bad. More...
 
int NANDFLASH_ReadPage (uint32_t address, uint8_t *buffer)
 Read a page from nand device. Ecc errors will be detected and corrected if possible. NANDFLASH_Info_TypeDef::ecc will be set to the ecc generated while reading the page data. NANDFLASH_Info_TypeDef::spare will be set to the content of the page spare area. More...
 
int NANDFLASH_ReadSpare (uint32_t address, uint8_t *buffer)
 Read the spare area content of a page. More...
 
int NANDFLASH_WritePage (uint32_t address, uint8_t *buffer)
 Write a page in nand device. The ECC generated while writing the page data is written in the spare area at byte positions 7, 8 and 9. More...
 

Macro Definition Documentation

#define NAND256W3A_SPARESIZE   16

Spare area size of Numonyx NAND256W3A.

Definition at line 34 of file nandflash.h.

#define NAND_SPARE_BADBLOCK_POS   5

Spare area position of bad-block marker.

Definition at line 37 of file nandflash.h.

#define NAND_SPARE_ECC0_POS   6

Spare area position of ECC byte 0 (LSB).

Definition at line 38 of file nandflash.h.

Referenced by NANDFLASH_ReadPage().

#define NAND_SPARE_ECC1_POS   7

Spare area position of ECC byte 1.

Definition at line 39 of file nandflash.h.

Referenced by NANDFLASH_ReadPage().

#define NAND_SPARE_ECC2_POS   8

Spare area position of ECC byte 2 (MSB).

Definition at line 40 of file nandflash.h.

Referenced by NANDFLASH_ReadPage().

Enumeration Type Documentation

NANDFLASH status enumerator.

Enumerator
NANDFLASH_STATUS_OK 

No errors detected.

NANDFLASH_INVALID_DEVICE 

Invalid (unsupported) flash device.

NANDFLASH_INVALID_ADDRESS 

Invalid nand flash address.

NANDFLASH_WRITE_ERROR 

Nand flash write error, block is "bad".

NANDFLASH_ECC_ERROR 

Illegal ECC value read from spare area.

NANDFLASH_ECC_UNCORRECTABLE 

Uncorrectable data error in page.

NANDFLASH_INVALID_SETUP 

Invalid parameter to NANDFLASH_Init().

NANDFLASH_NOT_INITIALIZED 

Nand module has not been initialized.

Definition at line 43 of file nandflash.h.

Function Documentation

bool NANDFLASH_AddressValid ( uint32_t  address)

Check if an address is valid for the nand flash device.

Parameters
[in]addressThe address value to check.
Returns
True if address value is valid, false otherwise.

Definition at line 156 of file nandflash.c.

References NANDFLASH_Info_TypeDef::baseAddress, and NANDFLASH_Info_TypeDef::deviceSize.

Referenced by NANDFLASH_CopyPage(), NANDFLASH_EraseBlock(), NANDFLASH_MarkBadBlock(), NANDFLASH_ReadPage(), NANDFLASH_ReadSpare(), and NANDFLASH_WritePage().

int NANDFLASH_CopyPage ( uint32_t  dstAddr,
uint32_t  srcAddr 
)

Copy a page within the device to a new location.

Parameters
[in]dstAddrThe address of the destination page.
Note
The copy operation is performed inside the nand flash. No data is read from or written to the device.
Parameters
[in]srcAddrThe address of the source page.
Returns
NANDFLASH_STATUS_OK on success, an error code enumerated in NANDFLASH_Status_TypeDef on failure.

Definition at line 188 of file nandflash.c.

References NANDFLASH_AddressValid(), NANDFLASH_INVALID_ADDRESS, NANDFLASH_NOT_INITIALIZED, NANDFLASH_STATUS_OK, and NANDFLASH_WRITE_ERROR.

NANDFLASH_Info_TypeDef* NANDFLASH_DeviceInfo ( void  )

Return a pointer to a NANDFLASH_Info_TypeDef structure, which contain vital nand flash device information.

Returns
NULL if no prior call to NANDFLASH_Init() has been made. Pointer to a NANDFLASH_Info_TypeDef on success.

Definition at line 248 of file nandflash.c.

int NANDFLASH_EccCorrect ( uint32_t  generatedEcc,
uint32_t  readEcc,
uint8_t *  data 
)

Check generated ECC against ECC read from device and correct data if possible.

Parameters
[in]generatedEccAn ECC value originating from the hardware ECC generator.
[in]readEccAn ECC value read from a page spare area.
[in]dataPointer to a page of data read from device.
Returns
NANDFLASH_STATUS_OK on success, an error code enumerated in NANDFLASH_Status_TypeDef on failure.

Definition at line 275 of file nandflash.c.

References NANDFLASH_ECC_ERROR, NANDFLASH_ECC_UNCORRECTABLE, and NANDFLASH_STATUS_OK.

Referenced by NANDFLASH_ReadPage().

int NANDFLASH_EraseBlock ( uint32_t  address)

Erase a block in the nand flash.

Note
If this function returns NANDFLASH_WRITE_ERROR, the block should be considered as "bad" and never used again.
Parameters
[in]addressBlock address.
Returns
NANDFLASH_STATUS_OK on success, an error code enumerated in NANDFLASH_Status_TypeDef on failure.

Definition at line 353 of file nandflash.c.

References NANDFLASH_AddressValid(), NANDFLASH_INVALID_ADDRESS, NANDFLASH_NOT_INITIALIZED, NANDFLASH_STATUS_OK, and NANDFLASH_WRITE_ERROR.

int NANDFLASH_Init ( int  dmaCh)

Initialize the NANDFLASH module.

Note
This function should be called before any other NANDFLASH_xxx() functions are used.
Parameters
[in]dmaChThe DMA channel to use when transfering data to/from the device. DMA will not be used for data transfers if dmaCh is set to -1.
Returns
NANDFLASH_STATUS_OK on success, an error code enumerated in NANDFLASH_Status_TypeDef on failure.

Definition at line 407 of file nandflash.c.

References DMA_CfgChannel(), DMA_CHAN_COUNT, DMA_Init(), NANDFLASH_Info_TypeDef::dmaCh, and NANDFLASH_INVALID_SETUP.

int NANDFLASH_MarkBadBlock ( uint32_t  address)

Mark a block as bad.

Note
This function writes a bad-block marker in the spare area of the first page in the block. The marker is written in the 6th byte of the spare area. A bad-block marker is any value different from 0xFF.
Parameters
[in]addressBlock address.
Returns
NANDFLASH_STATUS_OK on success, an error code enumerated in NANDFLASH_Status_TypeDef on failure.

Definition at line 442 of file nandflash.c.

References NANDFLASH_AddressValid(), NANDFLASH_INVALID_ADDRESS, NANDFLASH_NOT_INITIALIZED, and NANDFLASH_STATUS_OK.

int NANDFLASH_ReadPage ( uint32_t  address,
uint8_t *  buffer 
)

Read a page from nand device. Ecc errors will be detected and corrected if possible. NANDFLASH_Info_TypeDef::ecc will be set to the ecc generated while reading the page data. NANDFLASH_Info_TypeDef::spare will be set to the content of the page spare area.

Parameters
[in]addressPage address.
[in]bufferPointer to page data buffer.
Returns
NANDFLASH_STATUS_OK on success, an error code enumerated in NANDFLASH_Status_TypeDef on failure.

Definition at line 500 of file nandflash.c.

References NANDFLASH_Info_TypeDef::dmaCh, EBI_StartNandEccGen(), EBI_StopNandEccGen(), NANDFLASH_Info_TypeDef::ecc, NAND_SPARE_ECC0_POS, NAND_SPARE_ECC1_POS, NAND_SPARE_ECC2_POS, NANDFLASH_AddressValid(), NANDFLASH_EccCorrect(), NANDFLASH_INVALID_ADDRESS, NANDFLASH_NOT_INITIALIZED, NANDFLASH_Info_TypeDef::pageSize, NANDFLASH_Info_TypeDef::spare, and NANDFLASH_Info_TypeDef::spareSize.

int NANDFLASH_ReadSpare ( uint32_t  address,
uint8_t *  buffer 
)

Read the spare area content of a page.

Parameters
[in]addressPage address.
[in]bufferPointer to page spare area data buffer.
Returns
NANDFLASH_STATUS_OK on success, an error code enumerated in NANDFLASH_Status_TypeDef on failure.

Definition at line 581 of file nandflash.c.

References NANDFLASH_Info_TypeDef::dmaCh, NANDFLASH_AddressValid(), NANDFLASH_INVALID_ADDRESS, NANDFLASH_NOT_INITIALIZED, NANDFLASH_STATUS_OK, and NANDFLASH_Info_TypeDef::spareSize.

int NANDFLASH_WritePage ( uint32_t  address,
uint8_t *  buffer 
)

Write a page in nand device. The ECC generated while writing the page data is written in the spare area at byte positions 7, 8 and 9.

Note
If this function returns NANDFLASH_WRITE_ERROR, the block should be considered as "bad" and never used again.
Parameters
[in]addressPage address.
[in]bufferPointer to page data buffer.
Returns
NANDFLASH_STATUS_OK on success, an error code enumerated in NANDFLASH_Status_TypeDef on failure.

Definition at line 646 of file nandflash.c.

References NANDFLASH_Info_TypeDef::dmaCh, EBI, EBI_StartNandEccGen(), EBI_STATUS_AHBACT, EBI_StopNandEccGen(), NANDFLASH_Info_TypeDef::ecc, NANDFLASH_AddressValid(), NANDFLASH_INVALID_ADDRESS, NANDFLASH_NOT_INITIALIZED, NANDFLASH_STATUS_OK, NANDFLASH_WRITE_ERROR, and NANDFLASH_Info_TypeDef::pageSize.