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:
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 */
Thanks to the above modifications, the user can get the SWO traces in the SWO Viewer (see the next figure).
This viewer is part of the STM32 ST-LINK Utility tools : STM32 ST-LINK Utility
Note : Depending on the board, a solder bridge may have to be soldered. For example, a short is placed in SB15 on the NUCLEO-64 boards
For more information about C/C++ development tools in Eclipse, please see C/C++ Development User Guide.