Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Altera_Forum
Honored Contributor I
835 Views

Read/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
0 Kudos
1 Reply
Altera_Forum
Honored Contributor I
59 Views

I want just to precise that in debug mode, I can see that the location where I write changed but with wrong values. 

For example, I'm writing 0x40228f5c to 04FC0000 address, but I can see this :  

04FC0000 2E479120 FFFFFFFF FFFFFFFF FFFFFFFF  

 

I don't find an explication why. 

 

Do you have any suggestion please? 

 

Thanks  

 

Best regards
Reply