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

Printf not displaying characters

Altera_Forum
Honored Contributor II
4,675 Views

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)
0 Kudos
14 Replies
Altera_Forum
Honored Contributor II
2,676 Views

 

--- 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&#39;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.
0 Kudos
Altera_Forum
Honored Contributor II
2,676 Views

mine isn&#39;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&#39;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&#39;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 ---  

0 Kudos
Altera_Forum
Honored Contributor II
2,676 Views

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
0 Kudos
Altera_Forum
Honored Contributor II
2,676 Views

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.
0 Kudos
Altera_Forum
Honored Contributor II
2,676 Views

So, your code isn&#39;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&#39;ll find an option to set the initial breakpoint at alt_main(). 

 

Cheers, 

 

- slacker
0 Kudos
Altera_Forum
Honored Contributor II
2,676 Views

 

--- Quote Start ---  

originally posted by slacker@Mar 30 2007, 02:22 AM 

so, your code isn&#39;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&#39;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
0 Kudos
Altera_Forum
Honored Contributor II
2,676 Views

Silly question... Do you have a stdout device defined in your System Library properties page? Without it, printf() doesn&#39;t have a chance to work. 

 

- slacker
0 Kudos
Altera_Forum
Honored Contributor II
2,676 Views

 

--- 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&#39;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
0 Kudos
Altera_Forum
Honored Contributor II
2,676 Views

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&#39;s standard practice to return &#39;0&#39; when successful on just about any program I&#39;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
0 Kudos
Altera_Forum
Honored Contributor II
2,676 Views

I&#39;ll say try to open one HyperTerminal at one spare port. 

I don&#39;t know why, but that&#39;s the way I ran for the past two years, otherwise I won&#39;t have any stdout on IDE-console.
0 Kudos
Altera_Forum
Honored Contributor II
2,676 Views

I have the same problem. printf() does not display any characters on the console. If I place all sections in the external SRAM everything works fine. Running from within the onchip RAM the function does not display anything. Maybe printf() requires more RAM. I have only 2k left (internal RAM). In all of my last application this was no problem, but now there is ess memory. Maybe this is the reason? 

 

Try to use more on-chip RAM.
0 Kudos
Altera_Forum
Honored Contributor II
2,676 Views

Hi all, 

I know it is very late to answer this question. However, I decided to post what I found just in case someone come by this thread or searches for this problem then he can find my notes. 

 

What I found is that printf() can work only if the related interrupt is enabled. You can put alt_irq_enable_all( 0x01 ); at the beginning of your main function and hopefully everything will go fine.
0 Kudos
Altera_Forum
Honored Contributor II
2,676 Views

long shot...but i have the same problem after updating to windows 10...JTAG i qsys, stdio set to jtag code running(led control) but no output from alt_printf or printf but both functions returns... 

 

thanks in advance (in case somebody sees this old thread)
0 Kudos
Altera_Forum
Honored Contributor II
2,676 Views
0 Kudos
Reply