stm32 - 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
解决方案
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,不使用强制转换运算符。
推荐阅读
- javascript - 当我单击反应按钮时,如何将所选项目调用到模型中?
- c - 如何使用 IAR 解决下载和调试问题?
- c# - 尝试将 Azure Blob 存储 URI 添加到 Azure 存储表时出错
- java - Spring MVC 找到 JSP 视图但无法渲染
- ruby-on-rails - 从设备A重置密码时如何从设备B注销
- tensorflow - tf.compat.v1 的替代品
- sql - 查询每个 ID 的单个最旧记录
- python - discord.py 琐事命令错误,正确回答琐事时,它说我没有帐户可以给我货币,但我已注册
- reactjs - ReactJS 获取数据不显示
- python - Python:随机播放函数