C 未知数据类型IRQn_类型,

C 未知数据类型IRQn_类型,,c,makefile,stm32,hal,cmsis,C,Makefile,Stm32,Hal,Cmsis,尝试构建项目时,我会遇到如下错误: 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: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)
      |                                         ^~~~~~~~~

因此,似乎没有定义IRQn_类型和_NVIC_PRIO_位

据我所知,数据类型是在stm32f407xx.h文件中定义的,我告诉make在哪里可以找到它: -i驱动程序/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目录)


我只得到这个错误:

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
上面


在将
-D\u FPU\u 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
传递给编译器。具体如何实现这一点取决于构建环境

完成此操作后,相关头文件将被删除

如果您想知道如何确保依次包括
stm32f4xx.h
,并且如果需要在您自己的源文件中显式地包括它

通常,您不需要显式地包括
stm32f4xx.h
。只要包含其中一个标准外围设备(如RCC或GPIO)的头文件,它就会自动包含

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


  • stm32f4xx_rcc.h
    core_cm4.h
    不应直接包括在内

    相反,您可以定义MCU行,并包含MCU系列的标题

    这将包括
    stm32f407xx.h
    ,而后者又包括
    core\u cm4.h


    直接包括
    stm32f407xx.h
    ,而不使用
    #define
    也可能有效。

    IRQn\u 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 
    }
    

    若不存在头文件,则表示该文件已损坏或有人对其进行了更改。用新文件替换您的文件可能会解决您的问题。

    对不起,值得一提。已设置-DSTM32F407xx标志。(否则我也会得到错误:“请首先选择应用程序中使用的目标STM32F4xx设备(在STM32F4xx.h文件中)”。还有其他想法吗?@Drimer:你能发布你的Makefile的相关部分吗?我修改了我的问题,非常感谢你的帮助。嘿。谢谢你的回答。我添加了这些行,但仍然存在问题。我修改了我的问题。你能再查一下吗?
    #define STM32F407xx
    #include "stm32f4xx.h"
    
    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)
    
    #define STM32F407xx
    #include "stm32f4xx.h"
    
    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 
    }