STM32问题分析:error: #20: identifier "uint16_t" is undefined

本文介绍了在STM32编程中遇到的"uint16_t"未定义错误,分析了错误原因,并提供了解决方案。作者强调了包含"stm32f10x.h"头文件的重要性,指出该头文件应放置在.h文件中,以避免重复引用导致的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

说明:
本文原创作者『Allen5G』
首发于微信公众号『Allen5G』
标签:编程,软件,算法,思维

QQ技术资料群:736386324
个人微信 : coderAllen (人较多,请备注公众号读者)

推荐阅读:
如何更快的学习单片机?


#include "stm32f10x.h"语句要放在.h文件里,之前都是一直放在.c文件里的。他是先编译头文件,所以如果放在h文件里,c文件里就不用再写了,但是如果放在c文件里,如果h文件也要用的话还要在h文件再写一次

Build target &#39;Target 1&#39; compiling main.c... ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(296): error: #20: identifier "HAL_StatusTypeDef" is undefined HAL_StatusTypeDef HAL_Init(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(297): error: #20: identifier "HAL_StatusTypeDef" is undefined HAL_StatusTypeDef HAL_DeInit(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(300): error: #20: identifier "HAL_StatusTypeDef" is undefined HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(300): error: #20: identifier "uint32_t" is undefined HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(310): error: #20: identifier "uint32_t" is undefined void HAL_Delay(uint32_t Delay); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(311): error: #20: identifier "uint32_t" is undefined uint32_t HAL_GetTick(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(312): error: #20: identifier "uint32_t" is undefined uint32_t HAL_GetTickPrio(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(313): error: #20: identifier "HAL_StatusTypeDef" is undefined HAL_StatusTypeDef HAL_SetTickFreq(HAL_TickFreqTypeDef Freq); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(317): error: #20: identifier "uint32_t" is undefined uint32_t HAL_GetHalVersion(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(318): error: #20: identifier "uint32_t" is undefined uint32_t HAL_GetREVID(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(319): error: #20: identifier "uint32_t" is undefined uint32_t HAL_GetDEVID(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(326): error: #20: identifier "uint32_t" is undefined void HAL_GetUID(uint32_t *UID); dht11.h(12): error: #20: identifier "GPIO_TypeDef" is undefined void DHT11_Init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); dht11.h(12): error: #20: identifier "uint16_t" is undefined void DHT11_Init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); dht11.h(13): error: #20: identifier "uint8_t" is undefined DHT11_Status DHT11_Read(uint8_t *temperature, uint8_t *humidity); dht11.h(13): error: #20: identifier "uint8_t" is undefined DHT11_Status DHT11_Read(uint8_t *temperature, uint8_t *humidity); main.c(9): error: #20: identifier "SPI_HandleTypeDef" is undefined extern SPI_HandleTypeDef hspi1; main.c(10): error: #20: identifier "TIM_HandleTypeDef" is undefined extern TIM_HandleTypeDef htim2; main.c(15): warning: #223-D: function "SystemClock_Config" declared implicitly SystemClock_Config(); main.c(16): warning: #223-D: function "MX_GPIO_Init" declared implicitly MX_GPIO_Init(); main.c(17): warning: #223-D: function "MX_SPI1_Init" declared implicitly MX_SPI1_Init(); // ??SPI??? main.c(18): warning: #223-D: function "MX_TIM2_Init" declared implicitly MX_TIM2_Init(); // ??TIM2??? main.c(24): error: #159: declaration is incompatible with previous "MX_TIM2_Init" (declared at line 18) static void MX_TIM2_Init(void) { main.c(25): error: #20: identifier "TIM_ClockConfigTypeDef" is undefined TIM_ClockConfigTypeDef sClockSourceConfig = {0}; main.c(26): error: #20: identifier "TIM_MasterConfigTypeDef" is undefined TIM_MasterConfigTypeDef sMasterConfig = {0}; main.c(28): error: #20: identifier "TIM2" is undefined htim2.Instance = TIM2; main.c(30): error: #20: identifier "TIM_COUNTERMODE_UP" is undefined htim2.Init.CounterMode = TIM_COUNTERMODE_UP; main.c(32): error: #20: identifier "TIM_CLOCKDIVISION_DIV1" is undefined htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; main.c(33): error: #20: identifier "TIM_AUTORELOAD_PRELOAD_DISABLE" is undefined htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE; main.c(34): warning: #223-D: function "HAL_TIM_Base_Init" declared implicitly if (HAL_TIM_Base_Init(&htim2) != HAL_OK) { main.c(34): error: #20: identifier "HAL_OK" is undefined if (HAL_TIM_Base_Init(&htim2) != HAL_OK) { main.c(35): warning: #223-D: function "Error_Handler" declared implicitly Error_Handler(); main.c(37): error: #20: identifier "TIM_CLOCKSOURCE_INTERNAL" is undefined sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL; main.c(38): warning: #223-D: function "HAL_TIM_ConfigClockSource" declared implicitly if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK) { main.c(38): error: #20: identifier "HAL_OK" is undefined if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK) { main.c(39): warning: #223-D: function "Error_Handler" declared implicitly Error_Handler(); main.c(41): error: #20: identifier "TIM_TRGO_RESET" is undefined sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; main.c(42): error: #20: identifier "TIM_MASTERSLAVEMODE_DISABLE" is undefined sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; main.c: 8 warnings, 30 errors compiling dht11.c... ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(296): error: #20: identifier "HAL_StatusTypeDef" is undefined HAL_StatusTypeDef HAL_Init(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(297): error: #20: identifier "HAL_StatusTypeDef" is undefined HAL_StatusTypeDef HAL_DeInit(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(300): error: #20: identifier "HAL_StatusTypeDef" is undefined HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(300): error: #20: identifier "uint32_t" is undefined HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(310): error: #20: identifier "uint32_t" is undefined void HAL_Delay(uint32_t Delay); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(311): error: #20: identifier "uint32_t" is undefined uint32_t HAL_GetTick(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(312): error: #20: identifier "uint32_t" is undefined uint32_t HAL_GetTickPrio(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(313): error: #20: identifier "HAL_StatusTypeDef" is undefined HAL_StatusTypeDef HAL_SetTickFreq(HAL_TickFreqTypeDef Freq); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(317): error: #20: identifier "uint32_t" is undefined uint32_t HAL_GetHalVersion(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(318): error: #20: identifier "uint32_t" is undefined uint32_t HAL_GetREVID(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(319): error: #20: identifier "uint32_t" is undefined uint32_t HAL_GetDEVID(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(326): error: #20: identifier "uint32_t" is undefined void HAL_GetUID(uint32_t *UID); dht11.h(12): error: #20: identifier "GPIO_TypeDef" is undefined void DHT11_Init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); dht11.h(12): error: #20: identifier "uint16_t" is undefined void DHT11_Init(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin); dht11.h(13): error: #20: identifier "uint8_t" is undefined DHT11_Status DHT11_Read(uint8_t *temperature, uint8_t *humidity); dht11.h(13): error: #20: identifier "uint8_t" is undefined DHT11_Status DHT11_Read(uint8_t *temperature, uint8_t *humidity); dht11.c(7): warning: #223-D: function "__HAL_TIM_SET_COUNTER" declared implicitly __HAL_TIM_SET_COUNTER(&htim2, 0); dht11.c(7): error: #20: identifier "htim2" is undefined __HAL_TIM_SET_COUNTER(&htim2, 0); dht11.c(8): warning: #223-D: function "HAL_TIM_Base_Start" declared implicitly HAL_TIM_Base_Start(&htim2); dht11.c(9): warning: #223-D: function "__HAL_TIM_GET_COUNTER" declared implicitly while (__HAL_TIM_GET_COUNTER(&htim2) < us); dht11.c(10): warning: #223-D: function "HAL_TIM_Base_Stop" declared implicitly HAL_TIM_Base_Stop(&htim2); dht11.c(6): warning: #177-D: function "delay_us" was declared but never referenced static void delay_us(uint16_t us) { dht11.c: 5 warnings, 17 errors compiling buzzer.c... ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\CMSIS\Device\ST\STM32F1xx\Include\stm32f1xx.h(159): error: #35: #error directive: "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" #error "Please select first the target STM32F1xx device used in your application (in stm32f1xx.h file)" buzzer.c: 0 warnings, 1 error compiling TFT_GFX.c... ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(296): error: #20: identifier "HAL_StatusTypeDef" is undefined HAL_StatusTypeDef HAL_Init(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(297): error: #20: identifier "HAL_StatusTypeDef" is undefined HAL_StatusTypeDef HAL_DeInit(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(300): error: #20: identifier "HAL_StatusTypeDef" is undefined HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(300): error: #20: identifier "uint32_t" is undefined HAL_StatusTypeDef HAL_InitTick(uint32_t TickPriority); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(310): error: #20: identifier "uint32_t" is undefined void HAL_Delay(uint32_t Delay); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(311): error: #20: identifier "uint32_t" is undefined uint32_t HAL_GetTick(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(312): error: #20: identifier "uint32_t" is undefined uint32_t HAL_GetTickPrio(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(313): error: #20: identifier "HAL_StatusTypeDef" is undefined HAL_StatusTypeDef HAL_SetTickFreq(HAL_TickFreqTypeDef Freq); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(317): error: #20: identifier "uint32_t" is undefined uint32_t HAL_GetHalVersion(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(318): error: #20: identifier "uint32_t" is undefined uint32_t HAL_GetREVID(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(319): error: #20: identifier "uint32_t" is undefined uint32_t HAL_GetDEVID(void); ..\STM32CubeF1\STM32Cube_FW_F1_V1.6.0\Drivers\STM32F1xx_HAL_Driver\Inc\stm32f1xx_hal.h(326): error: #20: identifier "uint32_t" is undefined void HAL_GetUID(uint32_t *UID); TFT_GFX.c(2): error: #5: cannot open source input file "spi.h": No such file or directory #include "spi.h" TFT_GFX.c: 0 warnings, 13 errors compiling TFT_FONTS.c... TFT_FONTS.c(5): error: #20: identifier "Font8x16_Data" is undefined FontDef Font_8x16 = {8, 16, Font8x16_Data}; TFT_FONTS.c: 0 warnings, 1 error ".\Objects\zuoye.axf" - 62 Error(s), 13 Warning(s). Target not created. Build Time Elapsed: 00:00:01
最新发布
06-26
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

CodeAllen嵌入式

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值