Read/Write EPCS64 flash from Nios II

OP (Company: xlue) #4228818
Rate this post
• ▲ 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:
1
int Write_flash( alt_flash_fd* fd, float *Ks_para,int test_offset)
2
{
3
  int i;
4
  int ret_code = 0;
5

6
  alt_u8 *ptr_ks=(alt_u8*) Ks_para;
7

8
  int test_length = sizeof(Ks_para);
9

10
  // before writing in a sector, we should erase it before
11
  ret_code=alt_erase_flash_block(fd, test_offset,regions->block_size);
12
  if(!ret_code){
13

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

18
    //ret_code = alt_epcq_controller_write_block(fd, test_offset, test_offset,ptr_ks, test_length);
19
    ret_code=alt_write_flash_block(fd,test_offset,test_offset,ptr_ks,test_length);
20
  }
21
  if (ret_code)
22
  {
23
      printf( "\nERROR: function alt_write_flash failed. ret_code %d\n",ret_code);
24
      return ret_code;
25
  }
26
  return ret_code;
1
float Read_flash( alt_flash_fd* fd,int test_offset)
2
{
3
  int test_length = 4;
4
  alt_u8 data_read[test_length];
5
  int i=0;
6
  union conv2float read_flash;
7
  float Ks_para=0.0;
8
  int ret_code = 0;
9

10
    if (!ret_code)
11
    {
12
      //ret_code = alt_epcq_controller_read(fd, test_offset, data_read, test_length);
13
      ret_code=alt_read_flash(fd, test_offset, data_read, test_length);
14

15
      if(!ret_code)
16
      {
17
        for(i=0;i<4;i++){
18
          read_flash.V_In[i]=data_read[i];
19
            printf( "Flash+%d= 0x%08x\n\r",i,read_flash.V_In[i]);
20

21
        }
22

23
          Ks_para=(float)read_flash.V_Fl;
24
      
25
      }
26
    }
27

28
    alt_flash_close_dev(fd);
29
    if (ret_code)
30
    {
31
      printf( "\nERROR: function READ failed. ret_code %d\n",ret_code);
32
      //return ret_code;
33
    }
34
  return Ks_para;
35
}

Can you help please if you have any idea ?

Thank in advance.
Best regards
OP (Company: xlue) #4230267
Rate this post
• ▲ 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

Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.

Formatting
  • [c]C-Code[/c]
  • [vhdl]VHDL-Code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.