首页 > 解决方案 > STM32 HSE VALUE 缺少二元运算符

问题描述

我在 SPL 库的 SW4STM32 中工作。我的 MCU 是 STM32F407(发现板)。我在 stm32f4xx.h 中有关于 HSE 的奇怪错误。

#if !defined  (HSE_VALUE) 
  #define HSE_VALUE    ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */

错误:

missing binary operator before token "8000000"

在控制台中:

C:/Users/Neptun/workspace/ex_vendor_dev/CMSIS/device/stm32f4xx.h:98:32: error: missing binary operator before token "8000000"
   #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
                                ^ 

我还有其他错误,但我很惊讶为什么会有问题。

控制台输出:

16:57:12 **** Incremental Build of configuration Release for project ex_vendor_dev ****
make -j4 all 
Building file: ../src/board_init_207.c
Building file: ../src/i2c.c
Building file: ../src/i2s.c
Building file: ../src/led.c
Invoking: MCU GCC Compiler
Invoking: MCU GCC Compiler
Invoking: MCU GCC Compiler
C:\Users\Neptun\workspace\ex_vendor_dev\Release
Invoking: MCU GCC Compiler
C:\Users\Neptun\workspace\ex_vendor_dev\Release
arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -DSTM32 -DSTM32F4 -DSTM32F407VGTx -DSTM32F407G_DISC1 -DSTM32F40XX -DSTM32F40_41xxx -DUSE_STDPERIPH_DRIVER -I"C:/Users/Neptun/workspace/ex_vendor_dev/StdPeriph_Driver/inc" -I"C:/Users/Neptun/workspace/ex_vendor_dev/inc" -I"C:/Users/Neptun/workspace/ex_vendor_dev/CMSIS/device" -I"C:/Users/Neptun/workspace/ex_vendor_dev/CMSIS/core" -O3 -Wall -fmessage-length=0 -ffunction-sections -c -MMD -MP -MF"src/board_init_207.d" -MT"src/board_init_207.o" -o "src/board_init_207.o" "../src/board_init_207.c"
C:\Users\Neptun\workspace\ex_vendor_dev\Release
C:\Users\Neptun\workspace\ex_vendor_dev\Release
arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -DSTM32 -DSTM32F4 -DSTM32F407VGTx -DSTM32F407G_DISC1 -DSTM32F40XX -DSTM32F40_41xxx -DUSE_STDPERIPH_DRIVER -I"C:/Users/Neptun/workspace/ex_vendor_dev/StdPeriph_Driver/inc" -I"C:/Users/Neptun/workspace/ex_vendor_dev/inc" -I"C:/Users/Neptun/workspace/ex_vendor_dev/CMSIS/device" -I"C:/Users/Neptun/workspace/ex_vendor_dev/CMSIS/core" -O3 -Wall -fmessage-length=0 -ffunction-sections -c -MMD -MP -MF"src/i2c.d" -MT"src/i2c.o" -o "src/i2c.o" "../src/i2c.c"
arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -DSTM32 -DSTM32F4 -DSTM32F407VGTx -DSTM32F407G_DISC1 -DSTM32F40XX -DSTM32F40_41xxx -DUSE_STDPERIPH_DRIVER -I"C:/Users/Neptun/workspace/ex_vendor_dev/StdPeriph_Driver/inc" -I"C:/Users/Neptun/workspace/ex_vendor_dev/inc" -I"C:/Users/Neptun/workspace/ex_vendor_dev/CMSIS/device" -I"C:/Users/Neptun/workspace/ex_vendor_dev/CMSIS/core" -O3 -Wall -fmessage-length=0 -ffunction-sections -c -MMD -MP -MF"src/i2s.d" -MT"src/i2s.o" -o "src/i2s.o" "../src/i2s.c"
arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16 -DSTM32 -DSTM32F4 -DSTM32F407VGTx -DSTM32F407G_DISC1 -DSTM32F40XX -DSTM32F40_41xxx -DUSE_STDPERIPH_DRIVER -I"C:/Users/Neptun/workspace/ex_vendor_dev/StdPeriph_Driver/inc" -I"C:/Users/Neptun/workspace/ex_vendor_dev/inc" -I"C:/Users/Neptun/workspace/ex_vendor_dev/CMSIS/device" -I"C:/Users/Neptun/workspace/ex_vendor_dev/CMSIS/core" -O3 -Wall -fmessage-length=0 -ffunction-sections -c -MMD -MP -MF"src/led.d" -MT"src/led.o" -o "src/led.o" "../src/led.c"
In file included from C:/Users/Neptun/workspace/ex_vendor_dev/StdPeriph_Driver/inc/misc.h:38:0,
                 from C:/Users/Neptun/workspace/ex_vendor_dev/inc/board_def.h:4,
                 from ../src/board_init_207.c:2:
C:/Users/Neptun/workspace/ex_vendor_dev/CMSIS/device/stm32f4xx.h:98:32: error: missing binary operator before token "8000000"
   #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
                                ^
C:/Users/Neptun/workspace/ex_vendor_dev/inc/board_def.h:31:5: note: in expansion of macro 'HSE_VALUE'
 #if HSE_VALUE != 8000000
     ^~~~~~~~~
In file included from C:/Users/Neptun/workspace/ex_vendor_dev/StdPeriph_Driver/inc/misc.h:38:0,
                 from C:/Users/Neptun/workspace/ex_vendor_dev/inc/board_def.h:4,
                 from ../src/i2s.c:1:
C:/Users/Neptun/workspace/ex_vendor_dev/CMSIS/device/stm32f4xx.h:98:32: error: missing binary operator before token "8000000"
   #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
                                ^
C:/Users/Neptun/workspace/ex_vendor_dev/inc/board_def.h:31:5: note: in expansion of macro 'HSE_VALUE'
 #if HSE_VALUE != 8000000
     ^~~~~~~~~
In file included from C:/Users/Neptun/workspace/ex_vendor_dev/StdPeriph_Driver/inc/misc.h:38:0,
                 from C:/Users/Neptun/workspace/ex_vendor_dev/inc/board_def.h:4,
                 from ../src/i2c.c:1:
C:/Users/Neptun/workspace/ex_vendor_dev/CMSIS/device/stm32f4xx.h:98:32: error: missing binary operator before token "8000000"
   #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
                                ^
C:/Users/Neptun/workspace/ex_vendor_dev/inc/board_def.h:31:5: note: in expansion of macro 'HSE_VALUE'
 #if HSE_VALUE != 8000000
     ^~~~~~~~~
In file included from C:/Users/Neptun/workspace/ex_vendor_dev/StdPeriph_Driver/inc/misc.h:38:0,
                 from C:/Users/Neptun/workspace/ex_vendor_dev/inc/board_def.h:4,
                 from ../src/led.c:1:
C:/Users/Neptun/workspace/ex_vendor_dev/CMSIS/device/stm32f4xx.h:98:32: error: missing binary operator before token "8000000"
   #define HSE_VALUE ((uint32_t)8000000) /*!< Value of the External oscillator in Hz */
                                ^
C:/Users/Neptun/workspace/ex_vendor_dev/inc/board_def.h:31:5: note: in expansion of macro 'HSE_VALUE'
 #if HSE_VALUE != 8000000
     ^~~~~~~~~
src/subdir.mk:87: recipe for target 'src/board_init_207.o' failed
make: *** [src/board_init_207.o] Error 1
src/subdir.mk:87: recipe for target 'src/i2s.o' failed
make: *** Waiting for unfinished jobs....
src/subdir.mk:87: recipe for target 'src/i2c.o' failed
make: *** [src/i2s.o] Error 1
make: *** [src/i2c.o] Error 1
make: *** [src/led.o] Error 1
src/subdir.mk:87: recipe for target 'src/led.o' failed

报告中提到的文件:misc.h:38:0

#include "stm32f4xx.h"

board_def.h:4

#include <misc.h>

board_init_207.c:2

#include <board_def.h>

board_def.h:31:5

#if HSE_VALUE != 8000000
  #error STM32F4-Discovery board uses 8 MHz external quarz.
#endif

删除 board_def.h 上的短语后出现错误:#error 设备类型未定义。在文件 startup_stm32.c 中:

#else
  #error Device type is not defined. 
#endif

我删除了这个并且错误消失了,但另一个是“#error STM32 device subfamily is unknown or undefined.”,似乎没有定义的设备。但在 stm32f4xx.h 中:

#if !defined (STM32F4XX) 
  #define STM32F4XX
#endif

标签: stm32stm32f4discoverystm32f4

解决方案


error: missing binary operator before token- 是来自预处理器的错误消息。消息文本非常混乱,gcc 邮件列表中有关于它的消息。

在您的情况下,此错误的原因是#if语句中的类型转换:

#if HSE_VALUE != 8000000

扩展到

#if ((uint32_t)8000000) != 8000000

预处理器只是不知道如何处理它,强制转换是编译器的事情。因此,您可以从中删除此条件表达式board_def.h或从中删除类型转换stm32f4xx.h。较新的库具有等效的代码,定义HSE_VALUE,移动到用户定义的部分。

另一种解决方案是HSE_VALUE在 makefile 中定义为 8000000,不使用强制转换运算符。


推荐阅读