Altera_Forum
Honored Contributor
10 years agoRead/Write EPCS64 flash from Nios II
Hi all,
Actually, I'm trying to write/read my flash device using the HAL functions. After opening the device, I write into the EPCS64 using alt_write_flash_block, then i read it using alt_read_flash. The problem i have is that the data read/ written showen in the Nios II console are not the same. The code for writing and reading is below:int Write_flash( alt_flash_fd* fd, float *Ks_para,int test_offset)
{
int i;
int ret_code = 0;
alt_u8 *ptr_ks=(alt_u8*) Ks_para;
int test_length = sizeof(Ks_para);
// before writing in a sector, we should erase it before
ret_code=alt_epcq_controller_erase_block(fd, test_offset);
if(!ret_code){
for(i=0;i<test_length;i++){
printf( "data_written= 0x%08x\n\r",i,ptr_ks);
}
ret_code=alt_write_flash_block(fd,test_offset,test_offset,ptr_ks,test_length);
}
if (ret_code)
{
printf( "\nERROR: function alt_write_flash failed. ret_code %d\n",ret_code);
return ret_code;
}
return ret_code;
} float Read_flash( alt_flash_fd* fd,int test_offset)
{
int test_length = 4;
alt_u8 data_read;
int i=0;
union conv2float read_flash;
float Ks_para=0.0;
int ret_code = 0;
if (!ret_code)
{
ret_code=alt_read_flash(fd, test_offset, data_read, test_length);
if(!ret_code)
{
for(i=0;i<4;i++){
read_flash.V_In=data_read;
printf( "Flash+%d= 0x%08x\n\r",i,read_flash.V_In);
}
Ks_para=read_flash.V_Fl;
}
}
if (ret_code)
{
printf( "\nERROR: function READ failed. ret_code %d\n",ret_code);
}
return Ks_para;
} Do you have an idea why ? Thank you in advance. Best regards