仿真器:Stlink v2
硬件:STM32F103RCT6
软件:STM32CubeIDE Version: 1.8.0
修改 syscalls.c 代码如下:
#include "stm32f1xx_hal.h" //增加头文件
__attribute__((weak)) int _write(int file, char *ptr, int len)
{
int DataIdx;
for (DataIdx = 0; DataIdx < len; DataIdx++)
{
//__io_putchar(*ptr++);
ITM_SendChar(*ptr++);
}
return len;
}
修改 main.c :
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include <stdio.h>
/* USER CODE END Includes */
int main(void)
{
..........................
while (1)
{
HAL_Delay(200);
printf(" SWD output \n");
}
..........................
}
CubeIDE 设置
开始Debug:
打开 SWV ITM Data Console
运行结果: