Skip to main content
Graduate II
January 7, 2021
Question

How to setup printf to print message to console

  • January 7, 2021
  • 12 replies
  • 99282 views

Hello. I have STM32F767ZI nucleo board. I have created a new project and used default setup for the nucleo board. It have automatically set up some peripherals for me

0693W000006HnM9QAK.png 

In my code, I want to print the debug messages to the console:

 while (1)
 
 {
 
 /* USER CODE END WHILE */
 
 HAL_Delay(1000);
 
 printf("hello");
 
 /* USER CODE BEGIN 3 */
 
 }
 
 /* USER CODE END 3 */
 
}

But the printf is not working. I remember doing simmilar excersise in the class and it did not require any additional setup.

Can someone help me understand how printf works and how to set it up? Do I need to dedicate USART port for it?

    This topic has been closed for replies.

    12 replies

    Explorer II
    June 8, 2022

    Dear All.

    I am using the Nucleo+F072RB (M0 grade) under CUBE IDE.

    I am trying to implement the "printf" aproach of this post.

    Even thought the last post of "Retarget" means very sound, at first I had implemented all aproach using "__io_putchar" and or "_write" merged into "main".

    At first, I would like to know, if someone could explain, why some approach refere only to "__io_putchar" but not "_write"? And others approaches, like above, start with "_write" and jump to "__io_putchar"?

    I must report that both approaches seems to work (0 compilation error), It seems like printing "somewhere" . I am using the CUBE IDE Embedded "terminal", which seems to work for simple HAL UART functions.

    Second, the "retarget" implementation raises a lot of compilation error. So, I would ask to someone: for M0 (no SWV) should we swich ON/OFF any options on CUBE IDE environment? Or add some #include somewhere?

    Third, Should we take some right action on "syscall.c/h" files, if we implement this "retarget" files approach?

    Thanks in advance.

    Visitor II
    June 9, 2024

    There is one comment mentioned the use to  fflush(stdout);

    I got it working after adding it after printf(), still don't know why.