0

我是 stm32 的新手,我在 linux shell 上编程。

每次我观看 arm gcc makefile 示例时,我都会看到很多附加的 gcc 标志。我想知道如何为特定类型的板(例如 stm32f10x)确定这些标志。或者我应该说我应该检查哪些文件以获取这些信息。或者这些标志对于不同的板基本相同?

这是我在https://github.com/rowol/stm32_discovery_arm_gcc.git中找到的一个 makefile 示例,我不知道 flags like-mcpu-mfpu什么。

# Put your stlink folder here so make burn will work.
STLINK=~/stlink.git

# Put your source files here (or *.c, etc)
SRCS=main.c system_stm32f4xx.c

# Binaries will be generated with this name (.elf, .bin, .hex, etc)
PROJ_NAME=blinky

# Put your STM32F4 library code directory here
STM_COMMON=../STM32F4-Discovery_FW_V1.1.0

# Normally you shouldn't need to change anything below this line!
#######################################################################################

CC=arm-none-eabi-gcc
OBJCOPY=arm-none-eabi-objcopy

CFLAGS  = -g -O2 -Wall -Tstm32_flash.ld 
CFLAGS += -mlittle-endian -mthumb -mcpu=cortex-m4 -mthumb-interwork
CFLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
CFLAGS += -I.

# Include files from STM libraries
CFLAGS += -I$(STM_COMMON)/Utilities/STM32F4-Discovery
CFLAGS += -I$(STM_COMMON)/Libraries/CMSIS/Include -I$(STM_COMMON)/Libraries/CMSIS/ST/STM32F4xx/Include
CFLAGS += -I$(STM_COMMON)/Libraries/STM32F4xx_StdPeriph_Driver/inc

# add startup file to build
SRCS += $(STM_COMMON)/Libraries/CMSIS/ST/STM32F4xx/Source/Templates/TrueSTUDIO/startup_stm32f4xx.s 
OBJS = $(SRCS:.c=.o)


.PHONY: proj

all: proj

proj: $(PROJ_NAME).elf

$(PROJ_NAME).elf: $(SRCS)
    $(CC) $(CFLAGS) $^ -o $@ 
    $(OBJCOPY) -O ihex $(PROJ_NAME).elf $(PROJ_NAME).hex
    $(OBJCOPY) -O binary $(PROJ_NAME).elf $(PROJ_NAME).bin

clean:
    rm -f *.o $(PROJ_NAME).elf $(PROJ_NAME).hex $(PROJ_NAME).bin

# Flash the STM32F4
burn: proj
    $(STLINK)/st-flash write $(PROJ_NAME).bin 0x8000000
4

1 回答 1

0

这些标志基本上表明它是什么类型的处理器,编译器需要此信息才能将编译器交叉编译到特定处理器。

-mcpu:是手臂皮质类型。例如:cortex-m4、cortex-m7、cortex-m0 或 cortex-m0+。不同 STM 系列的处理器类型相同。例如 STM32F4 是一个 cortex-m4 处理器系列。这些信息可以在数据表中找到,并且在搜索芯片时经常在摘要或规范中提到。

-mfpu是浮点单元类型,或者换一种说法,浮点在您的系统上是什么样子的。Embedded Artistry 对此有一篇很好的文章:https ://embeddedartistry.com/blog/2017/10/11/demystifying-arm-floating-point-compiler-options/

-mfloat-abi是特定板所需的另一个标志,这可以是硬的或软的,具体取决于 STM32 芯片是否具有浮点单元。如果确实如此,您想将其设置为困难。

对不同芯片进行交叉编译的另一件重要的事情是为您的特定芯片指定链接描述文件。这是存在的 .ld 文件,它指定了内存区域和所有代码的去向。

作为提示,使用 STM32CubeMX 为您的给定芯片生成 makefile 项目。STM32CubeMX 是 ST 的一个工具,它允许您为多个 IDE 生成项目框架,也可以作为一个裸 makefile。该 makefile 将为您提供上述所有信息,包括为您的特定目标编译的链接器脚本。

另一个很好的参考是 GCC 编译器文档,您可以在这里找到:https ://gcc.gnu.org/onlinedocs/gcc-10.3.0/gcc/Invoking-GCC.html#Invoking-GCC

于 2022-02-14T21:03:35.447 回答