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:

/* USER CODE BEGIN Includes */
#include "stdio.h"
/* USER CODE END Includes */


/* USER CODE BEGIN 0 */
int _write(int file, char *ptr, int len)
{
    int DataIdx;
    for (DataIdx = 0; DataIdx < len; DataIdx++)
    {
        ITM_SendChar(*ptr++);
    }
    return len;
}
/* USER CODE END 0 */


In the main loop, I added:

/* USER CODE BEGIN 2 */
int i = 0;
/* USER CODE END 2 */

/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
    printf("%d Hello World!\n", ++i);
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */


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?
Was this page helpful?