cancel
Showing results for 
Search instead for 
Did you mean: 

How to use SVW ITM Data Console with printf() in non-debug mode?

username007
Associate II

Hello everyone, 

 

I'm figuring out the redirection of `printf()` function to ITM Data Console on example of Nucleo-G474RE. 

 

I managed to set-up the forward of `printf()` to ITM Data Console when it is used in debug-mode, but I can't use it when it is build with regular Run command. The start trace button stays grey and unavailable. However, I can connect to SWV with STM32CubeProgrammer. Which setting am I missing?

 

The example code is simple and based on STM32 project without BSP. Code is:

 

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include <stdio.h>

/* USER CODE END Includes */

 

/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
__attribute__((weak)) int _write(int file, char *ptr, int len)
{
  (void)file;

  for (int DataIdx = 0; DataIdx < len; DataIdx++)
  {
    ITM_SendChar(*ptr++);
  }
  return len;
}

/* USER CODE END 0 */

 

/* USER CODE BEGIN WHILE */
  while (1)
  {
	  printf("Hello from within STM32 via SWO!\r\n");
	  HAL_Delay(500);
    /* USER CODE END WHILE */


    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */

Project configuration is:

 

username007_0-1750165716054.png

System info:

  • Windows 11
  • STLink firmware version : V3.J16.M8
  • Used Board : Nucleo-G474RE
  • STM32CubeIDE : 1.18.1
1 REPLY 1
Pavel A.
Super User

Use some tool that can read ITM trace without the IDE. For example, the Cube Programmer or something based on OpenOCD, pyocd.  Note that these tools will anyway enable the debugger interface (SWD pins and DBG) because the ITM is part of it.