Skip to content

Instantly share code, notes, and snippets.

@67hz
Created Mar 12, 2020
Embed
What would you like to do?
Makefile for STM32 development
TARGET=main
CC=arm-none-eabi-gcc
LD=arm-none-eabi-gcc
AR=arm-none-eabi-ar
AS=arm-none-eabi-as
CP=arm-none-eabi-objcopy
OD=arm-none-eabi-objdump
SE=arm-none-eabi-size
SF=st-flash
BOARD = STM32F4
CFLAGS = -std=gnu99 -g -O2 -Wall -specs=nosys.specs -D$(BOARD)
CFLAGS += -mlittle-endian -mthumb -mthumb-interwork -mcpu=cortex-m0
CFLAGS += -fsingle-precision-constant -Wdouble-promotion
CM3_DIR = ~/embedded/libopencm3
# CMD_DIR_INCLUDE = $(CM3_DIR)/include/libopencm3/stm32/
CMD_DIR_INCLUDE = $(CM3_DIR)/include/
CMD_DIR_LIB = $(CM3_DIR)/lib/
# CMD_DIR_LIB = $(CM3_DIR)/lib/
INCLUDE = -I $(CMD_DIR_INCLUDE)
LDLIBS = $(CMD_DIR_LIB)
SRCS = main.c
.PHONY: $(TARGET)
$(TARGET): $(TARGET).elf
$(TARGET).elf: $(SRCS)
$(CC) $(INCLUDE) $(CFLAGS) -L$(LDLIBS) $^ -o $@ -lopencm3_stm32f4
$(CP) -O binary $(TARGET).elf $(TARGET).bin
clean:
rm -f *.o $(TARGET).elf $(TARGET).bin
flash:
$(SF) write $(TARGET).bin 0x8000000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment