stm32的cmake的unknown type name ‘*****‘; did you mean ‘****‘解决方案

[  7%] Building C object CMakeFiles/mpu6050Test.elf.dir/Core/Src/MPU6050/I2C.c.obj
[  7%] Building C object CMakeFiles/mpu6050Test.elf.dir/Core/Src/MPU6050/inv_mpu.c.obj
[ 10%] Building C object CMakeFiles/mpu6050Test.elf.dir/Core/Src/MPU6050/inv_mpu_dmp_motion_driver.c.obj
In file included from E:\GitProject\stm32\mpu6050Test\Drivers\STM32F1xx_HAL_Driver\Inc/stm32f1xx_hal_rcc.h:1144,
                 from E:\GitProject\stm32\mpu6050Test\Core\Inc/stm32f1xx_hal_conf.h:237,
                 from E:\GitProject\stm32\mpu6050Test\Drivers\STM32F1xx_HAL_Driver\Inc/stm32f1xx_hal.h:30,
                 from E:\GitProject\stm32\mpu6050Test\Drivers\CMSIS\Device\ST\STM32F1xx\Include/stm32f1xx.h:200,
                 from E:\GitProject\stm32\mpu6050Test\Drivers\STM32F1xx_HAL_Driver\Inc/stm32f1xx_hal_def.h:30,
                 from E:\GitProject\stm32\mpu6050Test\Core\Inc/MPU6050/I2C.h:1,
                 from E:\GitProject\stm32\mpu6050Test\Core\Src\MPU6050\I2C.c:1:
E:\GitProject\stm32\mpu6050Test\Drivers\STM32F1xx_HAL_Driver\Inc/stm32f1xx_hal_rcc_ex.h:1859:1: error: unknown type name 'HAL_StatusTypeDef'; did you mean 'FLASH_TypeDef'?
 HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef  *PeriphClkInit);
 ^~~~~~~~~~~~~~~~~
 FLASH_TypeDef

而且有很多同类错误,在外网摸索后发现了问题来源

#include <stm32f1xx_hal_def.h>
#include <stm32f1xx_hal_conf.h>
#include "stm32f1xx_hal.h"//然而我包含上面两个

换而言之,被重复引用了。按照论坛说法

不必包括特定的HAL部分(在我的情况下为#include“ stm32f7xx_hal_gpio.h”),而仅需包括完整的HAL标头(#include“ stm32f7xx_hal.h”)。

所以把

#include <stm32f1xx_hal_def.h>
#include <stm32f1xx_hal_conf.h>

删去即可

同时这个错误不止发生在有

#include "stm32f1xx_hal.h" 

的情况中,还可能出现在

[  3%] Building C object CMakeFiles/mpu6050Test.elf.dir/Core/Src/MPU6050/mpu6050.c.obj
In file included from E:\GitProject\stm32\mpu6050Test\Core\Src\MPU6050\mpu6050.c:1:
E:\GitProject\stm32\mpu6050Test\Drivers\CMSIS\Include/core_armv8mbl.h:1252:39: error: unknown type name 'IRQn_Type'; did you mean 'IPSR_Type'?
 __STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn)
                                       ^~~~~~~~~
                                       IPSR_Type

这种错误的解决是删去

#include <core_armv8mbl.h>

版权声明:本文为qq_31710315原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。