Nios® II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
Announcements
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.
12410 Discussions

FILE * pointer declaration hangs uClinux

Altera_Forum
Honored Contributor II
1,108 Views

Hi all,  

 

I'm running uClinux (noMMU) on DE0 Nano. I'm trying to create a file and write to it via a C program. Example code: 

 

int main(void) 

FILE * fp; 

fp = fopen("test.txt","w+"); 

 

As soon as I run this the OS hangs. If I add a printf after the FILE * fp; command, nothing is printed. The OS hangs at the file declaration. Any ideas?
0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
75 Views

That can't be. Most likely fopen is dead-locked and preventing the stdout from flushing out the printf. Try doing a fflush (stdout) after the printf and before the fopen. I am assuming that main is getting called and that if the fopen call is not there, you do see the printf output. 

If the fopen is hanging, something must be wrong with the device it is trying to access. I am not too familiar with the uClinux/DE0 setup combination.
Altera_Forum
Honored Contributor II
75 Views

So I was going to try your suggestions but first thought I would remove ALL other code in the program. It worked!! Beginner mistake. I'll have to start adding my code and see where the train comes off the tracks. If it is relevant to this post I'll report back. Thanks for your reply. 

 

BTW, for other readers, the following code creates a text file and opens it for editing... 

 

int main(void) 

FILE * fp; 

fp = fopen("/bin/test_data.txt","w+"); 

//your code here 

fclose(fp); 

}
Reply