0

I'm new to stm32 and I program on linux shell.

Everytime I watch a arm gcc makefile example, I saw a lot of gcc flags attached. I wanna know how to determine these flags for a specific type of board (stm32f10x, for example). Or should I say what documentation should I check for these information. Or these flags are basically the same for different boards?

Here's a makefile example I found in https://github.com/rowol/stm32_discovery_arm_gcc.git, and I don't know what flags like -mcpu, -mfpu are about.

# 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
LunarEclipse
  • 661
  • 1
  • 4
  • 14
  • The compiler flags are not "for board" only for your needs. As a very beginner I would advice to use IDE like STM32CubeMX IDE which will generate the build files for you. Do not push yourself too far beyond your knowledge. Rather focus on programming than compiler options – 0___________ Nov 27 '21 at 10:52

1 Answers1

0

The flags basically indicate what type of processor it is, this information is required by the compiler to cross compiler to the specific processor.

-mcpu: is the arm cortex type. e.g: cortex-m4, cortex-m7, cortex-m0 or cortex-m0+. The type of processor is the same for the different STM families. e.g. STM32F4 is a family of cortex-m4 processors. This information can be found in the datasheet and is often mentioned in the summary or specification when searching for chips.

-mfpu is the floating point unit type, or put another way what does a floating point look like on your system. Embedded Artistry has a nice write-up about this: https://embeddedartistry.com/blog/2017/10/11/demystifying-arm-floating-point-compiler-options/

-mfloat-abi is another flag you need for specific board, this can be hard or soft depending on the fact if the STM32 chip has a floating point unit or not. If it does you want to set this to hard.

Another thing that is important for cross compiling to different chips is specifying a linker script for your specific chip. This is the .ld file that is present and it specifies the memory regions and where all the code goes.

As a tip use STM32CubeMX to generate makefile projects for your given chip. STM32CubeMX is a tool from ST, which allows you to generate the project skeleton for several IDE's and also as a bare makefile. This makefile will give you all the above information including the linker script to compile for your specific target.

Another good reference is the GCC compiler documentation which you can find here: https://gcc.gnu.org/onlinedocs/gcc-10.3.0/gcc/Invoking-GCC.html#Invoking-GCC

Jort
  • 96
  • 1
  • 1