cancel
Showing results for 
Search instead for 
Did you mean: 

How to setup printf to print message to console

LPetr.1
Senior

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?

13 REPLIES 13
mneg
Associate

Thanks @suads​ and @Christophe VRIGNAUD​, I got the STlink UART working.

JSILV.2
Senior

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.

Including the \n\r in the printf string worked for me on a NUCLEO-H753ZI. Another tricky thing was that my Nucleo board arrived with the solder bridges configured for using LPUART1 outputting to Arduino pins D0/D1 despite the documentation indicating the default configuration is USART3 outputting to the STLink virutal com port.

 

LittleLogic
Associate II

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

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