为啥编译器标志“-mcpu=cortex-m3”与 stm32f10x 出错?

Posted

技术标签:

【中文标题】为啥编译器标志“-mcpu=cortex-m3”与 stm32f10x 出错?【英文标题】:Why the compiler flags “-mcpu=cortex-m3” goes wrong with stm32f10x?为什么编译器标志“-mcpu=cortex-m3”与 stm32f10x 出错? 【发布时间】:2020-03-24 17:22:07 【问题描述】:

stm32f10x的核心应该是cortex-m3,带有标志“-mcpu=cortex-m3”↓(这是makefile的部分):

CFLAGS += -T$(STD_PERIPH_LIBS)/Project/STM32F10x_StdPeriph_Template/TrueSTUDIO/STM3210B-EVAL/stm32_flash.ld
CFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m3 -mthumb-interwork
CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16

错误:

/root/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: error: /tmp/ccwnNCUm.o uses VFP register arguments, t1.elf does not
/root/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: failed to merge target specific data of file /tmp/ccwnNCUm.o
/root/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: error: /tmp/ccaQhPT1.o uses VFP register arguments, t1.elf does not
/root/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: failed to merge target specific data of file /tmp/ccaQhPT1.o
collect2: error: ld returned 1 exit status
Makefile:39: recipe for target 't1.elf' failed
make: *** [t1.elf] Error 1

但是将“-mcpu=cortex-m3”替换为“-mcpu=cortex-m4”后,错误消失,程序正常运行。

本篇介绍“st.com”

STM32F103 器件使用 Cortex-M3 内核,最高 CPU 速度为 72 兆赫。

那么为什么是“-mcpu=cortex-m4”而不是“-mcpu=cortex-m3”? 我的 arm-none-eabi-gcc:

gcc 版本 9.2.1 20191025(发布)[ARM/arm-9-branch 修订版 277599](用于 Arm 嵌入式处理器的 GNU 工具 9-2019-q4-major)

【问题讨论】:

这里没有足够的信息来给出明确的答案——我们需要minimal reproducible example。但是,错误消息表明,为您的各种构建目标指定的目标平台的详细信息不一致。 你也有这些标志-mfloat-abi=hard -mfpu=fpv4-sp-d16,这仅在 Cortex-M4 上可用,所以删除这两个,它可能会工作 错误uses VFP register arguments 对我来说看起来比较清楚。您为什么不调查什么是 VFP(如果您不知道)以及是否存在 FPU? 【参考方案1】:

Cortex-m3 没有 FPU 选项

【讨论】:

以上是关于为啥编译器标志“-mcpu=cortex-m3”与 stm32f10x 出错?的主要内容,如果未能解决你的问题,请参考以下文章

为啥我不能禁用 ARC(每个单个文件)?

mdk Arm Compiler V6注意事宜

为啥 -march=native 很少使用?

为啥库需要硬编码矢量化而不是编译器自动矢量化

为啥我的返回类型没有意义?

linux 生成的.o文件为啥带锁标志