SystemWorkbench Logo

SystemWorkbench for STM32

SWOTraces

It is possible to display the traces sent by an application over SWO line. A pin configuration is required: the CubeMX SWO configuration must be selected for the PB3 pin. Check that the following configuration is applied:

CubeMX SWO configuration

The application must be linked with the librdimon library. To do so, update the Linker Flags with the following parameter as shown is the newt figure: -specs=nosys.specs -specs=nano.specs

Linker flags

In the main.c file, the stdio.h header file has to be included...

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

...and the following code lines have to be added in the application to root the traces from the printf function toward the ITM_SendChar function to be output on the PB3 pin:

/* USER CODE BEGIN 4 */ int __io_putchar(int ch) { //Comment all other lines ITM_SendChar(ch); return ch; } int _write(int file, char *ptr, int len) { int DataIdx; for (DataIdx = 0; DataIdx < len; DataIdx++) { __io_putchar(*ptr++); } return len; } /* USER CODE END 4 */

Then while using a printf, get the corresponding traces in the SWO viewer:

/* USER CODE BEGIN 2 */ printf("Hello STM32\n"); /* USER CODE END 2 */

SWO Traces


For more information about C/C++ development tools in Eclipse, please see C/C++ Development User Guide.