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链接已复制
14 回复数
--- 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; }
--- 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".
--- 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
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.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 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 ! :)
--- 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.
--- 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.
