SWO 调试输出配置——以STM32G474 NUCLEO为例
#Uncomment for hardware floating point
#add_compile_definitions(ARM_MATH_CM4;ARM_MATH_MATRIX_CHECK;ARM_MATH_ROUNDING)
#add_compile_options(-mfloat-abi=hard -mfpu=fpv4-sp-d16)
#add_link_options(-mfloat-abi=hard -mfpu=fpv4-sp-d16)
将这两个文件中的这一段代码的第2到4行的注释去掉
itm ports on
stm32g4x.tpiu enable
stm32g4x.tpiu configure -protocol uart -traceclk 170000000 -output :4444 -formatter off
在文件的最后添加这一段代码
int __io_putchar(int ch)
{
while (ITM->PORT[0].u32 == 0UL)
__NOP();
ITM->PORT[0].u8 = (uint8_t) ch;
return ch;
}
在任意一处的USER CODE里放置这一段代码,这main.c里的printf输出就能在putty中看到了
在while循环里写printf就能在putty里看到了,记得用debug模式下载
以上是培训时学长传授的,弄好后想写一篇记录一下。