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++
12642 Discussions

FILE * pointer declaration hangs uClinux

Altera_Forum
Honored Contributor II
1,382 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
349 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.
0 Kudos
Altera_Forum
Honored Contributor II
349 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); 

}
0 Kudos
Reply