未知数据类型 IRQn_Type,
Unknown datatypes IRQn_Type,
尝试构建我的项目时,出现如下错误:
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 生成的,但我做了一些更改(更改了我的文件夹的结构,添加了 defines 和 include 目录)。
# 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
后两者是自动的 - 只要在您的 pre-processor 标志中传递 -DSTM32F407xx
。
core_cm4.h
不应该直接包含。
相反,您 #define
MCU line,#include
header MCU series.
#define STM32F407xx
#include "stm32f4xx.h"
这将包括 stm32f407xx.h
,进而包括 core_cm4.h
。
直接包含 stm32f407xx.h
,不包含 #define
也可能有效。
IRQn_Type
基本上是一个枚举,它包含控制器具有的所有类型的中断的值。例如
enum IRQn_Type {
NonMaskableInt_IRQn = -14,
HardFault_IRQn = -13,
MemoryManagement_IRQn = -12,
BusFault_IRQn = -11,
UsageFault_IRQn = -10,
SecureFault_IRQn = -9,
SVCall_IRQn = -5,
DebugMonitor_IRQn = -4,
PendSV_IRQn = -2,
SysTick_IRQn = -1,
WWDG_STM_IRQn = 0,
PVD_STM_IRQn = 1
}
如果您的头文件不存在,则表示该文件已损坏或有人进行了更改。用新文件替换您的文件可能会解决您的问题。
尝试构建我的项目时,出现如下错误:
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 生成的,但我做了一些更改(更改了我的文件夹的结构,添加了 defines 和 include 目录)。
# 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
后两者是自动的 - 只要在您的 pre-processor 标志中传递 -DSTM32F407xx
。
core_cm4.h
不应该直接包含。
相反,您 #define
MCU line,#include
header MCU series.
#define STM32F407xx
#include "stm32f4xx.h"
这将包括 stm32f407xx.h
,进而包括 core_cm4.h
。
直接包含 stm32f407xx.h
,不包含 #define
也可能有效。
IRQn_Type
基本上是一个枚举,它包含控制器具有的所有类型的中断的值。例如
enum IRQn_Type {
NonMaskableInt_IRQn = -14,
HardFault_IRQn = -13,
MemoryManagement_IRQn = -12,
BusFault_IRQn = -11,
UsageFault_IRQn = -10,
SecureFault_IRQn = -9,
SVCall_IRQn = -5,
DebugMonitor_IRQn = -4,
PendSV_IRQn = -2,
SysTick_IRQn = -1,
WWDG_STM_IRQn = 0,
PVD_STM_IRQn = 1
}
如果您的头文件不存在,则表示该文件已损坏或有人进行了更改。用新文件替换您的文件可能会解决您的问题。