使用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都没有报错,进行到擦除时出错了。