KEIL报错:error in include chain(cmsis_armcc.h):expected identifier or '(' 。

本文解决了一个Keil编译器中常见的问题,即使编译成功,但在头文件前出现红色“X”。通过修改UVCC.ini文件,将特定头文件添加到其中,成功消除了错误标记,使界面更加整洁。

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

今天用Keil的时候出现了一个能逼死强迫症的问题。

具体表现是编译通过了,输出显示 0 warning 0 error !。

但是在include头文件时,某一行前面出现了一个红色的“X"!

这个其实也没有什么影响,可以直接忽略掉,因为编译通过了,下载运行也没有任何问题,但是还是不能忍,不能忍呀~

于是我就找了找解决办法,果然被我找到了( > _ < )

Keil报错.....(问题解决从未开始到放弃) 这篇博主说了,因为Keil版本的问题可能升级下版本就可以解决这个问题,不过我用的版本目前是V5.25,和博主文章里提到的版本不同,或者直接忽略掉。

不过我没有像博主说的直接忽略掉,而是找到了Keil的安装目录下的 UV4 文件夹,搜索找到文件夹中的 UVCC.ini 文件,用记事本打开,将报错的那个头文件添加到文件中 (即添加一句 xxxx.h  = *)。

然后保存,关掉之前打开的Keil,重新再打开Keil就会发现红色的“X"不见了,不见了。顿时舒心很多。谢谢上文博主提供的方法。

 

../Middlewares/ST/ARM/DSP/Inc/arm_math.h(1132): warning: #47-D: incompatible redefinition of macro "__PKHBT" (declared at line 852 of "../Drivers/CMSIS/Include/cmsis_armcc.h") #define __PKHBT(ARG1, ARG2, ARG3) ( (((int32_t)(ARG1) << 0) & (int32_t)0x0000FFFF) | \ ../Middlewares/ST/ARM/DSP/Inc/arm_math.h(1134): warning: #47-D: incompatible redefinition of macro "__PKHTB" (declared at line 855 of "../Drivers/CMSIS/Include/cmsis_armcc.h") #define __PKHTB(ARG1, ARG2, ARG3) ( (((int32_t)(ARG1) << 0) & (int32_t)0xFFFF0000) | \ ../Middlewares/ST/ARM/DSP/Inc/arm_math.h(1735): error: #79: expected a type specifier __STATIC_FORCEINLINE int32_t __SMMLA( ../Middlewares/ST/ARM/DSP/Inc/arm_math.h(1735): error: #101: "int32_t" has already been declared in the current scope __STATIC_FORCEINLINE int32_t __SMMLA( ../Middlewares/ST/ARM/DSP/Inc/arm_math.h(1735): error: #141-D: unnamed prototyped parameters not allowed when body is present __STATIC_FORCEINLINE int32_t __SMMLA( ../Middlewares/ST/ARM/DSP/Inc/arm_math.h(1740): error: #20: identifier "sum" is undefined return (sum + (int32_t) (((int64_t) x * y) >> 32)); ../Middlewares/ST/ARM/DSP/Inc/arm_math.h(1740): error: #20: identifier "x" is undefined return (sum + (int32_t) (((int64_t) x * y) >> 32)); ../Middlewares/ST/ARM/DSP/Inc/arm_math.h(1740): error: #20: identifier "y" is undefined return (sum + (int32_t) (((int64_t) x * y) >> 32)); ../Middlewares/ST/ARM/DSP/Inc/arm_math.h(2680): error: #757: function "int32_t" is not a type name int32_t shift, ../Middlewares/ST/ARM/DSP/Inc/arm_math.h(2695): error: #757: function "int32_t" is not a type name int32_t shift, ../Middlewares/ST/ARM/DSP/Inc/arm_math.h(2793): error: #757: function "int32_t" is not a type name int32_t resetStateFlag); ../Middlewares/ST/ARM/DSP/Inc/arm_math.h(2811): error: #757: function "int32_t" is not a type name int32_t resetStateFlag); ../Middlewares/ST/ARM/DSP/Inc/arm_math.h(2830): error: #757: function "int32_t" is not a type name int32_t resetStateFlag); ../Middlewares/ST/ARM/DSP/Inc/arm_math.h(5532): error: #757: function "int32_t" is not a type name int32_t *pTapDelay; /**< points to the array of delay values. The array is of length numTaps. */ ../Middlewares/ST/ARM/DSP/Inc/arm_math.h(5545): error: #757: function "int32_t" is not a type name int32_t *pTapDelay; /**< points to the array of delay values. The array is of length numTaps. */ ../Middlewares/ST/ARM/DSP/Inc/arm_math.h(5558): error: #757: function "int32_t" is not a type name int32_t *pTapDelay; /**< points to the array of delay values. The array is of length numTaps. */ ../Middlewares/ST/ARM/DSP/Inc/arm_math.h(5571): error: #757: function "int32_t" is not a type name int32_t *pTapDelay; /**< points to the array of delay values. The array is of length numTaps. */ ../Middlewares/ST/ARM/DSP/Inc/arm_math.h(5606): error: #757: function "int32_t" is not a type name int32_t * pTapDelay, ../Middlewares/ST/ARM/DSP/Inc/arm_math.h(5642): error: #757: function "int32_t" is not a type name int32_t * pTapDelay, ../Middlewares/ST/ARM/DSP/Inc/arm_math.h(5680): error: #757: function "int32_t" is not a type name int32_t * pTapDelay, ../Middlewares/ST/ARM/DSP/Inc/arm_math.h(5718): error: #757: function "int32_t" is not a type name int32_t * pTapDelay, ../Middlewares/ST/ARM/DSP/Inc/arm_math.h(6491): warning: #174-D: expression has no effect int32_t i; /* Index variable */ ../Middlewares/ST/ARM/DSP/Inc/arm_math.h(6491): error: #65: expected a ";" int32_t i; /* Index variable */ ../Middlewares/ST/ARM/DSP/Inc/arm_math.h(6495): error: #20: identifier "i" is undefined i = (int32_t) ((x - S->x1) / xSpacing); ../Middlewares/ST/ARM/DSP/Inc/arm_math.h(6548): warning: #174-D: expression has no effect int32_t index; /* Index to read nearest output values */ ../Middlewares/ST/ARM/DSP/Inc/arm_math.h(6548): error: #65: expected a ";" int32_t index; /* Index to read nearest output values */ ../Middlewares/ST/ARM/DSP/Inc/arm_math.h(6553): error: #20: identifier "index" is undefined index = ((x & (q31_t)0xFFF00000) >> 20); ../Middlewares/ST/ARM/DSP/Inc/arm_math.h(6606): warning: #174-D: expression has no effect int32_t index; /* Index to read nearest output values */ ../Middlewares/ST/ARM/DSP/Inc/arm_math.h(6606): error: #65: expected a ";" int32_t index; /* Index to read nearest output values */ ../Middlewares/ST/ARM/DSP/Inc/arm_math.h(6611): error: #20: identifier "index" is undefined index = ((x & (int32_t)0xFFF00000) >> 20); ../Middlewares/ST/ARM/DSP/Inc/arm_math.h(6611): error: #31: expression must have integral type index = ((x & (int32_t)0xFFF00000) >> 20); ../Middlewares/ST/ARM/DSP/Inc/arm_math.h(6611): error: #18: expected a ")" index = ((x & (int32_t)0xFFF00000) >> 20); ../Middlewares/ST/ARM/DSP/Inc/arm_math.h(6911): error: #757: function "int32_t" is not a type name int32_t * circBuffer, ../Middlewares/ST/ARM/DSP/Inc/arm_math.h(6912): error: #757: function "int32_t" is not a type name int32_t L, ../Middlewares/ST/ARM/DSP/Inc/arm_math.h(6914): error: #757: function "int32_t" is not a type name int32_t bufferInc, ..\User\modules\master_process.c: 5 warnings, 30 errors
06-07
*** Using Compiler 'V6.7', folder: 'D:\Keil5 max\ARM\ARMCLANG\Bin' Rebuild target 'Target 1' compiling dl_adc12.c... compiling dl_aesadv.c... compiling dl_aes.c... ../../../source/ti/driverlib/dl_flashctl.c(60): error: "Compiler not supported for this function" #error "Compiler not supported for this function" ^ ../../../source/ti/driverlib/dl_flashctl.c(62): error: unknown type name 'RAMFUNC' RAMFUNC static DL_FLASHCTL_COMMAND_STATUS DL_FlashCTL_executeCommandFromRAM( ^ ../../../source/ti/driverlib/dl_flashctl.c(62): error: expected identifier or '(' RAMFUNC static DL_FLASHCTL_COMMAND_STATUS DL_FlashCTL_executeCommandFromRAM( ^ 3 errors generated. compiling dl_flashctl.c... compiling dl_comp.c... compiling dl_i2c.c... compiling dl_keystorectl.c... compiling dl_gpamp.c... compiling dl_dma.c... compiling dl_dac12.c... compiling dl_common.c... compiling dl_lcd.c... compiling dl_crc.c... compiling dl_crcp.c... compiling dl_gpio.c... compiling dl_iwdt.c... compiling dl_mathacl.c... compiling dl_lfss.c... compiling dl_mcan.c... compiling dl_opa.c... compiling dl_rtc.c... compiling dl_rtc_a.c... compiling dl_rtc_b.c... compiling dl_rtc_common.c... compiling dl_scratchpad.c... compiling dl_spi.c... compiling dl_timera.c... compiling dl_tamperio.c... compiling dl_timer.c... compiling dl_timerg.c... compiling dl_trng.c... compiling dl_uart.c... assembling startup_mspm0g350x_uvision.s... compiling dl_vref.c... compiling dl_wwdt.c... compiling dl_interrupt.c... compiling dl_sysctl_mspm0g1x0x_g3x0x.c... ../ti_msp_dl_config.c(47): error: unknown type name 'SYSCONFIG_WEAK' SYSCONFIG_WEAK void SYSCFG_DL_init(void) ^ ../ti_msp_dl_config.c(47): error: expected identifier or '(' SYSCONFIG_WEAK void SYSCFG_DL_init(void) ^ ../ti_msp_dl_config.c(55): error: unknown type name 'SYSCONFIG_WEAK' SYSCONFIG_WEAK void SYSCFG_DL_initPower(void) ^ ../ti_msp_dl_config.c(55): error: expected identifier or '(' SYSCONFIG_WEAK void SYSCFG_DL_initPower(void) ^
07-29
Build started: Project: gpio_toggle_output_LP_MSPM0G3507_nortos_keil *** Using Compiler 'V6.5', folder: 'D:\keil32\ARM\ARMCLANG\Bin' Build target 'gpio_toggle_output_LP_MSPM0G3507_nortos_keil' Before Build - User command #1: cmd.exe /C "C:\Users\liang\Desktop\电赛\mspm0\examples\ganwei_wu_mcu\MSPM0G3507_Demo\No_mcu\gpio_toggle_output\keil\../../../../../../tools/keil/syscfg.bat 'C:\Users\liang\Desktop\电赛\mspm0\examples\ganwei_wu_mcu\MSPM0G3507_Demo\No_mcu\gpio_toggle_output\keil\' gpio_toggle_output.syscfg" 'H' 不是内部或外部命令,也不是可运行的程序 或批处理文件。 文件名、目录名或卷标语法不正确。 'SysConfig宸ュ叿锛岃妫€鏌ヨ矾寰勬槸鍚︽纭紒' 不是内部或外部命令,也不是可运行的程序 或批处理文件。 '瀹為檯璺緞锛?SYSCFG_CLI_PATH' 不是内部或外部命令,也不是可运行的程序 或批处理文件。 ArmClang.exe: error: unsupported argument 'armasm' to option 'Wa,' ArmClang.exe: error: unsupported argument '--pd' to option 'Wa,' ArmClang.exe: error: unsupported argument '__UVISION_VERSION SETA 538' to option 'Wa,' ArmClang.exe: error: unsupported argument 'armasm' to option 'Wa,' ArmClang.exe: error: unsupported argument '--pd' to option 'Wa,' ArmClang.exe: error: unsupported argument '__MSPM0G3507__ SETA 1' to option 'Wa,' assembling startup_mspm0g350x_uvision.s... warning: unknown warning option '-Wno-nonportable-include-path'; did you mean '-Wno-gnu-include-next'? [-Wunknown-warning-option] 1 warning generated. compiling ADC.c... warning: unknown warning option '-Wno-nonportable-include-path'; did you mean '-Wno-gnu-include-next'? [-Wunknown-warning-option] 1 warning generated. compiling Uart.c... warning: unknown warning option '-Wno-nonportable-include-path'; did you mean '-Wno-gnu-include-next'? [-Wunknown-warning-option] 1 warning generated. compiling gpio_toggle_output.c... warning: unknown warning option '-Wno-nonportable-include-path'; did you mean '-Wno-gnu-include-next'? [-Wunknown-warning-option] 1 warning generated. compiling No_Mcu_Ganv_Grayscale_Sensor.c... warning: unknown warning option '-Wno-nonportable-include-path'; did you mean '-Wno-gnu-include-next'? [-Wunknown-warning-option] 1 warning generated. compiling Time.c... warning: unknown warning option '-Wno-nonportable-include-path'; did you mean '-Wno-gnu-include-next'? [-Wunknown-warning-option] ../ti_msp_dl_config.c(47): error: unknown type name 'SYSCONFIG_WEAK' SYSCONFIG_WEAK void SYSCFG_DL_init(void) ^ ../ti_msp_dl_config.c(47): error: expected identifier or '(' SYSCONFIG_WEAK void SYSCFG_DL_init(void) ^ ../ti_msp_dl_config.c(62): error: unknown type name 'SYSCONFIG_WEAK' SYSCONFIG_WEAK void SYSCFG_DL_initPower(void) ^ ../ti_msp_dl_config.c(62): error: expected identifier or '(' SYSCONFIG_WEAK void SYSCFG_DL_initPower(void) ^ ../ti_msp_dl_config.c(82): error: unknown type name 'SYSCONFIG_WEAK' SYSCONFIG_WEAK void SYSCFG_DL_GPIO_init(void) ^ ../ti_msp_dl_config.c(82): error: expected identifier or '(' SYSCONFIG_WEAK void SYSCFG_DL_GPIO_init(void) ^ ../ti_msp_dl_config.c(139): error: unknown type name 'SYSCONFIG_WEAK' SYSCONFIG_WEAK void SYSCFG_DL_SYSCTL_init(void) ^ ../ti_msp_dl_config.c(139): error: expected identifier or '(' SYSCONFIG_WEAK void SYSCFG_DL_SYSCTL_init(void) ^ ../ti_msp_dl_config.c(184): error: unknown type name 'SYSCONFIG_WEAK' SYSCONFIG_WEAK void SYSCFG_DL_TIMER_1_init(void) { ^ ../ti_msp_dl_config.c(184): error: expected identifier or '(' SYSCONFIG_WEAK void SYSCFG_DL_TIMER_1_init(void) { ^ ../ti_msp_dl_config.c(206): error: unknown type name 'SYSCONFIG_WEAK' SYSCONFIG_WEAK void SYSCFG_DL_I2C_0_init(void) { ^ ../ti_msp_dl_config.c(206): error: expected identifier or '(' SYSCONFIG_WEAK void SYSCFG_DL_I2C_0_init(void) { ^ ../ti_msp_dl_config.c(244): error: unknown type name 'SYSCONFIG_WEAK' SYSCONFIG_WEAK void SYSCFG_DL_UART_0_init(void) ^ ../ti_msp_dl_config.c(244): error: expected identifier or '(' SYSCONFIG_WEAK void SYSCFG_DL_UART_0_init(void) ^ ../ti_msp_dl_config.c(268): error: unknown type name 'SYSCONFIG_WEAK' SYSCONFIG_WEAK void SYSCFG_DL_ADC1_init(void) ^ ../ti_msp_dl_config.c(268): error: expected identifier or '(' SYSCONFIG_WEAK void SYSCFG_DL_ADC1_init(void) ^ ../ti_msp_dl_config.c(282): error: unknown type name 'SYSCONFIG_WEAK' SYSCONFIG_WEAK void SYSCFG_DL_SYSTICK_init(void) ^ ../ti_msp_dl_config.c(282): error: expected identifier or '(' SYSCONFIG_WEAK void SYSCFG_DL_SYSTICK_init(void) ^ 1 warning and 18 errors generated. compiling ti_msp_dl_config.c... ".\Objects\gpio_toggle_output_LP_MSPM0G3507_nortos_keil.axf" - 24 Error(s), 6 Warning(s). Target not created. Build Time Elapsed: 00:01:29
最新发布
07-31
Build started: Project: xunji1 *** Using Compiler 'V5.06 update 5 (build 528)', folder: 'D:\Keil5 C51\ARM\ARMCC\Bin' Build target 'xunji1' compiling freertos.c... D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(165): warning: #47-D: incompatible redefinition of macro "__MPU_PRESENT" (declared at line 50 of "../Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xb.h") #define __MPU_PRESENT 0 /*!< Other STM32 devices does not provide an MPU */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(167): warning: #47-D: incompatible redefinition of macro "__CM3_REV" (declared at line 49 of "../Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xb.h") #define __CM3_REV 0x0200 /*!< Core Revision r2p0 */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(168): warning: #47-D: incompatible redefinition of macro "__NVIC_PRIO_BITS" (declared at line 51 of "../Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xb.h") #define __NVIC_PRIO_BITS 4 /*!< STM32 uses 4 Bits for the Priority Levels */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(169): warning: #47-D: incompatible redefinition of macro "__Vendor_SysTickConfig" (declared at line 52 of "../Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xb.h") #define __Vendor_SysTickConfig 0 /*!< Set to 1 if different SysTick Config is used */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(178): error: #101: "NonMaskableInt_IRQn" has already been declared in the current scope NonMaskableInt_IRQn = -14, /*!< 2 Non Maskable Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(179): error: #101: "MemoryManagement_IRQn" has already been declared in the current scope MemoryManagement_IRQn = -12, /*!< 4 Cortex-M3 Memory Management Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(180): error: #101: "BusFault_IRQn" has already been declared in the current scope BusFault_IRQn = -11, /*!< 5 Cortex-M3 Bus Fault Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(181): error: #101: "UsageFault_IRQn" has already been declared in the current scope UsageFault_IRQn = -10, /*!< 6 Cortex-M3 Usage Fault Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(182): error: #101: "SVCall_IRQn" has already been declared in the current scope SVCall_IRQn = -5, /*!< 11 Cortex-M3 SV Call Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(183): error: #101: "DebugMonitor_IRQn" has already been declared in the current scope DebugMonitor_IRQn = -4, /*!< 12 Cortex-M3 Debug Monitor Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(184): error: #101: "PendSV_IRQn" has already been declared in the current scope PendSV_IRQn = -2, /*!< 14 Cortex-M3 Pend SV Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(185): error: #101: "SysTick_IRQn" has already been declared in the current scope SysTick_IRQn = -1, /*!< 15 Cortex-M3 System Tick Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(188): error: #101: "WWDG_IRQn" has already been declared in the current scope WWDG_IRQn = 0, /*!< Window WatchDog Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(189): error: #101: "PVD_IRQn" has already been declared in the current scope PVD_IRQn = 1, /*!< PVD through EXTI Line detection Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(190): error: #101: "TAMPER_IRQn" has already been declared in the current scope TAMPER_IRQn = 2, /*!< Tamper Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(191): error: #101: "RTC_IRQn" has already been declared in the current scope RTC_IRQn = 3, /*!< RTC global Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(192): error: #101: "FLASH_IRQn" has already been declared in the current scope FLASH_IRQn = 4, /*!< FLASH global Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(193): error: #101: "RCC_IRQn" has already been declared in the current scope RCC_IRQn = 5, /*!< RCC global Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(194): error: #101: "EXTI0_IRQn" has already been declared in the current scope EXTI0_IRQn = 6, /*!< EXTI Line0 Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(195): error: #101: "EXTI1_IRQn" has already been declared in the current scope EXTI1_IRQn = 7, /*!< EXTI Line1 Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(196): error: #101: "EXTI2_IRQn" has already been declared in the current scope EXTI2_IRQn = 8, /*!< EXTI Line2 Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(197): error: #101: "EXTI3_IRQn" has already been declared in the current scope EXTI3_IRQn = 9, /*!< EXTI Line3 Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(198): error: #101: "EXTI4_IRQn" has already been declared in the current scope EXTI4_IRQn = 10, /*!< EXTI Line4 Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(199): error: #101: "DMA1_Channel1_IRQn" has already been declared in the current scope DMA1_Channel1_IRQn = 11, /*!< DMA1 Channel 1 global Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(200): error: #101: "DMA1_Channel2_IRQn" has already been declared in the current scope DMA1_Channel2_IRQn = 12, /*!< DMA1 Channel 2 global Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(201): error: #101: "DMA1_Channel3_IRQn" has already been declared in the current scope DMA1_Channel3_IRQn = 13, /*!< DMA1 Channel 3 global Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(202): error: #101: "DMA1_Channel4_IRQn" has already been declared in the current scope DMA1_Channel4_IRQn = 14, /*!< DMA1 Channel 4 global Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(203): error: #101: "DMA1_Channel5_IRQn" has already been declared in the current scope DMA1_Channel5_IRQn = 15, /*!< DMA1 Channel 5 global Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(204): error: #101: "DMA1_Channel6_IRQn" has already been declared in the current scope DMA1_Channel6_IRQn = 16, /*!< DMA1 Channel 6 global Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(205): error: #101: "DMA1_Channel7_IRQn" has already been declared in the current scope DMA1_Channel7_IRQn = 17, /*!< DMA1 Channel 7 global Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(252): error: #101: "ADC1_2_IRQn" has already been declared in the current scope ADC1_2_IRQn = 18, /*!< ADC1 and ADC2 global Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(253): error: #101: "USB_HP_CAN1_TX_IRQn" has already been declared in the current scope USB_HP_CAN1_TX_IRQn = 19, /*!< USB Device High Priority or CAN1 TX Interrupts */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(254): error: #101: "USB_LP_CAN1_RX0_IRQn" has already been declared in the current scope USB_LP_CAN1_RX0_IRQn = 20, /*!< USB Device Low Priority or CAN1 RX0 Interrupts */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(255): error: #101: "CAN1_RX1_IRQn" has already been declared in the current scope CAN1_RX1_IRQn = 21, /*!< CAN1 RX1 Interrupt */ ../Core/Src/freertos.c: 4 warnings, 30 errors compiling main.c... D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(165): warning: #47-D: incompatible redefinition of macro "__MPU_PRESENT" (declared at line 50 of "../Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xb.h") #define __MPU_PRESENT 0 /*!< Other STM32 devices does not provide an MPU */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(167): warning: #47-D: incompatible redefinition of macro "__CM3_REV" (declared at line 49 of "../Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xb.h") #define __CM3_REV 0x0200 /*!< Core Revision r2p0 */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(168): warning: #47-D: incompatible redefinition of macro "__NVIC_PRIO_BITS" (declared at line 51 of "../Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xb.h") #define __NVIC_PRIO_BITS 4 /*!< STM32 uses 4 Bits for the Priority Levels */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(169): warning: #47-D: incompatible redefinition of macro "__Vendor_SysTickConfig" (declared at line 52 of "../Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xb.h") #define __Vendor_SysTickConfig 0 /*!< Set to 1 if different SysTick Config is used */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(178): error: #101: "NonMaskableInt_IRQn" has already been declared in the current scope NonMaskableInt_IRQn = -14, /*!< 2 Non Maskable Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(179): error: #101: "MemoryManagement_IRQn" has already been declared in the current scope MemoryManagement_IRQn = -12, /*!< 4 Cortex-M3 Memory Management Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(180): error: #101: "BusFault_IRQn" has already been declared in the current scope BusFault_IRQn = -11, /*!< 5 Cortex-M3 Bus Fault Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(181): error: #101: "UsageFault_IRQn" has already been declared in the current scope UsageFault_IRQn = -10, /*!< 6 Cortex-M3 Usage Fault Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(182): error: #101: "SVCall_IRQn" has already been declared in the current scope SVCall_IRQn = -5, /*!< 11 Cortex-M3 SV Call Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(183): error: #101: "DebugMonitor_IRQn" has already been declared in the current scope DebugMonitor_IRQn = -4, /*!< 12 Cortex-M3 Debug Monitor Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(184): error: #101: "PendSV_IRQn" has already been declared in the current scope PendSV_IRQn = -2, /*!< 14 Cortex-M3 Pend SV Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(185): error: #101: "SysTick_IRQn" has already been declared in the current scope SysTick_IRQn = -1, /*!< 15 Cortex-M3 System Tick Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(188): error: #101: "WWDG_IRQn" has already been declared in the current scope WWDG_IRQn = 0, /*!< Window WatchDog Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(189): error: #101: "PVD_IRQn" has already been declared in the current scope PVD_IRQn = 1, /*!< PVD through EXTI Line detection Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(190): error: #101: "TAMPER_IRQn" has already been declared in the current scope TAMPER_IRQn = 2, /*!< Tamper Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(191): error: #101: "RTC_IRQn" has already been declared in the current scope RTC_IRQn = 3, /*!< RTC global Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(192): error: #101: "FLASH_IRQn" has already been declared in the current scope FLASH_IRQn = 4, /*!< FLASH global Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(193): error: #101: "RCC_IRQn" has already been declared in the current scope RCC_IRQn = 5, /*!< RCC global Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(194): error: #101: "EXTI0_IRQn" has already been declared in the current scope EXTI0_IRQn = 6, /*!< EXTI Line0 Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(195): error: #101: "EXTI1_IRQn" has already been declared in the current scope EXTI1_IRQn = 7, /*!< EXTI Line1 Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(196): error: #101: "EXTI2_IRQn" has already been declared in the current scope EXTI2_IRQn = 8, /*!< EXTI Line2 Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(197): error: #101: "EXTI3_IRQn" has already been declared in the current scope EXTI3_IRQn = 9, /*!< EXTI Line3 Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(198): error: #101: "EXTI4_IRQn" has already been declared in the current scope EXTI4_IRQn = 10, /*!< EXTI Line4 Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(199): error: #101: "DMA1_Channel1_IRQn" has already been declared in the current scope DMA1_Channel1_IRQn = 11, /*!< DMA1 Channel 1 global Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(200): error: #101: "DMA1_Channel2_IRQn" has already been declared in the current scope DMA1_Channel2_IRQn = 12, /*!< DMA1 Channel 2 global Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(201): error: #101: "DMA1_Channel3_IRQn" has already been declared in the current scope DMA1_Channel3_IRQn = 13, /*!< DMA1 Channel 3 global Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(202): error: #101: "DMA1_Channel4_IRQn" has already been declared in the current scope DMA1_Channel4_IRQn = 14, /*!< DMA1 Channel 4 global Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(203): error: #101: "DMA1_Channel5_IRQn" has already been declared in the current scope DMA1_Channel5_IRQn = 15, /*!< DMA1 Channel 5 global Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(204): error: #101: "DMA1_Channel6_IRQn" has already been declared in the current scope DMA1_Channel6_IRQn = 16, /*!< DMA1 Channel 6 global Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(205): error: #101: "DMA1_Channel7_IRQn" has already been declared in the current scope DMA1_Channel7_IRQn = 17, /*!< DMA1 Channel 7 global Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(252): error: #101: "ADC1_2_IRQn" has already been declared in the current scope ADC1_2_IRQn = 18, /*!< ADC1 and ADC2 global Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(253): error: #101: "USB_HP_CAN1_TX_IRQn" has already been declared in the current scope USB_HP_CAN1_TX_IRQn = 19, /*!< USB Device High Priority or CAN1 TX Interrupts */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(254): error: #101: "USB_LP_CAN1_RX0_IRQn" has already been declared in the current scope USB_LP_CAN1_RX0_IRQn = 20, /*!< USB Device Low Priority or CAN1 RX0 Interrupts */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(255): error: #101: "CAN1_RX1_IRQn" has already been declared in the current scope CAN1_RX1_IRQn = 21, /*!< CAN1 RX1 Interrupt */ ../Core/Src/main.c: 4 warnings, 30 errors compiling ja370.c... ../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim.h(84): error: #40: expected an identifier uint32_t ulse; /*!< Specifies the pulse value to be loaded into the Capture Compare Register. ../Drivers/STM32F1xx_HAL_Driver/Inc/stm32f1xx_hal_tim.h(116): error: #40: expected an identifier uint32_t ulse; /*!< Specifies the pulse value to be loaded into the Capture Compare Register. D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(165): warning: #47-D: incompatible redefinition of macro "__MPU_PRESENT" (declared at line 50 of "../Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xb.h") #define __MPU_PRESENT 0 /*!< Other STM32 devices does not provide an MPU */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(167): warning: #47-D: incompatible redefinition of macro "__CM3_REV" (declared at line 49 of "../Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xb.h") #define __CM3_REV 0x0200 /*!< Core Revision r2p0 */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(168): warning: #47-D: incompatible redefinition of macro "__NVIC_PRIO_BITS" (declared at line 51 of "../Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xb.h") #define __NVIC_PRIO_BITS 4 /*!< STM32 uses 4 Bits for the Priority Levels */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(169): warning: #47-D: incompatible redefinition of macro "__Vendor_SysTickConfig" (declared at line 52 of "../Drivers/CMSIS/Device/ST/STM32F1xx/Include/stm32f103xb.h") #define __Vendor_SysTickConfig 0 /*!< Set to 1 if different SysTick Config is used */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(178): error: #101: "NonMaskableInt_IRQn" has already been declared in the current scope NonMaskableInt_IRQn = -14, /*!< 2 Non Maskable Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(179): error: #101: "MemoryManagement_IRQn" has already been declared in the current scope MemoryManagement_IRQn = -12, /*!< 4 Cortex-M3 Memory Management Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(180): error: #101: "BusFault_IRQn" has already been declared in the current scope BusFault_IRQn = -11, /*!< 5 Cortex-M3 Bus Fault Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(181): error: #101: "UsageFault_IRQn" has already been declared in the current scope UsageFault_IRQn = -10, /*!< 6 Cortex-M3 Usage Fault Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(182): error: #101: "SVCall_IRQn" has already been declared in the current scope SVCall_IRQn = -5, /*!< 11 Cortex-M3 SV Call Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(183): error: #101: "DebugMonitor_IRQn" has already been declared in the current scope DebugMonitor_IRQn = -4, /*!< 12 Cortex-M3 Debug Monitor Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(184): error: #101: "PendSV_IRQn" has already been declared in the current scope PendSV_IRQn = -2, /*!< 14 Cortex-M3 Pend SV Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(185): error: #101: "SysTick_IRQn" has already been declared in the current scope SysTick_IRQn = -1, /*!< 15 Cortex-M3 System Tick Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(188): error: #101: "WWDG_IRQn" has already been declared in the current scope WWDG_IRQn = 0, /*!< Window WatchDog Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(189): error: #101: "PVD_IRQn" has already been declared in the current scope PVD_IRQn = 1, /*!< PVD through EXTI Line detection Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(190): error: #101: "TAMPER_IRQn" has already been declared in the current scope TAMPER_IRQn = 2, /*!< Tamper Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(191): error: #101: "RTC_IRQn" has already been declared in the current scope RTC_IRQn = 3, /*!< RTC global Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(192): error: #101: "FLASH_IRQn" has already been declared in the current scope FLASH_IRQn = 4, /*!< FLASH global Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(193): error: #101: "RCC_IRQn" has already been declared in the current scope RCC_IRQn = 5, /*!< RCC global Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(194): error: #101: "EXTI0_IRQn" has already been declared in the current scope EXTI0_IRQn = 6, /*!< EXTI Line0 Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(195): error: #101: "EXTI1_IRQn" has already been declared in the current scope EXTI1_IRQn = 7, /*!< EXTI Line1 Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(196): error: #101: "EXTI2_IRQn" has already been declared in the current scope EXTI2_IRQn = 8, /*!< EXTI Line2 Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(197): error: #101: "EXTI3_IRQn" has already been declared in the current scope EXTI3_IRQn = 9, /*!< EXTI Line3 Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(198): error: #101: "EXTI4_IRQn" has already been declared in the current scope EXTI4_IRQn = 10, /*!< EXTI Line4 Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(199): error: #101: "DMA1_Channel1_IRQn" has already been declared in the current scope DMA1_Channel1_IRQn = 11, /*!< DMA1 Channel 1 global Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(200): error: #101: "DMA1_Channel2_IRQn" has already been declared in the current scope DMA1_Channel2_IRQn = 12, /*!< DMA1 Channel 2 global Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(201): error: #101: "DMA1_Channel3_IRQn" has already been declared in the current scope DMA1_Channel3_IRQn = 13, /*!< DMA1 Channel 3 global Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(202): error: #101: "DMA1_Channel4_IRQn" has already been declared in the current scope DMA1_Channel4_IRQn = 14, /*!< DMA1 Channel 4 global Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(203): error: #101: "DMA1_Channel5_IRQn" has already been declared in the current scope DMA1_Channel5_IRQn = 15, /*!< DMA1 Channel 5 global Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(204): error: #101: "DMA1_Channel6_IRQn" has already been declared in the current scope DMA1_Channel6_IRQn = 16, /*!< DMA1 Channel 6 global Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(205): error: #101: "DMA1_Channel7_IRQn" has already been declared in the current scope DMA1_Channel7_IRQn = 17, /*!< DMA1 Channel 7 global Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(252): error: #101: "ADC1_2_IRQn" has already been declared in the current scope ADC1_2_IRQn = 18, /*!< ADC1 and ADC2 global Interrupt */ D:\Keil5 C51\ARM\PACK\Keil\STM32F1xx_DFP\2.4.1\Device\Include\stm32f10x.h(253): error: #101: "USB_HP_CAN1_TX_IRQn" has already been declared in the current scope USB_HP_CAN1_TX_IRQn = 19, /*!< USB Device High Priority or CAN1 TX Interrupts */ ..\Core\Src\ja370.c: 4 warnings, 30 errors "xunji1\xunji1.axf" - 90 Error(s), 12 Warning(s). Target not created. Build Time Elapsed: 00:00:02
06-18
<think>我们面对的问题是STM32F1xx项目中编译时出现头文件重复声明错误,特别是关于stm32f10x.h头文件中一些宏和中断号的重复声明。根据引用内容,我们可以分析错误原因并给出解决方案。错误原因分析:1.引用[2]提到stm32f10x.h定义了器件、中断线、数据类型、寄存器等,这意味着该头文件是项目必须的。2.引用[3]提到core_cm3.h中定义了CM3内核的寄存器组和中断相关寄存器(如NVIC),而stm32f10x.h也会定义类似内容,可能导致重复定义。3.错误信息中提到的宏(如__MPU_PRESENT,__CM3_REV,__NVIC_PRIO_BITS)和中断号(IRQn)很可能在多个头文件中被重复定义。解决方案:1.检查头文件包含顺序和条件编译:确保在包含stm32f10x.h之前没有包含core_cm3.h(或类似内核头文件),因为stm32f10x.h内部可能已经包含了core_cm3.h。同时,使用头文件保护宏(#ifndef...#define...#endif)防止重复包含。2.在STM32标准库中,stm32f10x.h已经包含了core_cm3.h,因此我们不应在其他地方再次包含core_cm3.h。检查项目中是否有显式包含core_cm3.h的地方,如果有,请移除。3.对于标准库中的头文件,我们应使用库提供的配置方式。例如,在包含stm32f10x.h之前,应该先包含stm32f10x_conf.h(该文件用于配置使用哪些外设头文件),并且确保在stm32f10x_conf.h中没有包含任何会导致重复定义的头文件。4.如果项目中使用了其他库(如FreeRTOS),则需要注意FreeRTOS的头文件可能也会包含core_cm3.h。例如,引用[4]中提到的portmacro.h可能包含与内核相关的定义。此时,我们需要调整包含顺序或通过宏定义来避免重复。具体步骤:步骤1:检查main.c(或其他顶层源文件)中的头文件包含顺序,确保如下:#include"stm32f10x.h"//这个头文件应该在最前面,因为它包含了内核定义和芯片外设定义//然后包含其他头文件,如FreeRTOS的头文件步骤2:检查是否在stm32f10x.h之前包含了其他内核相关的头文件(如core_cm3.h),如果有,请删除。步骤3:检查stm32f10x_conf.h文件,确保它只包含了外设的头文件(如stm32f10x_gpio.h,stm32f10x_rcc.h等),而不要包含core_cm3.h或类似的内核头文件。步骤4:如果使用FreeRTOS,注意FreeRTOSConfig.h中可能包含一些与内核相关的定义。确保在FreeRTOSConfig.h中,我们使用条件编译来检查是否已经定义了这些宏,例如:#ifndef__NVIC_PRIO_BITS#define__NVIC_PRIO_BITS4//根据实际情况设置优先级位数#endif步骤5:如果错误依然存在,可以尝试在编译器设置中定义宏,例如在预处理器选项中添加:__MPU_PRESENT=0//根据你的芯片是否具有MPU来设置,STM32F1通常没有MPU,所以设为0__CM3_REV=0x0201//根据芯片手册设置__NVIC_PRIO_BITS=4//设置优先级位数这样,在头文件中这些宏已经被定义,就不会再重复定义。步骤6:检查项目中是否有多个地方包含了stm32f10x.h,可以通过头文件保护来避免重复包含,标准库头文件通常已经有保护,但还是要检查。步骤7:如果上述步骤无法解决,可以查看错误信息中重复定义的具体变量名,然后使用预编译宏进行条件定义。例如,在包含stm32f10x.h之前,先定义这些宏,这样在stm32f10x.h内部就会跳过定义。示例代码(在包含stm32f10x.h之前):#define__MPU_PRESENT0#include"stm32f10x.h"但这种方法需要谨慎,因为必须确保定义的值正确。步骤8:如果错误发生在第三方库中,考虑更新第三方库或修改第三方库的头文件(在确保合法的情况下)添加头文件保护。常见错误原因:-重复包含头文件:同一个头文件被直接或间接包含了两次。-头文件保护缺失:虽然标准库头文件通常有保护,但自定义头文件可能没有。-不同库之间的冲突:例如标准外设库和FreeRTOS的portmacro.h都定义了相同的内容。通过以上步骤,通常可以解决重复声明的问题。</think>### 解决STM32F1xx头文件重复声明错误 在STM32F1xx项目中,`stm32f10x.h`与其他头文件(如CMSIS内核头文件)发生宏和中断号的重复声明,本质上是**头文件包含顺序冲突**或**多重包含防护失效**导致的。以下是系统解决方案: --- ### 错误原因分析 1. **CMSIS与标准库冲突** CMSIS内核头文件(如`core_cm3.h`)和`stm32f10x.h`均定义了以下内容: - 内核宏:`__MPU_PRESENT`, `__CM3_REV`, `__NVIC_PRIO_BITS` - 中断号:`IRQn_Type`枚举(如`NonMaskableInt_IRQn`) - 引用[3]中提到的NVIC寄存器组定义 2. **包含顺序错误** 若在项目中先包含`core_cm3.h`再包含`stm32f10x.h`,后者尝试重复定义相同内容。 3. **条件编译失效** 标准库未正确检测到CMSIS头文件已被包含(防护宏未生效)。 --- ### 解决方案(分步操作) #### 步骤1:统一头文件包含顺序 **强制先包含芯片级头文件**,确保`stm32f10x.h`优先处理: ```c // main.c 或 stm32f10x_conf.h #include "stm32f10x.h" // 必须在所有头文件之前 #include "core_cm3.h" // 内核文件在后 ``` #### 步骤2:检查标准库配置 在`stm32f10x.h`中,确认以下防护宏已启用(约第80行): ```c #if !defined (__STM32F10x_H) // 防护宏必须存在 #define __STM32F10x_H // ...原有内容... #endif /* __STM32F10x_H */ ``` #### 步骤3:预处理宏定义覆盖 在编译器全局预定义中**强制覆盖冲突宏**(以Keil MDK为例): 1. 打开工程选项 → C/C++选项卡 2. 在`Define:`字段添加: ``` __MPU_PRESENT=0, __CM3_REV=0x0201, __NVIC_PRIO_BITS=4 ``` (值根据具体芯片型号调整,STM32F103通常为`__CM3_REV=0x0201`) #### 步骤4:中断号冲突处理 若仍出现`IRQn_Type`重复定义: 1. 在`stm32f10x.h`中注释掉重复定义(约第423行): ```c // typedef enum IRQn { ... } IRQn_Type; // 注释此行 ``` 2. 确保`core_cm3.h`中的定义生效(CMSIS标准定义优先)。 --- ### 关键原理说明 1. **防护宏作用** `stm32f10x.h`通过`__STM32F10x_H`宏避免重复包含,但若`core_cm3.h`在其之前被包含,内核相关定义会被二次声明[^3]。 2. **宏优先级** 编译器预定义的宏(步骤3)会覆盖头文件内部定义,从根本上避免冲突[^1]。 3. **CMSIS兼容性** STM32标准库基于CMSIS实现,必须保持内核头文件的权威性,外设库应服从其定义[^2]。 --- ### 预防措施 - **头文件标准化**:始终以`stm32f10x.h`作为首个包含的头文件。 - **版本检查**:确认标准库版本(引用[1]中`__STM32F10X_STDPERIPH_VERSION`)与CMSIS包匹配。 - **清理冗余包含**:移除手动包含的`core_cm3.h`或`stm32f10x_conf.h`外其他外设头文件。 > 通过以上步骤,可彻底解决`__MPU_PRESENT`、`__CM3_REV`等宏及中断号的重复声明问题。若涉及RTOS(如FreeRTOS),需额外检查其`portmacro.h`是否包含内核文件(引用[4]),必要时调整包含顺序。
评论 29
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

微芯供氧

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

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

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

打赏作者

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

抵扣说明:

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

余额充值