Implements a NAND flash device driver. More...
![]() |
Data Structures | |
struct | NANDFLASH_Info_TypeDef |
NANDFLASH device information structure. More... | |
Defines | |
#define | NAND256W3A_SPARESIZE 16 |
Spare area size of Numonyx NAND256W3A. | |
#define | NAND_SPARE_BADBLOCK_POS 5 |
Spare area position of bad-block marker. | |
#define | NAND_SPARE_ECC0_POS 6 |
Spare area position of ECC byte 0 (LSB). | |
#define | NAND_SPARE_ECC1_POS 7 |
Spare area position of ECC byte 1. | |
#define | NAND_SPARE_ECC2_POS 8 |
Spare area position of ECC byte 2 (MSB). | |
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. | |
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. | |
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. |
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.
#define NAND256W3A_SPARESIZE 16 |
Spare area size of Numonyx NAND256W3A.
Definition at line 52 of file nandflash.h.
#define NAND_SPARE_BADBLOCK_POS 5 |
Spare area position of bad-block marker.
Definition at line 55 of file nandflash.h.
#define NAND_SPARE_ECC0_POS 6 |
Spare area position of ECC byte 0 (LSB).
Definition at line 56 of file nandflash.h.
Referenced by NANDFLASH_ReadPage().
#define NAND_SPARE_ECC1_POS 7 |
Spare area position of ECC byte 1.
Definition at line 57 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 58 of file nandflash.h.
Referenced by NANDFLASH_ReadPage().
NANDFLASH status 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 61 of file nandflash.h.
bool NANDFLASH_AddressValid | ( | uint32_t | address | ) |
Check if an address is valid for the nand flash device.
[in] | address | The address value to check. |
Definition at line 174 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.
[in] | dstAddr | The address of the destination page. |
[in] | srcAddr | The address of the source page. |
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.
Definition at line 266 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.
[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. |
Definition at line 293 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.
[in] | address | Block address. |
Definition at line 371 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.
[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. |
Definition at line 425 of file nandflash.c.
References NANDFLASH_Info_TypeDef::dmaCh, and NANDFLASH_INVALID_SETUP.
int NANDFLASH_MarkBadBlock | ( | uint32_t | address | ) |
Mark a block as bad.
[in] | address | Block address. |
Definition at line 460 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.
[in] | address | Page address. |
[in] | buffer | Pointer to page data buffer. |
Definition at line 518 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.
[in] | address | Page address. |
[in] | buffer | Pointer to page spare area data buffer. |
Definition at line 599 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.
[in] | address | Page address. |
[in] | buffer | Pointer to page data buffer. |
Definition at line 664 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.