cancel
Showing results for 
Search instead for 
Did you mean: 

How to redirect the printf function to a UART for debug messages

Supriyash
Visitor

It can be especially useful during code development to display messages in a terminal window about various system parameters to help with debugging. An easy way to do that is to use the printf function and redirect the output to a UART for display in a terminal window.

 

The ST-LINKs embedded on ST Nucleo boards have a virtual com port feature, and we can easily get debugging information on a terminal using printf redirected to the UART of the STM32 connected to the ST-LINK pins used for the virtual COM port.

3 REPLIES 3
Supriyash
Visitor

BOT / SPAMMER

Andrew Neil
Evangelist III

Are you asking a question, or just making an observation (twice)?

 

The first thing to do - before worrying about printf - is to get the basic UART comms working:

https://community.st.com/t5/stm32-mcus/implementing-uart-receive-and-transmit-functions-on-an-stm32/ta-p/694926

 

Once that is done, then - and only then -  move on to redirecting printf:

https://community.st.com/t5/stm32-mcus/how-to-redirect-the-printf-function-to-a-uart-for-debug-messages/ta-p/49865

And here's a 3rd-party article on the same:

https://shawnhymel.com/1873/ 

+ Refer to the board schematics to check which UART is connected to the STLINK to use the virtual comport.

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.