Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
13 years ago

printf bug?

Hello.

I've encountered a strange behaviour of prinf function. The code is a simple "hello world" example:

#include <stdio.h>
int main()
{
	printf("Hello 1\n");
	printf("HELLO 2\n");
	return 0;
}

It works and the result are two lines in console. But once i remove the second printf, it does not show up a line. When I run debug, it seem that processor executes something and does not even reach the main function. The QSys system is Nios(50MHz)+JTAG UART(50MHz)->clock bridge(50 to 143MHz)->SDRAM controller(143MHz), and timing constraints are met.

Just found out that it works if there is no \n symbol.

1 Reply

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Try with a delay loop just before the return or even with a while(1) after the last printf.

    Functions like printf are non-blocking: the string is sent to the jtag uart buffer, but transmission will take place when the interface is ready, thus it could be delayed.

    Terminating the program before transmission has completed could prevent data from being received by your terminal.