NANDFlash
Detailed Description
Driver for Numonyx NAND256W3A NAND Flash devices.
Driver for Numonyx NAND256W3A NAND Flash the device on EFM32GG STK3700 kits.
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 can easily be modified to suit other NAND Flash devices.
Data Structures |
|
struct | NANDFLASH_Info_TypeDef |
NANDFLASH device information structure.
|
|
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.
|
|
Functions |
|
bool | NANDFLASH_AddressValid (uint32_t address) |
Check if an address is valid for the nand flash device.
|
|
int | NANDFLASH_CopyPage (uint32_t dstAddr, uint32_t srcAddr) |
Copy a page within the device to a new location.
|
|
NANDFLASH_Info_TypeDef * | NANDFLASH_DeviceInfo (void) |
Return a pointer to a
NANDFLASH_Info_TypeDef
structure, which contain vital nand flash device information.
|
|
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.
|
|
int | NANDFLASH_EraseBlock (uint32_t address) |
Erase a block in the nand flash.
|
|
int | NANDFLASH_Init (int dmaCh) |
Initialize the NANDFLASH module.
|
|
int | NANDFLASH_MarkBadBlock (uint32_t address) |
Mark a block as bad.
|
|
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.
|
|
int | NANDFLASH_ReadSpare (uint32_t address, uint8_t *buffer) |
Read the spare area content of a page.
|
|
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.
|
|
Macro Definition Documentation
#define NAND256W3A_SPARESIZE 16 |
Spare area size of Numonyx NAND256W3A.
Definition at line
48
of file
nandflash.h
.
#define NAND_SPARE_BADBLOCK_POS 5 |
Spare area position of bad-block marker.
Definition at line
51
of file
nandflash.h
.
#define NAND_SPARE_ECC0_POS 6 |
Spare area position of ECC byte 0 (LSB).
Definition at line
52
of file
nandflash.h
.
Referenced by NANDFLASH_ReadPage() .
#define NAND_SPARE_ECC1_POS 7 |
Spare area position of ECC byte 1.
Definition at line
53
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
54
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
57
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] address
The address value to check.
- Returns
- True if address value is valid, false otherwise.
Definition at line
176
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] dstAddr
The 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] srcAddr
The address of the source page.
- Returns
- NANDFLASH_STATUS_OK on success, an error code enumerated in NANDFLASH_Status_TypeDef on failure.
Definition at line
206
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
264
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] generatedEcc
An ECC value originating from the hardware ECC generator. [in] readEcc
An ECC value read from a page spare area. [in] data
Pointer 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
290
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] address
Block address.
- Returns
- NANDFLASH_STATUS_OK on success, an error code enumerated in NANDFLASH_Status_TypeDef on failure.
Definition at line
368
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] dmaCh
The 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
420
of file
nandflash.c
.
References 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] address
Block address.
- Returns
- NANDFLASH_STATUS_OK on success, an error code enumerated in NANDFLASH_Status_TypeDef on failure.
Definition at line
453
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] address
Page address. [in] buffer
Pointer to page data buffer.
- Returns
- NANDFLASH_STATUS_OK on success, an error code enumerated in NANDFLASH_Status_TypeDef on failure.
Definition at line
509
of file
nandflash.c
.
References NANDFLASH_Info_TypeDef::dmaCh , 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] address
Page address. [in] buffer
Pointer 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
580
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] address
Page address. [in] buffer
Pointer to page data buffer.
- Returns
- NANDFLASH_STATUS_OK on success, an error code enumerated in NANDFLASH_Status_TypeDef on failure.
Definition at line
639
of file
nandflash.c
.
References NANDFLASH_Info_TypeDef::dmaCh , NANDFLASH_Info_TypeDef::ecc , NANDFLASH_AddressValid() , NANDFLASH_INVALID_ADDRESS , NANDFLASH_NOT_INITIALIZED , NANDFLASH_STATUS_OK , NANDFLASH_WRITE_ERROR , and NANDFLASH_Info_TypeDef::pageSize .