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

C code freezes/Pauses while execution

Altera_Forum
Honored Contributor II
1,769 Views

I have a C application in which I have two adjacent print statements. But only the top one is printed and not the second one. 

What could be reason. My C code is quiet bigger and complex in size. Is their any restriction on code size we can execute in a quarts web edition? 

 

I tried a lot but couldn't find the reason. 

 

Please reply.
0 Kudos
10 Replies
Altera_Forum
Honored Contributor II
576 Views

Hi, it is difficult to help you .... with a very little information. 

Could you post your piece of code ? 

 

 

--- Quote Start ---  

Is their any restriction on code size we can execute in a quarts web edition? 

--- Quote End ---  

 

Quartus is for Hardware : the code (VHDL, Verilog...) size is not limited, but the resources are limited. 

Nios II SBT is for embedded Software : the code size is limited by the C compiler, the software is limited by your target resources (ROM, RAM...)
0 Kudos
Altera_Forum
Honored Contributor II
576 Views

Hi, 

Below is the part of code where execution stops. I also have the same piece of code in upper part of the same C file but it is working absolutely fine. 

Here, I can see only "hi" printed on my console and nothing after that. Ideally it should print "BREAKED" & "1" & then break the loop & execute the following part of my C file. But it doesn't. PFA attachment for the error on console. Sometime I get this error and the console exits and sometime it gets freeze. 

 

while (1) 

for (i=0;i<1000000;i=i+1) //MAIN 

L5 = IORD(OnChip,5); 

L6 = IORD(OnChip,6); 

L7 = IORD(OnChip,7); 

L8 = IORD(OnChip,8); 

//printf("\n%d %d %d %d",L5,L6,L7,L8); 

if (L5 && L6 && L7 && L8) 

printf("\n hi"); 

printf("\nBREAKED"); 

printf("\n1"); 

break; 

printf("\n2"); 

 

I gave lot of try's and seems some issue with compiler or any other stuff. The code is absolutely fine. I don't know why it freezes at that time. 

Can anyone tell me how to debug the C code, I tried but couldn't do that.
0 Kudos
Altera_Forum
Honored Contributor II
576 Views

Try to add "fflush(stdout);" after the last printf.

0 Kudos
Altera_Forum
Honored Contributor II
576 Views

It says "undefined reference to fflush" 

 

Is there some specific header to be included? I already included <stdio.h>.
0 Kudos
Altera_Forum
Honored Contributor II
576 Views

fflush() is declared in <stdio.h> Not sure what your problem is compiling with it. 

 

Your screenshot shows garbage characters in the output after "hi". Your screenshot also shows this is a multi-core project. Those two facts make me think that your problem is more likely something like memory corruption causing the progrm you are trying to debug to crash, or possibly multiple cores accessing the same serial port? I would try the basic debugging technique of removing large chunks of code until your printf()'s start working again to get an idea of where the issue might be. I would start with just a single core executing.
0 Kudos
Altera_Forum
Honored Contributor II
576 Views

Hello, 

 

I implemented the whole application on single core and it works fine. But when I just add one more core, I start facing the issues mentioned above. Code starts behaving weird. And I observed that, when my slave core(which i added later) is done with its operation/execution, the main core freezes. As per my app, slave core returns some values and master should continue its operation on returned values. I added print statements to debug, but the master stops printing once slave is done with its execution. 

 

Please suggest. Having hard time with this.
0 Kudos
Altera_Forum
Honored Contributor II
576 Views

My general suggestion would be to further reduce your application(s) to the minimum needed to reliably reproduce the problem, and then debug it. 

For example, you ought to be able to (eventually) find a breakpoint in the slave that as soon as you resume execution causes the master to fail. Then it is simply a matter of single-stepping through a relatively small section of code to learn what is the root of the problem. 

 

From your description, I would be suspicious of a resource having been accidentally shared between the cores (the JTAG UART, some RAM, etc. etc. etc.)
0 Kudos
Altera_Forum
Honored Contributor II
576 Views

Manually download your NIOS application & run it , to see the console message. 

 

1) Open nios2 console windows 

2)# nios2-download app.elf -g -r && nios2-terminal 

 

I think that NIOS2-IDE has some problem ...
0 Kudos
Altera_Forum
Honored Contributor II
576 Views

Hello,  

 

I was doing manually via NIOSII console.
0 Kudos
Altera_Forum
Honored Contributor II
576 Views

I'm getting the same "undefined reference to fflush" error as well. Did you find a way to fix it?

0 Kudos
Reply