6
\$\begingroup\$

I create a blinky project to test a qemu simulator, but my printf`s not showing in the debug console. I create a project like official tutorial GNU MCU Eclipse.

int
main(int argc, char* argv[])
{
  // By customising __initialize_args() it is possible to pass arguments,
  // for example when running tests with semihosting you can pass various
  // options to the test.
  // trace_dump_args(argc, argv);

  // Send a greeting to the trace device (skipped on Release).
  trace_puts("Hello ARM World!");

  // The standard output and the standard error should be forwarded to
  // the trace device. For this to work, a redirection in _write.c is
  // required.
  puts("Standard output message.");
  fprintf(stderr, "Standard error message.\n");

  // At this stage the system clock should have already been configured
  // at high speed.
  trace_printf("System clock: %u Hz\n", SystemCoreClock);

  timer_start();

  blink_led_init();

  uint32_t seconds = 0;

  // Infinite loop
  while (1)
    {
      blink_led_on();
      timer_sleep(seconds == 0 ? TIMER_FREQUENCY_HZ : BLINK_ON_TICKS);

      blink_led_off();
      timer_sleep(BLINK_OFF_TICKS);

      ++seconds;
      // Count seconds on the trace device.

      printf("My printf");

      trace_printf("Second %u\n", seconds);
    }
  // Infinite loop, never return.
}

enter image description here

\$\endgroup\$
3
\$\begingroup\$

This is a standard feature of the C library. Standard output (and input) is line buffered by default, therefore it will be held in a buffer (by the target libc) until/unless you do one of the following

  • send a newline character to stdout
  • call fflush(stdout)
  • turn off buffering with setbuf() or setvbuf() (do this before the very first output)

Standard error is not buffered, unless you tell the library otherwise, therefore you'd see every character immediately even if there is no newline.

\$\endgroup\$
  • \$\begingroup\$ Yes! I just called printf("My Pritnf\n") and this went to output console. This works. \$\endgroup\$ – Augusto Sep 2 '17 at 12:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.