EFM32 Happy Gecko Software Documentation
efm32hg-doc-5.1.2
|
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_TypeDef * | NANDFLASH_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... | |
#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().
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.
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 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.
[in] | dstAddr | The address of the destination page. |
[in] | srcAddr | The address of the source page. |
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.
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.
[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 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.
[in] | address | Block address. |
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.
[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 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.
[in] | address | Block address. |
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.
[in] | address | Page address. |
[in] | buffer | Pointer to page data buffer. |
Definition at line 500 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 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.
[in] | address | Page address. |
[in] | buffer | Pointer to page data buffer. |
Definition at line 646 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.