cancel
Showing results for 
Search instead for 
Did you mean: 

Retarget printf on STM32G070RBxx Cortex M0+

AVerm.4
Associate III

Hi,

I'm trying retarget printf. My uart_write function is working correctly and i'm able to see character on Teraterm.

But when i try to use printf it is not working. i even tried semihosting to execute printf but it fails. i'm attaching the screenshots -

uart_code.jpg

Disassembly of the code stucks at "bkpt 0x00ab" -disassembly_debug.jpg

any solution for this problem? 

1 ACCEPTED SOLUTION

Accepted Solutions
Andrew Neil
Evangelist III

Just noticed that you are doing this in C++

The linked articles are both just C, and I have just used C.

Could you try this in a plain C project to see if that makes a difference?

 

EDIT:

See: https://community.st.com/t5/stm32cubeide-mcus/stm32cubeide-c-redirected-printf-no-longer-works-how-to-use-cout/m-p/285002/highlight/true#M14943 

 

View solution in original post

22 REPLIES 22
KDJEM.1
ST Employee

Hello @AVerm.4 ,

 

I recommend you to refer to this FAQ: How to redirect the printf function to a UART for debug messages and follow the steps.

This article describes how to redirect the printf output to the STM32 UART peripheral that is connected to the UART pins on the embedded ST-Link that will be transmitted to the host computer and displayed via a windows terminal program, Tera Term using Nucleo-G070RB.

 

I hope this help you!

Thank you.

Kaouthar

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.

Andrew Neil
Evangelist III

Please see this for how to capture a screenshot - far better than photographing the screen!

https://www.techrepublic.com/article/how-to-take-screenshots-in-windows-10/

For posting source code, please see the posting tips:

https://community.st.com/t5/community-guidelines/how-to-write-your-question-to-maximize-your-chances-to-find-a/ta-p/575228

 

Hi @KDJEM.1 ,

I appreciate your comment. But the link provides the way to retarget HAL library UART, which i see is working fine. 

But here I'm using CMSIS library to write my UART driver. And here it is not working.

@Andrew Neil sorry for that. I'm not using a personal computer rather a corporate one were we have limited access to file sharing.!

Andrew Neil
Evangelist III

@AVerm.4 wrote:

i even tried semihosting


Presumably, the screenshots you shared show your semihosting attempt - as this works via the BKPT instruction?

https://interrupt.memfault.com/blog/arm-semihosting 

 

Instead, follow the Knowledge Base article linked by @KDJEM.1 

And here's a 3rd-party article on the same: https://shawnhymel.com/1873/ 

 


@AVerm.4 wrote:

the link provides the way to retarget HAL library UART, which i see is working fine. 

But here I'm using CMSIS library to write my UART driver. And here it is not working.


It really shouldn't make any difference - they all just end up writing to the UART.

If you're hitting a BKPT instruction, that suggests you're configured for semihosting - you don't want that.

@Andrew Neil 

I tried both of the above solutions but there is no success in using printf.!

Again, if you're hitting a BKPT instruction, that suggests you're still configured for semihosting - you need to get rid of that.

 

@Andrew Neil 

Sorry missed to mention i have disabled semihosting. Even reconfigured a new project still stuck with not working "printf" whereas "uart_write" function working correctly.