1.现象
使用usart1打印日志到串口乱码,经调试发现和SystemInit函数调用有关。
2.解决办法:修改SystemInit函数和晶振相关的配置
2.1 检查实际使用的晶振和代码中配置的晶振,不同则修改 stm32f0xx.h
#if !defined (HSE_VALUE)
#define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz*/
#endif /* HSE_VALUE */
如实际使用的是24M,则这里应该是
#define HSE_VALUE ((uint32_t)24000000) /*!< Value of the External oscillator in Hz*/