EmbDev.net

Forum: FPGA, VHDL & Verilog Read/Write EPCS64 flash from Nios II


Author: jeorges FrenchRivera (Company: xlue) (khal1985)
Posted on:

Rate this post
0 useful
not useful
Hi all,

Actually, I'm trying to write/read my flash device using the HAL 
functions.

After opening the device, I write data into the EPCS64 using 
alt_write_flash_block, then i read it back using alt_read_flash.
The problem i have is that the data read/ written shown 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_erase_flash_block(fd, test_offset,regions->block_size);
  if(!ret_code){

    for(i=0;i<test_length;i++){
        printf( "data_written[%d]= 0x%08x\n\r",i,ptr_ks[i]);
    }

    //ret_code = alt_epcq_controller_write_block(fd, test_offset, test_offset,ptr_ks, test_length);
    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[test_length];
  int i=0;
  union conv2float read_flash;
  float Ks_para=0.0;
  int ret_code = 0;

    if (!ret_code)
    {
      //ret_code = alt_epcq_controller_read(fd, test_offset, data_read, test_length);
      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[i]=data_read[i];
            printf( "Flash+%d= 0x%08x\n\r",i,read_flash.V_In[i]);

        }

          Ks_para=(float)read_flash.V_Fl;
      
      }
    }

    alt_flash_close_dev(fd);
    if (ret_code)
    {
      printf( "\nERROR: function READ failed. ret_code %d\n",ret_code);
      //return ret_code;
    }
  return Ks_para;
}

Can you help please if you have any idea ?

Thank in advance.
Best regards

Author: jeorges FrenchRivera (Company: xlue) (khal1985)
Posted on:

Rate this post
0 useful
not useful
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

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [vhdl]VHDL code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.