本帖最后由 chujunzbdx 于 2016-3-20 22:37 编辑
在Platform平台中操作Nandflash具体操作如下1.Platform平台中初始化函数为如下函数(具体操作如下具体)
- platform_platform_device_open(PLATFORM_DEVID_MT29F1G08ABCHC, 0);
复制代码
- PLATFORM_DEVICE_info *platform_device_open(uint32_t deviceid, uint32_t flags ) {
-
- PLATFORM_DEVICE_info *p_info;
- IFPRINT(platform_write("platform_device_open(deviceid=0x%x,flags=0x%x) called n", deviceid, flags));
- #if (PLATFORM_NAND_IN)
- if (deviceid == PLATFORM_DEVID_MT29F1G08ABCHC) {
- /* Disable Write protect in NAND */
- if (nandInit() != SUCCESS) {
- IFPRINT(platform_write("platform_dveice_open: Initialization failed.n"));
- return NULL;
- }
- /* Store the open flags */
- gDeviceNand.flags = flags;
- /* Set the device to point to its bad block list */
- gDeviceNand.bblist = (uint8_t *)&gDeviceNandBBlist;
- p_info = &gDeviceNand;
- if (NandGetDetails(p_info) != SUCCESS) {
- IFPRINT(platform_write("platform_device_open: Unable to read device information.n"));
- platform_errno = PLATFORM_ERRNO_BADFLASHDEV;
- return NULL;
- }
- p_info->handle = deviceid;
- return p_info;
- }
复制代码
上面操作具体为 先配置,后对Nandflash复位操作,操作完成后进行读取状态操作,并返回操作结果。 2.Platform平台中擦除函数为
- platform_device_erase_block(p_device->handle, EMIF_NANDFLASH_TEST_BLOCK) != Platform_EOK
复制代码
具体操作为
- #if (PLATFORM_NAND_IN) && (PLATFORM_NAND_WRITE_IN)
- if (deviceid == PLATFORM_DEVID_MT29F1G08ABCHC) {
- if (block_number >= gDeviceNand.block_count) {
- platform_errno = PLATFORM_ERRNO_INVALID_ARGUMENT;
- return Platform_EINVALID;
- }
- if (nandFlashBlockErase (&gDeviceNand, block_number) != SUCCESS) {
- return ( (Platform_STATUS) Platform_EFAIL);
- }
- return Platform_EOK;
- }
- #endif
复制代码
先判断NandflashID并进行传递擦除block数目。
- uint32_t nandFlashBlockErase(PLATFORM_DEVICE_info *p_device, uint32_t uiBlockNumber)
- {
- uint32_t addr = 0, ret_val = SUCCESS;
- uint8_t status;
- NandCmdSet(NAND_BLOCK_ERASE); // Block erase command
- platform_delay(25);
- /*
- * Send address of the block + page to be read
- * Address cycles = 2, Block shift = 22, Page shiht = 16
- */
- addr = PACK_ADDR(0x0, 0x0, uiBlockNumber);
- /* Properly adjust the shifts to match to the data sheet */
- NandAleSet((addr >> 16u) & 0xC0); // A17-A24 3rd Cycle; Block addr
- platform_delay(25);
- NandAleSet((addr >> 24u) & 0xFF); // A25-A26 4th Cycle; Plane addr
- platform_delay(1000);
- NandCmdSet(NAND_ERASE_CONFIRM); // Erase confirm
- platform_delay(EMIF16_WAIT_PIN_POLL_ST_DLY);
- /* Wait for erase operation to finish: 2msec */
- ret_val = NandWaitRdy(EMIF16_NAND_BLOCK_ERASE_TIMEOUT);
- if (ret_val != SUCCESS) {
- platform_errno = PLATFORM_ERRNO_DEV_TIMEOUT;
- return FAIL;
- }
- NandCmdSet(NAND_STATUS);
- platform_delay(10);
- NandReadDataByte(&status);
- if ((status & 0x01) == 1) {
- /* if SR0 bit is set to 1, there is Error - operation failed */
- platform_errno = PLATFORM_ERRNO_DEV_FAIL;
- return FAIL;
- }
- return SUCCESS;
- }
复制代码
擦出操作为按块擦除:发送擦除命令,发送块地址(主要为3个地址循环),发送擦除确认命令,最后判断擦除返回状态命令。
2
|
|
|
|