HAL库uint8_t,uint16_t,uint32_t类型报错error: #20: identifier “uint32_t“ is undefined
uint8_t的报错为例
error: #20: identifier "uint8_t" is undefined
找不到这个类型了
解决办法:
法1:
在.h的文件添加:#include "stdint.h",对应.c文件开头都会有它的#include"模块.h"
如果还不能解决就勾选微库 “Use Micro LIB”看看
法2:
自己编写头文件声明这些类型,
uint8_t等本质是typedef 定义的固定宽度整数类型,完全可以在自定义头文件中手动声明,无需依赖stdint.h。示例自定义头文件(比如命名为
my_typedef.h)#ifndef __MY_TYPEDEF_H #define __MY_TYPEDEF_H// 手动定义固定宽度类型,需根据MCU的位数(如32位STM32)匹配 typedef unsigned char uint8_t; // 无符号8位 typedef signed char int8_t; // 有符号8位 typedef unsigned short uint16_t; // 无符号16位 typedef signed short int16_t; // 有符号16位 typedef unsigned int uint32_t; // 无符号32位(STM32中int为32位) typedef signed int int32_t; // 有符号32位#endif#ifndef __SYS_H__ #define __SYS_H__#include "stm32f4xx.h" 这个根据情况改 #include "stm32f4xx_hal.h" 这个根据情况改typedef int32_t s32; typedef int16_t s16; typedef int8_t s8;typedef const int32_t sc32; typedef const int16_t sc16; typedef const int8_t sc8; typedef __IO int32_t vs32; typedef __IO int16_t vs16; typedef __IO int8_t vs8;typedef __I int32_t vsc32; typedef __I int16_t vsc16; typedef __I int8_t vsc8; typedef uint32_t u32; typedef uint16_t u16; typedef uint8_t u8;typedef const uint32_t uc32; typedef const uint16_t uc16; typedef const uint8_t uc8; typedef __IO uint32_t vu32; typedef __IO uint16_t vu16; typedef __IO uint8_t vu8;typedef __I uint32_t vuc32; typedef __I uint16_t vuc16; typedef __I uint8_t vuc8; #endif之后在需要的
.h或.c文件中包含#include "my_typedef.h"即可。但注意:手动定义需和 MCU 的架构匹配,通用性不如标准stdint.h。

找不到这个类型了