2024-09-17 12:55 AM
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 -
Disassembly of the code stucks at "bkpt 0x00ab" -
any solution for this problem?
Solved! Go to Solution.
2024-09-17 03:29 AM - edited 2024-09-17 03:48 AM
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:
2024-09-17 03:54 AM - edited 2024-09-17 03:57 AM
Tried with the C project as well it's not working.
It printed few lines then threw some garbage. I retried debugging but now nothing displayed on terminal.
Do I need to increase baud rate from 9600 to 115200? Because it's taking time to print.
2024-09-17 04:19 AM - edited 2024-09-17 04:27 AM
@AVerm.4 wrote:it's taking time to print.
What do you mean by that?
Remember that printf is line-buffered - it won't (usually) send its output until it gets a newline...
stderr isn't buffered:
2024-09-17 04:27 AM
@AVerm.4 wrote:Sorry missed to mention i have disabled semihosting.
and that's stopped the BKPT problem?
2024-09-17 04:42 AM - edited 2024-09-17 04:43 AM
Because I stopped semihosting in this new C project it is not getting stuck at BKPT.
Note - It's not getting stuck at BKPT even in C++ project if not using semihosting.
2024-09-17 04:46 AM
"Time to print" i mean to say, it's stuck in buffer before displaying in the terminal. Like it takes couple of minutes to display in terminal when I'm using printf.
2024-09-17 05:24 AM
As noted, that's expected behaviour for stdout (used implicitly by printf)
From the other threads, you should be able to disable the buffering with:
setbuf( stdout, NULL );
https://en.cppreference.com/w/c/io/setbuf
Or use stderr
Or just send a newline.
2024-09-17 10:12 PM
For C++ we need to add the extern "C"..
Thanks for the suggestions.!
2024-09-18 03:09 AM - edited 2024-09-18 03:11 AM
@ST AME Support NF @STTwo-32 can the knowledge base article please be updated to note this?
I think the article also needs to explain about the line-buffering - as that is a frequent cause of problems!
2024-09-18 03:29 AM
Hello @Andrew Neil ,
Thank you for this proposal. I reported this request internally.
Your feedback and request are welcome.
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.