尝试构建项目时,出现如下错误:

Drivers/CMSIS/Include/core_cm4.h:1816:41: error: unknown type name 'IRQn_Type'; did you mean 'ITM_Type'?
 1816 | __STATIC_INLINE void __NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
      |                                         ^~~~~~~~~


要么

Drivers/CMSIS/Include/core_cm4.h: In function 'NVIC_EncodePriority':
Drivers/CMSIS/Include/core_cm4.h:1869:64: error: '__NVIC_PRIO_BITS' undeclared (first use in this function)
 1869 |   PreemptPriorityBits = ((7UL - PriorityGroupTmp) > (uint32_t)(__NVIC_PRIO_BITS)) ? (uint32_t)(__NVIC_PRIO_BITS) : (uint32_t)(7UL - PriorityGroupTmp);


因此,似乎没有定义IRQn_Type和__NVIC_PRIO_BITS。

据我了解,数据类型在stm32f407xx.h文件中定义,我告诉make在哪里可以找到它:
-IDrivers / CMSIS / Device / ST / STM32F4xx / Include



编辑

我刚刚看到的第一个错误是:

In file included from Drivers/CMSIS/DSP/Include/arm_math.h:322,
                 from Src/dsp/dsp.c:1:
Drivers/CMSIS/Include/core_cm4.h:105:8: error: #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
  105 |       #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
      |        ^~~~~

In file included from Src/dsp/dsp.c:3:
Drivers/CMSIS/Include/core_cm4.h:1688:39: error: unknown type name 'IRQn_Type'; did you mean 'ITM_Type'?
 1688 | __STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn)
      |                                       ^~~~~~~~~
      |                                       ITM_Type


我的模板makefile由CubeMX生成,但是我做了一些更改(更改了文件夹的结构,添加了定义和包含目录)。

# C defines
C_DEFS =  \
-DUSE_HAL_DRIVER \
-DSTM32F407xx \
-DARM_MATH_CM4

# C includes
C_INCLUDES =  \
-IConfigs \
-ISrc \
-IDrivers/STM32F4xx_HAL_Driver/Inc \
-IDrivers/STM32F4xx_HAL_Driver/Inc/Legacy \
-IDrivers/CMSIS/Device/ST/STM32F4xx/Include \
-IDrivers/CMSIS/Include \
-IDrivers/CMSIS/DSP/Include





我得到这个错误:

In file included from Drivers/CMSIS/DSP/Include/arm_math.h:322,
                 from Src/dsp/filter.h:9,
                 from Src/dsp/filter.c:1:
Drivers/CMSIS/Include/core_cm4.h:105:8: error: #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
  105 |       #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)"
      |        ^~~~~
make: *** [Makefile:228: build/filter.o] Error 1


如果我将此行放在#include <arm_math.h>上方。

#define STM32F407xx
#include "stm32f4xx.h"




-D__FPU_PRESENT也添加到定义之后,我仍然收到错误:

In file included from Src/dsp/dsp.c:4:
Drivers/CMSIS/Include/core_cm4.h:1688:39: error: unknown type name 'IRQn_Type'; did you mean 'ITM_Type'?
 1688 | __STATIC_INLINE void __NVIC_EnableIRQ(IRQn_Type IRQn)

最佳答案

为了确保包含特定微控制器的头文件,您需要定义相关的宏。对于您的情况,您需要确保将-DSTM32F407xx传递给编译器。具体执行方式将取决于您的构建环境。

完成后,相关的头文件将为automatically included via stm32f4xx.h

如果您想知道如何确保依次包含stm32f4xx.h-以及是否需要将其明确包含在您自己的源文件中...

通常,您不需要显式包含stm32f4xx.h。只要包括标准外设之一(例如RCC或GPIO)的头文件,该文件就会自动包含在内。

因此,包含链可能如下所示:


stm32f4xx_rcc.h

stm32f4xx.h


stm32f407xx.h




后两个是自动的-只要在预处理器标志中传递-DSTM32F407xx

关于c - 未知的数据类型IRQn_Type,,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56489064/

10-11 21:30