Forum Discussion
Altera_Forum
Honored Contributor
13 years agoNiosII printf() not printing correctly
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, Isuru14 Replies
- Altera_Forum
Honored Contributor
Hi,
could you post your piece of code employing printf() ? - Altera_Forum
Honored Contributor
Are strings printed correctly? Or is everything wrong??
- Altera_Forum
Honored Contributor
--- 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; } - Altera_Forum
Honored Contributor
--- 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". - Altera_Forum
Honored Contributor
Try using %d instead of %i
- Altera_Forum
Honored Contributor
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. - Altera_Forum
Honored Contributor
--- 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 - Altera_Forum
Honored Contributor
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. - Altera_Forum
Honored Contributor
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'. - Altera_Forum
Honored Contributor
--- 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?