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

NiosII printf() not printing correctly

Altera_Forum
Honored Contributor II
2,505 Views

Hi all, 

 

I have a problem with the printf() commands not printing. If I un-tick the "small C library" option in the HAL, I don't receive any output to the NiosII console, but the program is working correctly when I check it in the debugger. However, if I use the "small C library" option I do receive the output, but the numbers (integers) are printed incorrectly (i.e. 128 is printed as 111, 1024 is printed as 1111, and so on). I have two NiosII processors and each of them has a separate JTAG UART in the Qsys system. 

 

Has anyone encountered such a problem? Any idea how to resolve this? 

 

Cheers, 

Isuru
0 Kudos
14 Replies
Altera_Forum
Honored Contributor II
1,707 Views

Hi, 

could you post your piece of code employing printf() ?
0 Kudos
Altera_Forum
Honored Contributor II
1,707 Views

Are strings printed correctly? Or is everything wrong??

0 Kudos
Altera_Forum
Honored Contributor II
1,707 Views

 

--- Quote Start ---  

Hi, 

could you post your piece of code employing printf() ? 

--- Quote End ---  

 

 

It's like a simple formatted print statement.. 

 

int main() 

int k = 128; 

printf("Value of K is [%i]",k); 

return 0; 

}
0 Kudos
Altera_Forum
Honored Contributor II
1,707 Views

 

--- Quote Start ---  

Are strings printed correctly? Or is everything wrong?? 

--- Quote End ---  

 

 

Yes, the string are printing correctly. Only the numbers with one or more digits are giving trouble. For example, it prints "66" instead of "64" and "111" instead of "128". Also, it printed "553333333" where it should have printed "563353127".
0 Kudos
Altera_Forum
Honored Contributor II
1,707 Views

Try using %d instead of %i

0 Kudos
Altera_Forum
Honored Contributor II
1,707 Views

Might be that the divide operation is failing. 

Maybe you code is using the divide instructions, but it isn't present in your cpu. 

But %i isn't a standard format.
0 Kudos
Altera_Forum
Honored Contributor II
1,707 Views

 

--- Quote Start ---  

I have two NiosII processors 

--- Quote End ---  

 

Maybe it is a source of incorrect "value" : memory of integer "K" could be overwritten. 

"Strings" are located inline or at the end of program section, whereas data are in other section. 

It is a clue, i am not expert in multi processor. 

Good luck
0 Kudos
Altera_Forum
Honored Contributor II
1,707 Views

In addition to the suggestions about your 2nd processor, does your BSP include any custom HAL components (or, misconfigured vendor-supplied components) whose initialization functions might be causing memory corruption prior to execution of your main() ? 

 

For example, a table initialization that overruns it's boundaries might go undetected with the "small" library, but now with the "large" library it is clobbering something important, and your printf() failure is simply the first symptom you are noticing.
0 Kudos
Altera_Forum
Honored Contributor II
1,707 Views

Are the two processors set to use completely different memory areas for absolutely everything? 

Otherwise things will go very strangely wrong. 

Similarly I think the stack crashes into the heap - if they collide things will also be 'strange'.
0 Kudos
Altera_Forum
Honored Contributor II
1,707 Views

 

--- Quote Start ---  

Try using %d instead of %i 

--- Quote End ---  

 

 

I tried using %d, but it's still the same. And why won't anything get printed when I use the normal C library?
0 Kudos
Altera_Forum
Honored Contributor II
1,707 Views

 

--- Quote Start ---  

Might be that the divide operation is failing. 

Maybe you code is using the divide instructions, but it isn't present in your cpu. 

But %i isn't a standard format. 

--- Quote End ---  

 

 

I don't have the divider enabled in the CPU. I'll have it enabled and see if it fixes the issue. Thanks ! :)
0 Kudos
Altera_Forum
Honored Contributor II
1,707 Views

 

--- Quote Start ---  

Maybe it is a source of incorrect "value" : memory of integer "K" could be overwritten. 

"Strings" are located inline or at the end of program section, whereas data are in other section. 

It is a clue, i am not expert in multi processor. 

Good luck 

--- Quote End ---  

 

 

Mmmm, that's an interesting thought. but I checked the values from the debugger and they are correct. Only printf() function outputs the messed up values. I also tried sprintf() to get the integer values converted into a string, and the converted string is still incorrect. 

Biggest problem is why nothing gets printed when the normal C library is used.
0 Kudos
Altera_Forum
Honored Contributor II
1,707 Views

 

--- Quote Start ---  

Are the two processors set to use completely different memory areas for absolutely everything? 

Otherwise things will go very strangely wrong. 

Similarly I think the stack crashes into the heap - if they collide things will also be 'strange'. 

--- Quote End ---  

 

 

The two processors use different memory areas for all the code sections. At the moment each processor has 2MB for instructions and 1MB for data sections.
0 Kudos
Altera_Forum
Honored Contributor II
1,707 Views

Does the JTAG UART need a specific clock frequency to communicate correctly with the host PC? Currently all the components in my system run at 100Mhz.

0 Kudos
Reply