1.
https://www.strongerhuang.com/categories/printf%E7%B3%BB%E5%88%97%E6%95%99%E7%A8%8B/
黄工的这篇文章相当有用
总结一下。
SWO类似于printf
可以替换一个printf,用起来很方便。
core_m4.h
中
__STATIC_INLINE uint32_t ITM_SendChar (uint32_t ch)
{
if (((ITM->TCR & ITM_TCR_ITMENA_Msk) != 0UL) && /* ITM enabled */
((ITM->TER & 2UL ) != 0UL) ) /* ITM Port #0 enabled */
{
while (ITM->PORT[1U].u32 == 0UL)
{
__NOP();
}
ITM->PORT[1U].u8 = (uint8_t)ch;
}
return (ch);
}
#include <stdio.h>
#include "core_cm4.h"
int fputc(int ch, FILE *f)
{
ITM_SendChar(ch);
return ch;
}
以上是函数中需要添加的代码,代码量很少。
硬件上需要多连接一根线SWO
本系列教程主要是针对MCU的printf打印输出,常见的方式:
1.UART打印输出
2.仿真打印输出
3.SWO打印输出
4.JLink-RTT打印输出
除仿真之外,其它三种都是基于MCU硬件打印输出。
从打印效率来说:UART < SWO < JLink-RTT。
每一种printf打印输出方式应用场景不同,也各有各的特点。
CUBE MX配置
KEIL配置:
IAR
RTT