使用STM32CubeMX生成了一个工程文件,在使用串口库文件是,出现:“”identifier “HAL_StatusTypeDef” is undefined”错误。

经过测试发现是在添加的usart.c文件中,直接调用了#include "stm32f1xx_hal_uart.h"头文件,便会出现上述错误,解决方法经过测试,在调用#include "stm32f1xx_hal_uart.h"头文件时首先调用#include "stm32f1xx_hal.h"头文件,该头文件根据自己工程修改,我的是STM32F103,用的是stm32f1xx_hal.h。
将上述头文件添加到#include "stm32f1xx_hal_uart.h"头文件前,再次编译,解决该问题。

为了美观,将#include "stm32f1xx_hal.h"放入usart.h头文件中,将usart.h的头文件调用放到#include "stm32f1xx_hal_uart.h"前,如下图所示,异曲同工。

|