Libopencm3 blink template, simplified for only bluepill/stm32f1 target as a base template for stm32f1 projects
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

52 lines
1.4 KiB

PREFIX?=arm-none-eabi-
CC=$(PREFIX)gcc
OBJCOPY=$(PREFIX)objcopy
OD=bin
all: realall.really
SFLAGS= --static -nostartfiles -std=c11 -g3 -Os
SFLAGS+= -fno-common -ffunction-sections -fdata-sections
SFLAGS+= -I./libopencm3/include -L./libopencm3/lib
LFLAGS+=-Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group
M3_FLAGS= $(SFLAGS) -mcpu=cortex-m3 -mthumb -msoft-float
LFLAGS_STM32=$(LFLAGS) main.c -T ld.stm32.basic
# STM32F1 starts up with HSI at 8Mhz
STM32F1_CFLAGS=$(M3_FLAGS) -DSTM32F1 $(LFLAGS_STM32) -lopencm3_stm32f1
BOARDS_ELF+=$(OD)/stm32/bluepill.elf
BOARDS_BIN+=$(OD)/stm32/bluepill.bin
BOARDS_HEX+=$(OD)/stm32/bluepill.hex
$(OD)/stm32/bluepill.elf: main.c libopencm3/lib/libopencm3_stm32f1.a
@echo " stm32f1 -> Creating $(OD)/stm32/bluepill.elf"
$(CC) $(STM32F1_CFLAGS) -o $(OD)/stm32/bluepill.elf
realall.really: outdir $(BOARDS_ELF) $(BOARDS_BIN) $(BOARDS_HEX)
libopencm3/Makefile:
@echo "Initializing libopencm3 submodule"
git submodule update --init
libopencm3/lib/libopencm3_%.a: libopencm3/Makefile
$(MAKE) -C libopencm3
%.bin: %.elf
$(OBJCOPY) -Obinary $(*).elf $(*).bin
%.hex: %.elf
$(OBJCOPY) -Oihex $(*).elf $(*).hex
flash:
openocd -f interface/stlink-v2.cfg -f target/stm32f1x.cfg -c "program bin/stm32/bluepill.elf verify reset exit"
outdir:
mkdir -p $(OD)/stm32
clean:
$(RM) $(BOARDS_ELF) $(BOARDS_BIN) $(BOARDS_HEX)
.PHONY: realall.really outdir clean all
$(V).SILENT: