Forum Discussion
Printf not displaying characters
I have a problem with the printf function,
# include <stdio.h> int main() { printf("Hello from Nios II!\n"); return 0; } that is the simple program that i tried to run, however the printf function did not print the sentence to the console, i am using the nios2 IDE. does anyone know why it doesnt display the printf sentence? the console remains as this: nios2-terminal: connected to hardware target using JTAG UART on cable nios2-terminal: "USB-Blaster [USB-0]", device 1, instance 0 nios2-terminal: (Use the IDE stop button or Ctrl-C to terminate)14 Replies
- Altera_Forum
Honored Contributor
--- Quote Start --- originally posted by estellrum@Mar 28 2007, 08:38 AM i have a problem with the printf function,# include <stdio.h>
int main()
{
printf("hello from nios ii!\n");
return 0;
}
that is the simple program that i tried to run, however the printf function did not print the sentence to the console, i am using the nios2 ide.
does anyone know why it doesnt display the printf sentence?
the console remains as this:
nios2-terminal: connected to hardware target using jtag uart on cable
nios2-terminal: "usb-blaster [usb-0]", device 1, instance 0
nios2-terminal: (use the ide stop button or ctrl-c to terminate)
<div align='right'><{post_snapback}> (index.php?act=findpost&pid=22588)
--- quote end ---
--- Quote End --- The printf use stdout as the output channel, so one possible cause is that there is no stdout device in the system, you can check this by selecting you project in Nios IDE's Project Navigation panel, right click "System Library Properties". If no stdout device is there, a common solution is to add a JTAG_UART device into your system in SOPC Builder.
- Altera_Forum
Honored Contributor
mine isn't working either.
I am using Quartus 5.0 and Nios II IDE 5.0 with the niosII_stratixII_2s60/standard example, meaning that I do have a JTAG_UART device on my processor. I double checked if the stdout is binded with the jtag device and it is. I still don't get anything after the "press ctrl+c to terminate" message. Any ideas ? --- Quote Start --- originally posted by arrive+mar 28 2007, 12:47 pm--><div class='quotetop'>quote (arrive @ mar 28 2007, 12:47 pm)</div>--- quote start ---
<!--quotebegin-estellrum@Mar 28 2007, 08:38 AM i have a problem with the printf function,
# include <stdio.h>
int main()
{
printf("hello from nios ii!\n");
return 0;
}
that is the simple program that i tried to run, however the printf function did not print the sentence to the console, i am using the nios2 ide.
does anyone know why it doesnt display the printf sentence?
the console remains as this:
nios2-terminal: connected to hardware target using jtag uart on cable
nios2-terminal: "usb-blaster [usb-0]", device 1, instance 0
nios2-terminal: (use the ide stop button or ctrl-c to terminate)
<div align='right'><{post_snapback}> (index.php?act=findpost&pid=22588)
--- quote end ---
--- Quote End --- The printf use stdout as the output channel, so one possible cause is that there is no stdout device in the system, you can check this by selecting you project in Nios IDE's Project Navigation panel, right click "System Library Properties". If no stdout device is there, a common solution is to add a JTAG_UART device into your system in SOPC Builder. <div align='right'><{post_snapback}> (index.php?act=findpost&pid=22594)</div> [/b] --- Quote End ---
- Altera_Forum
Honored Contributor
Try debugging your code. You might have some sort of device/component initialization issue that is causing your code to get stuck prior to even entering main() or you might, inadvertently, be causing some sort of spurious interrupt issue.
At the very least, debugging your code will tell you more about your problem... Cheers, - slacker - Altera_Forum
Honored Contributor
Well i did spent a few hours debugging it,
in the debug panel, it has an error: <terminated, exit value : 0> NIOS II Download output (3/29/07 9.26PM) Nios II terminal window nios2-gdb-server output debugger process as you can see, the bottom 3 are running fine, but the first one...is always red and not running. can anyone please help me?..thankyou i already made sure the JTAG_uart is assciated. - Altera_Forum
Honored Contributor
So, your code isn't downloading? Do you have a JTAG Debug Module, with a leve of at least 1, enabled on your CPU? If not, then download/debug will not function.
If the debugger never makes it to main(), then you need to experiment with setting breakpoints earlier. In the Run/Debug target menu, you'll find an option to set the initial breakpoint at alt_main(). Cheers, - slacker - Altera_Forum
Honored Contributor
--- Quote Start --- originally posted by slacker@Mar 30 2007, 02:22 AM so, your code isn't downloading? do you have a jtag debug module, with a leve of at least 1, enabled on your cpu? if not, then download/debug will not function.if the debugger never makes it to main(), then you need to experiment with setting breakpoints earlier. in the run/debug target menu, you'll find an option to set the initial breakpoint at alt_main().
cheers,
- slacker
<div align='right'><{post_snapback}> (index.php?act=findpost&pid=22617)
--- quote end ---
--- Quote End --- yeah , the Jtag debug module is working fine and is enabled, the whole program runs fine, but when it reached the printf function, it executes it without printing out the text to the console. which is why i suspect the error in my previous post caused the problem. I dont know how to fix that error. thanks
- Altera_Forum
Honored Contributor
Silly question... Do you have a stdout device defined in your System Library properties page? Without it, printf() doesn't have a chance to work.
- slacker - Altera_Forum
Honored Contributor
--- Quote Start --- originally posted by slacker@Mar 31 2007, 12:58 AM silly question... do you have a stdout device defined in your system library properties page? without it, printf() doesn't have a chance to work.- slacker
<div align='right'><{post_snapback}> (index.php?act=findpost&pid=22672)
--- quote end ---
--- Quote End --- yes, i do have a stdout device in system library properties. i checked it, the jtag was there
- Altera_Forum
Honored Contributor
That "error" that you spotted, earlier, is probably not an error (at all). The download process terminates after executing, and I believe that this is just an informational message.... It's standard practice to return '0' when successful on just about any program I've used.
Please set a breakpoint on the printf() instruction and single-step from there. Note any errors you encounter, and where the single-stepping takes you. Good luck, and have a good weekend! - slacker - Altera_Forum
Honored Contributor
I'll say try to open one HyperTerminal at one spare port.
I don't know why, but that's the way I ran for the past two years, otherwise I won't have any stdout on IDE-console.