Forum Discussion
Altera_Forum
Honored Contributor
10 years agoHi again,
I'm actually trying to READ/Write the Flash EPCS64 device from NIOS II , unfortunately i doesn't work correctly. First of all i open my device using this code :int epcs_open(void)
{
int ret_code;
int i;
fd = alt_flash_open_dev("/dev/epcq_controller_avl_mem");
if (fd== NULL)
{
printf("** Can't open flash device **\n\n");
}else
{
printf("\n<----> Running Flash Tests <---->\n\r");
printf("-Testing flash info retrieval...");
ret_code = alt_get_flash_info(fd, ®ions, &number_of_regions);
//ret_code =alt_epcq_controller_get_info(fd, ®ions, &number_of_regions);
if (ret_code)
{
printf( "\nERROR: function alt_get_flash_info failed. ret_code %d\n",ret_code);
goto finished;
}
printf("\n\rThis is NIOSII Board Designed by flash Logic\n\r");
printf("Flash name %s\n\r",fd->name);
printf("This flash has %d erase regions\n\r", number_of_regions);
for (i=0;i<number_of_regions;i++)
{
printf("Start 0x%08x End 0x%08x Number of Blocks %3d Block Size 0x%08x\n\r",(regions+i)->offset,
(regions+i)->region_size+(regions+i)->offset,
(regions+i)->number_of_blocks,
(regions+i)->block_size);
}
}
printf("passed.\n\r");
printf("Exiting Flash Tests\n\r");
finished:
alt_flash_close_dev(fd);
return ret_code;
} it's ok. Then i Write/read the device using the code below: int test_programming( alt_flash_fd* fd, int test_offset)
{
int i;
alt_u8 data_written;
alt_u8 data_read;
int ret_code = 0;
int test_length = sizeof(data_written);
for(i=0;i<sizeof(data_written);i++){
data_written = i;
printf( "data_written= 0x%08x\n\r",i,data_written);
}
ret_code = alt_write_flash(fd, test_offset, data_written, test_length);
if (!ret_code)
{
ret_code = alt_read_flash(fd, test_offset, data_read, test_length);
if(!ret_code)
{
for(i=0;i<sizeof(data_read);i++)
printf( "Flash+%d= 0x%08x\n\r",i,data_read);
}
}
printf("*");
if (ret_code)
{
printf( "\nERROR: function alt_write_flash failed. ret_code %d\n",
ret_code);
return ret_code;
}
return ret_code;
} The problem is that the written/read data is not the same as shown the picture joined. Do you have any idea why ? Best regards.