123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317 |
- #ifndef __BSP_NAND_H
- #define __BSP_NAND_H
- #include "stm32f2xx.h"
- typedef struct
- {
- uint8_t Maker_ID;
- uint8_t Device_ID;
- uint8_t Third_ID;
- uint8_t Fourth_ID;
- }NAND_IDTypeDef;
- typedef struct
- {
- uint16_t Zone;
- uint16_t Block;
- uint16_t Page;
- } NAND_ADDRESS_T;
- #define NAND_TYPE S34ML02G100TF
- #define HY27UF081G2A 0xADF1801D
- #define K9F1G08U0A 0xECF18015
- #define K9F1G08U0B 0xECF10095
- #define H27U1G8F2BTR 0xADF1001D
- #define H27U4G8F2DTR 0xADDC9095
- #define S34ML02G100TF 0x01DA9095
- #define NAND_UNKNOW 0xFFFFFFFF
- #define CMD_AREA (uint32_t)(1<<16)
- #define ADDR_AREA (uint32_t)(1<<17)
- #define DATA_AREA ((uint32_t)0x00000000)
- #define NAND_CMD_AREA_A ((uint8_t)0x00)
- #define NAND_CMD_AREA_B ((uint8_t)0x01)
- #define NAND_CMD_AREA_C ((uint8_t)0x50)
- #define NAND_CMD_AREA_TRUE1 ((uint8_t)0x30)
- #define NAND_CMD_WRITE0 ((uint8_t)0x80)
- #define NAND_CMD_WRITE_TRUE1 ((uint8_t)0x10)
- #define NAND_CMD_ERASE0 ((uint8_t)0x60)
- #define NAND_CMD_ERASE1 ((uint8_t)0xD0)
- #define NAND_CMD_READID ((uint8_t)0x90)
- #define NAND_CMD_LOCK_STATUS ((uint8_t)0x7A)
- #define NAND_CMD_RESET ((uint8_t)0xFF)
- #define NAND_BUSY ((uint8_t)0x00)
- #define NAND_ERROR ((uint8_t)0x01)
- #define NAND_READY ((uint8_t)0x40)
- #define NAND_TIMEOUT_ERROR ((uint8_t)0x80)
- #if NAND_TYPE==S34ML02G100TF
- #define NAND_PAGE_SIZE ((uint16_t)0x0800)
- #define NAND_BLOCK_SIZE ((uint16_t)0x0040)
- #define NAND_ZONE_SIZE ((uint16_t)0x0400)
- #define NAND_SPARE_AREA_SIZE ((uint16_t)0x0040)
- #define NAND_MAX_ZONE ((uint16_t)0x0002)
- #define NAND_ADDR_5 1
-
-
- #define NAND_CMD_COPYBACK_A ((uint8_t)0x00)
- #define NAND_CMD_COPYBACK_B ((uint8_t)0x35)
- #define NAND_CMD_COPYBACK_C ((uint8_t)0x85)
- #define NAND_CMD_COPYBACK_D ((uint8_t)0x10)
- #define NAND_CMD_STATUS ((uint8_t)0x70)
- #define MAX_PHY_BLOCKS_PER_ZONE 1024
- #define MAX_LOG_BLOCKS_PER_ZONE 1000
- #define NAND_BLOCK_COUNT 1024
- #define NAND_PAGE_TOTAL_SIZE (NAND_PAGE_SIZE + NAND_SPARE_AREA_SIZE)
- #elif NAND_TYPE == HY27UF081G2A
- #define NAND_PAGE_SIZE ((uint16_t)0x0800)
- #define NAND_BLOCK_SIZE ((uint16_t)0x0040)
- #define NAND_ZONE_SIZE ((uint16_t)0x0400)
- #define NAND_SPARE_AREA_SIZE ((uint16_t)0x0040)
- #define NAND_MAX_ZONE ((uint16_t)0x0001)
- #define NAND_ADDR_5 0
-
- #define NAND_CMD_COPYBACK_A ((uint8_t)0x00)
- #define NAND_CMD_COPYBACK_B ((uint8_t)0x35)
- #define NAND_CMD_COPYBACK_C ((uint8_t)0x85)
- #define NAND_CMD_COPYBACK_D ((uint8_t)0x10)
- #define NAND_CMD_STATUS ((uint8_t)0x70)
- #define MAX_PHY_BLOCKS_PER_ZONE 1024
- #define MAX_LOG_BLOCKS_PER_ZONE 1000
- #define NAND_BLOCK_COUNT 1024
- #define NAND_PAGE_TOTAL_SIZE (NAND_PAGE_SIZE + NAND_SPARE_AREA_SIZE)
- #elif NAND_TYPE == H27U4G8F2DTR
- #define NAND_PAGE_SIZE ((uint16_t)0x0800)
- #define NAND_BLOCK_SIZE ((uint16_t)0x0040)
- #define NAND_ZONE_SIZE ((uint16_t)0x1000)
- #define NAND_SPARE_AREA_SIZE ((uint16_t)0x0040)
- #define NAND_MAX_ZONE ((uint16_t)0x0001)
- #define NAND_ADDR_5 1
-
- #define NAND_CMD_COPYBACK_A ((uint8_t)0x00)
- #define NAND_CMD_COPYBACK_B ((uint8_t)0x35)
- #define NAND_CMD_COPYBACK_C ((uint8_t)0x85)
- #define NAND_CMD_COPYBACK_D ((uint8_t)0x10)
- #define NAND_CMD_STATUS ((uint8_t)0x70)
- #define MAX_PHY_BLOCKS_PER_ZONE 4096
- #define MAX_LOG_BLOCKS_PER_ZONE 4000
- #define NAND_BLOCK_COUNT 4096
- #define NAND_PAGE_TOTAL_SIZE (NAND_PAGE_SIZE + NAND_SPARE_AREA_SIZE)
- #else
- #define NAND_PAGE_SIZE ((uint16_t)0x0200)
- #define NAND_BLOCK_SIZE ((uint16_t)0x0020)
- #define NAND_ZONE_SIZE ((uint16_t)0x0400)
- #define NAND_SPARE_AREA_SIZE ((uint16_t)0x0010)
- #define NAND_MAX_ZONE ((uint16_t)0x0004)
- #endif
- #define NAND_BAD_BLOCK_FLAG 0x00
- #define NAND_USED_BLOCK_FLAG 0xF0
- #define BI_OFFSET 0
- #define USED_OFFSET 1
- #define LBN0_OFFSET 2
- #define LBN1_OFFSET 3
- #define VALID_SPARE_SIZE 4
- #define ADDR_1st_CYCLE(ADDR) (uint8_t)((ADDR)& 0xFF)
- #define ADDR_2nd_CYCLE(ADDR) (uint8_t)(((ADDR)& 0xFF00) >> 8)
- #define ADDR_3rd_CYCLE(ADDR) (uint8_t)(((ADDR)& 0xFF0000) >> 16)
- #define ADDR_4th_CYCLE(ADDR) (uint8_t)(((ADDR)& 0xFF000000) >> 24)
- #define NAND_OK 0
- #define NAND_FAIL 1
- #define FREE_BLOCK (1 << 12 )
- #define BAD_BLOCK (1 << 13 )
- #define VALID_BLOCK (1 << 14 )
- #define USED_BLOCK (1 << 15 )
- #define DATA_BLOCK_PERCENT 98
- #define LUT_FIRST_GOOD_BLOCK 0
- #define LUT_DATA_BLOCK_COUNT 1
- #define LUT_BAK_BLOCK_START 2
- #define LUT_GOOD_BLOCK_START 3
- typedef struct __SPARE_AREA {
- uint16_t LogicalIndex;
- uint16_t DataStatus;
- uint16_t BlockStatus;
- } SPARE_AREA;
- typedef enum {
- WRITE_IDLE = 0,
- POST_WRITE,
- PRE_WRITE,
- WRITE_CLEANUP,
- WRITE_ONGOING
- }WRITE_STATE;
- typedef enum {
- OLD_BLOCK = 0,
- UNUSED_BLOCK
- }BLOCK_STATE;
- __packed typedef struct
- {
- uint8_t Sign[4];
- uint16_t Revision;
- uint16_t Features;
- uint16_t OptionalCommands;
- uint8_t Rsv1[22];
-
- uint8_t Manufacturer[12];
- uint8_t Model[20];
- uint8_t JEDEC_ID;
- uint16_t DateCode;
- uint8_t Rsv2[13];
-
- uint32_t PageDataSize;
- uint16_t PageSpareSize;
- uint32_t PartialPageDataSize;
- uint16_t PartialPageSpareSize;
- uint32_t BlockSize;
- uint32_t LogicalUnitSize;
- uint8_t LogicalUnitNumber;
- uint8_t AddressCycles;
- uint8_t CellBits;
- uint16_t BadBlockMax;
- uint16_t BlockEndurance;
- uint8_t ValidBlocksBegin;
- uint16_t BlockEndurance2;
- uint8_t ProgramsPerPage;
- uint8_t PartialProgram;
- uint8_t ECCcorrectBits;
- uint8_t InterleavedAddrBits;
- uint8_t InterleavedOperaton;
- uint8_t Rsv3[13];
-
- uint8_t PinCapactance;
- uint16_t TimingMode;
- uint16_t ProgramCacheTimingMode;
- uint16_t PageProgTime;
- uint16_t BlockEraseTime;
- uint16_t PageReadTime;
- uint16_t ChangeColumnSetupTime;
- uint8_t Rsv4[23];
-
- uint16_t VendorRevision;
- uint8_t VendorSpecific[88];
- uint16_t IntegritaCRC;
- }PARAM_PAGE_T;
- #define WEAR_DEPTH 10
- #define PAGE_TO_WRITE (Transfer_Length/512)
- #define BAD_BALOK_TEST_CYCLE 3
- typedef struct
- {
- uint32_t ChipID;
- char ChipName[16];
- uint32_t Bad;
- uint32_t Free;
- uint32_t Used;
- }NAND_BLOCK_INFO_T;
- uint8_t NAND_Init(void);
- uint8_t NAND_Write(uint32_t _ulMemAddr, uint32_t *_pWriteBuf, uint16_t _usSize);
- uint8_t NAND_Read(uint32_t _ulMemAddr, uint32_t *_pReadBuf, uint16_t _usSize);
- uint8_t NAND_Format(void);
- void NAND_DispBadBlockInfo(void);
- uint8_t NAND_ScanBlock(uint32_t _ulPageNo);
- uint32_t NAND_FormatCapacity(void);
- uint32_t NAND_ReadID(void);
- void NAND_DispPhyPageData(uint32_t _uiPhyPageNo);
- void NAND_DispLogicPageData(uint32_t _uiLogicPageNo);
- uint8_t NAND_WriteMultiSectors(uint8_t *_pBuf, uint32_t _SectorNo, uint16_t _SectorSize, uint32_t _SectorCount);
- uint8_t NAND_ReadMultiSectors(uint8_t *_pBuf, uint32_t _SectorNo, uint16_t _SectorSize, uint32_t _SectorCount);
- void NAND_ReadONFI(uint8_t *_pBuf);
- void NAND_ReadParamPage(PARAM_PAGE_T *_pData);
- void NAND_DispParamPage(void);
- void NAND_ScanAllBadBlock(void);
- uint8_t NAND_GetBlockInfo(NAND_BLOCK_INFO_T *_pInfo);
- void NAND_MarkBadBlock(uint32_t _ulBlockNo);
- #endif
|