使用场景:
今天在调试STM32F1项目的时候,碰到一个有点意思的小问题。
想着新建个工程,把要测试的函数直接移植到新的工程独立做测试。通过串口来输出信息查看。结果发现串口接收乱码。
原因分析:
由于STM32的串口我初始化过了,系统外部晶振和倍频系数也改过来。所以能确定不是系统时钟配置错误造成的。
那就肯定是串口相关的配置出了问题。
这里边就有2种可能:
1、串口外设初始化配置出错。(看过参数这边没问题,波特率是配置成115200)
2、printf没有做重定向(估计是这边)。
于是把printf重定向代码加进来。
重定向代码如下:
#pragma import(__use_no_semihosting)
struct __FILE
{
int handle