【发布时间】:2021-12-24 01:57:39
【问题描述】:
我在 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
报告中提到的文件: 杂项.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
【问题讨论】:
-
这是来自编译器的所有消息吗?
#define本身不应产生错误,它必须来自使用 HSE_VALUE 的位置。 -
我同意。错误消息通常包含宏的使用位置和扩展方式的详细报告。
-
我会将控制台输出添加到我的帖子中
-
有一次,
HSE_VALUE可能被定义为8000000,并且可以在 C 和预处理器语句#if中使用。现在通过将其声明为(uint32_t)8000000使其成为类型安全的,并且不再与预处理器一起使用。stm32f4xx.h和board_dev.h是否都是由 SW4STM32 生成的,或者它们来自哪里?简单去掉board_dev.h中的三行是否合理? -
这些文件来自某人的项目。我删除了这些行,编译继续前进。还有另一个错误“#error 设备类型未定义。”。我在我的帖子中放了关于这个的代码。删除行后,stm32.h 中显示另一个错误“#error STM32 device subfamily is unknown or undefined.”所以设备可能没有定义。
标签: stm32 stm32f4discovery stm32f4