STM32F429ZGT6 学习笔记
1.串口通信乱码(时钟配置有问题)
在使用过程中发现,配置的中断优先级和system_stm32f4xx.c中的HSE时钟仍然还是乱码
#if !defined (HSE_VALUE)
#define HSE_VALUE ((uint32_t)25000000) /*!< Default value of the External oscillator in Hz */
#endif /* HSE_VALUE */
#if !defined (HSI_VALUE)
#define HSI_VALUE ((uint32_t)16000000) /*!< Value of the Internal oscillator in Hz*/
#endif /* HSI_VALUE */
后面发现在stm32f4xx_hal_conf.h中会再次配置HSE,故导致系统时钟配置不对
#if !defined (HSE_VALUE)
#define HSE_VALUE ((uint32_t)25000000) /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */
在将以上两个HSE_VALUE都配置后时钟正确,通信正常
2.重映射printf函数
#pragma import(__use_no_semihosting)
//标准库需要的支持函数
struct __FILE
{
int handle;
};
FILE __stdout;
//定义_sys_exit()以避免使用半主机模式
void _sys_exit(int x)
{
x = x;
}
//重定义fputc函数
int fputc(int ch, FILE *f)
{
while((UART7->SR&0X40)==0);//循环发送,直到发送完毕
UART7->DR = (uint8_t) ch;
return ch;
}