Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12600 Discussions

Cannot write on-chip memory with fread.

Altera_Forum
Honored Contributor II
2,003 Views

I use DE2-70 to develop my project. My uClinux is running in SDRAM, and I want to copy a file to on-chip memory, but there is only 0 in on-chip memory, the fread() function didn't work.  

 

can anyone help me in removing this error,  

Thanks a lot ! 

 

Code: 

int main() 

FILE *fp1; 

unsigned int *mem_source = (unsigned int *)(na_onchip_mem_source|0x80000000); 

fp1 = open_file("P.dat",READ); 

long length; 

fseek(fp1, 0L, SEEK_END); 

length = ftell(fp1); 

int counter = 0; 

fseek(fp1,0L,SEEK_SET); 

fread(mem_source,length,1,fp1); 

int i; 

for(i=0;i<(length+3)/4;i++) 

printf("mem_source %d = %x\n",i,mem_source[i]); 

return 0; 

}
0 Kudos
6 Replies
Altera_Forum
Honored Contributor II
426 Views

You cannot use onchip_mem directly. Please read to a buffer, (dump/check it) then copy the content to the onchip_mem. 

 

You should check return of every file functions, such as open/seek/read/close etc. 

 

- Hippo
0 Kudos
Altera_Forum
Honored Contributor II
426 Views

Thanks. 

I want to use DMA to encrypt file between two onchip mems, and it will save some time if I can read data to onchip mem directly. Is there any other method can do that? 

 

Any of your help will be appreciated!
0 Kudos
Altera_Forum
Honored Contributor II
426 Views

You cannot handle interrupt in user space. So you might have to do it in kernel space, like using a driver or syscall. 

 

Beside, you should add return value check in your program and test it again before doing anything else. 

 

- Hippo
0 Kudos
Altera_Forum
Honored Contributor II
426 Views

 

--- Quote Start ---  

You cannot use onchip_mem directly. 

--- Quote End ---  

 

This _should_ be possible in a Kernel driver ?!?!?!? 

 

-Michael
0 Kudos
Altera_Forum
Honored Contributor II
426 Views

But I can use fwrite() to move data from on-chip mem to a file directly. 

Why fread() can't copy a file to on-chip mem? 

I tried kernel function like read(), failed too.
0 Kudos
Altera_Forum
Honored Contributor II
426 Views

Hi 

 

I wonder if the fread did work eventually to write to on chip memory? if so, what was the solution? 

 

thanks
0 Kudos
Reply