SWV printf Output Issue in C++ on STM32G431KB
I am currently utilizing an STM32G431KB board that differs from other boards in the STM32 Nucleo series as it has a wired SWO. While setting up SWV printf on a Nucleo variant of the same product, I encountered an inquiry and implemented suggestions given by its first answer which allowed me to enable functioning SWV under C programming language.
However, upon switching over to C++, no output is visible during usage of this feature.
For the C project, I created a new project, switched Debug to "Trace Asynchronous SW," and added the following code:
In the main loop, I added:
Upon activating SWV in the Debug Configuration, adjusting the core clock to 170 MHz, deactivating timestep in SWV settings and empowering port 0; executing C yields optimal results with expected output.
On renaming
main.c
to main.cpp
, the project operates in C++, but there is no result. What could be the reason for this problem?2 Replies
hi, @Sterling the issue you're facing is likely due to name mangling in C++. You can fix this by declaring the
_write
function with extern "C"
, which makes sure the C standard library recognizes it correctly. This should get your SWV printf output working as expectedThanks @Dark AI , I am gonna try using
extern "C"
to resolve the name mangling issue. Just to clarify, should I apply extern "C"
to the _write
function only, or are there other parts of the code that also need this adjustment in C++?