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

Read host PC data using HAL

I've spent the past 8 hours trying to read data from my host Windows PC using a C program running on NIOSII. And finally I found light with that Host File System business! I thought it would be good to share this with you because the settings are not that obvious, and I am sure there are many beginners like me who will struggle to find this on NIOSII SBT 10.1. 

 

So here goes. Go to NIOSII->BSP Editor -> Software Packages -> altera_hostfs and enable it! It will tell you /mnt/host/ as default. Just leave it as such.  

 

Then copy your data file (e.g testb.txt) in the folder where the C code is. Next you can insert the following lines in your C code to read the file: 

 

FILE* finput; 

finput = fopen ("/mnt/host/testb.txt", "r"); 

 

and then run it in debug mode in NIOSII hardware. 

 

OK, now my other question is: How to enter data from the host PC to the NIOS CPU when not in debug mode? Is that possible? Or do I have to copy data first to a memory or sd card available on my development kit and then try to access it from the code?
0 Kudos
2 Replies
Altera_Forum
Honored Contributor I
56 Views

It may not possible to send file to CPU if it is not in the debug mode. 

Just because this method is using gdb. 

 

This function only available when you use the debug mode.
Altera_Forum
Honored Contributor I
56 Views

 

--- Quote Start ---  

I've spent the past 8 hours trying to read data from my host Windows PC using a C program running on NIOSII. And finally I found light with that Host File System business! I thought it would be good to share this with you because the settings are not that obvious, and I am sure there are many beginners like me who will struggle to find this on NIOSII SBT 10.1. 

 

So here goes. Go to NIOSII->BSP Editor -> Software Packages -> altera_hostfs and enable it! It will tell you /mnt/host/ as default. Just leave it as such.  

 

Then copy your data file (e.g testb.txt) in the folder where the C code is. Next you can insert the following lines in your C code to read the file: 

 

FILE* finput; 

finput = fopen ("/mnt/host/testb.txt", "r"); 

 

and then run it in debug mode in NIOSII hardware. 

 

OK, now my other question is: How to enter data from the host PC to the NIOS CPU when not in debug mode? Is that possible? Or do I have to copy data first to a memory or sd card available on my development kit and then try to access it from the code? 

--- Quote End ---  

 

 

Hi 

 

I have a problem with the fopen, fclose, getc commands when I build my project, but I followed your instructions. Do you know what could be the problem? Did you have "small_c_library" enabled? 

 

Please help, i'm so desperate....
Reply