This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

320c6657 擦除nand失败

使用platform库中的nand擦除函数:

Platform_STATUS platform_device_erase_block(PLATFORM_DEVHANDLE handle,
                                            uint32_t block_number);

擦除flash中的某一块时失败,函数没有返回Platform_EOK。请问这是什么原因?具体代码如下:

uint8_t     *buf, * buf_orig;
    uint32_t    offset;
 PLATFORM_DEVICE_info  *p_device;
 uint32_t                i;

 buf_orig = NULL;

 /* Open the device */
    p_device = platform_device_open(PLATFORM_DEVID_MT29F1G08ABCHC, 0);
    if (p_device == NULL) {
       printf("test_nand: Could not open NAND device  errno = 0x%x \n", platform_errno);
       goto NAND_TEST_DONE;
    }

    /* We need a buffer to read a page in */
    buf_orig = (uint8_t *) malloc(p_device->page_size);
    if (buf_orig == NULL) {
        printf("test_nand: Can't allocate %d bytes for buf_orig\n", p_device->page_size);
        goto NAND_TEST_DONE;
    }

    /* Read the test block page 0 - save the contents so we can write back */
    platform_blocknpage_to_offset(p_device->handle, &offset, args->nand_test_block_number, 0 );
    if (platform_device_read(p_device->handle, offset, buf_orig, p_device->page_size) != Platform_EOK) {
        printf("test_nand: Unable to read block %d page %d errno = 0x%x\n", args->nand_test_block_number, 0, platform_errno );
        goto NAND_TEST_DONE;
    }
    printf("buf_orig:\n");
    buf=buf_orig;
    for(i=0;i<2048;i++){
     printf("%x ",*buf++);
    }
    printf("\n");

 

    /* Erase our test block so we can write to it */
    if (platform_device_erase_block(p_device->handle, args->nand_test_block_number) != Platform_EOK) {
        printf("test_nand: Unable to erase (%d) block %d errno = 0x%x\n", args->nand_test_block_number, platform_errno);
        goto NAND_TEST_DONE;
    }

    /* Fill in a test pattern */
    buf=buf_orig;
    for(i=0;i<2048;i++){
     *buf++=0xd8;
    }
    buf=buf_orig;
    printf("after memset:\n");
    for(i=0;i<2048;i++){
     printf("%x ",*buf++);
    }
    printf("\n");

    /* Write the test pattern to the test block */
    platform_blocknpage_to_offset(p_device->handle, &offset, args->nand_test_block_number, 0 );
    if (platform_device_write(p_device->handle, offset, buf_orig, p_device->page_size) != Platform_EOK) {
        printf("test_nand: Unable to write (%d) block %d page %d errno = 0x%x \n", args->nand_test_block_number, 0, platform_errno);
        goto NAND_TEST_DONE;
    }
    platform_delay(1000);

    //memset(buf2, 0xff, p_device->page_size);
    platform_blocknpage_to_offset(p_device->handle, &offset, args->nand_test_block_number, 0);
    if (platform_device_read(p_device->handle, offset, buf_orig, p_device->page_size) != Platform_EOK) {
        printf("test_nand: Unable to read block %d page %d errno = 0x%x\n", args->nand_test_block_number, 0, platform_errno );
        goto NAND_TEST_DONE;
    }
    platform_delay(1000);

    printf("after read:\n");
    buf=buf_orig;
    for(i=0;i<2048;i++){
     printf("%x ",*buf++);
    }
    printf("\n");

_DONE:

 if (buf_orig)
  free(buf_orig);

    platform_device_close(p_device->handle);

    return;

设备打开、读取nand都没有报错,进行到擦除时出错了。

  • hi allen

        我没有仔细看你的程序,但从你描述“设备打开、读取nand都没有报错,进行到擦除时出错了”,你可以看下你使用的flash的datasheet,确认在擦除前是否需要unprotect?

  • 谢谢您的回复。但是根据我的测试,并没有发现类似“锁”的东西,因为这个代码单独放到一个工程中可以正确执行,但是我把他加到我的总工程中就无法正确执行了。我还有个问题,我的总工程中涉及到串口通信的中断函数,不知道串口的中断是否会影响到对nand的操作。

  • 你好,我测试很久后发现似乎是出错的工程platform的库没有包对。当正确包含了库之后,erase操作可以执行了!但是紧接着write操作又失败了。具体如下:

    test_nand: Unable to write (512) block 0 page 48 errno = 0x822860

    我是向512块进行写的。代码相同,在单独的那个工程中写是成功的,但是复制到我的大工程中write就不能正确执行了。请问您有何高见?