cancel
Showing results for 
Search instead for 
Did you mean: 

Can't get Printf to work on CubeIDE

Hafez1
Associate III

Currently using a STM32L4R9I-DISCO and I've been struggling to get the SWV ITNM Data Console to work so I can do some debugging. I'm quite new to this, but I've followed every tutorial online to enable UART and how to set it all up, to no avail. I've managed to get the Trace Log to work, but I am looking for values of the variables in loops as the code is executed. Is there any other way to do this or is someone capable of helping me set this up?

1 ACCEPTED SOLUTION

Accepted Solutions

@Hafez1 wrote:

 help me set printf up so I can print the values of variables to the console? 


ST Knowledgebase article on redirecting printf to a UART:

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

 

And a 3rd-party article on the same:

https://shawnhymel.com/1873/ 

 

EDIT:

So sending printf to SWV is just a matter of putting "send-a-char-to-swv" instead of "send-a-char-to-uart" ...

View solution in original post

13 REPLIES 13
Pavel A.
Evangelist III

Let's begin with the ITM. Just call ITM_SendChar and ensure it goes out to the CubeIDE window. Send LF (\n) after some text characters to flush the line. If this won't work, something is wrong at ITM level (wrong clock value, something grabs the SWO pin, something not enabled in the GUI...).

Every ST evaluation board comes with a hidden gift to the buyer: a free debugging puzzle and IQ test )) Enjoy!

 


@Hafez1 wrote:

I'm quite new to this


New to which - just STM32? embedded in general? C programming in general?

 


@Hafez1 wrote:

 struggling to get the SWV ITNM Data Console to work ... I've followed every tutorial online to enable UART and how to set it all up


You realise that SWV and UART are different things?

 

New to Embdedded in general. Sorry my wording's a bit off I'm both tired and new to embedded. I meant that I've tried setting up SWV, and UART through PuttyGen for debugging and both don't seem to give me what I want. Thanks for the input.


@Hafez1 wrote:

New to Embdedded in general. 


:thumbs_up:

So familiar with C programming in general ?

 

As @Pavel A. suggested, start with just the basic sending a character - whether SWV or UART.

Get that working before trying to add the complications of printf.

Yes, I am. 

Thank you, I'll do as such. Worried about tackling printf later; everyone seems to complain about how it's hell to get it to work.


@Hafez1 wrote:

Worried about tackling printf later; everyone seems to complain about how it's hell to get it to work.


It really isn't.

But it does rely entirely on having the basic send-a-character working - so do that first!

 

EDIT:

ST Knowledgebase article on redirecting printf to a UART:

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

 

And a 3rd-party article on the same:

https://shawnhymel.com/1873/ 

I've got it to work and I can see it in my SWV ITM. Could you please help me set printf up so I can print the values of variables to the console? 


@Hafez1 wrote:

 help me set printf up so I can print the values of variables to the console? 


ST Knowledgebase article on redirecting printf to a UART:

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

 

And a 3rd-party article on the same:

https://shawnhymel.com/1873/ 

 

EDIT:

So sending printf to SWV is just a matter of putting "send-a-char-to-swv" instead of "send-a-char-to-uart" ...

Pavel A.
Evangelist III

+1 and for printf, don't forget the stdout is line-buffered. So end every line with \n.

Or use stderr: fprintf(stderr...)  - it should print immediately.