Browse Source

simplify makefiles

master
Jan Koppe 2 years ago
parent
commit
cad43301a4
Signed by: j GPG Key ID: BE935B0735A2129B
5 changed files with 27 additions and 50 deletions
  1. 1
      .gitignore
  2. 18
      Makefile
  3. 28
      boards.stm32.mk
  4. 15
      main.c
  5. 15
      template_stm32.c

1
.gitignore

@ -1 +1,2 @@
*.elf
bin/

18
Makefile

@ -10,13 +10,19 @@ SFLAGS+= -fno-common -ffunction-sections -fdata-sections
SFLAGS+= -I./libopencm3/include -L./libopencm3/lib
LFLAGS+=-Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group
M0_FLAGS= $(SFLAGS) -mcpu=cortex-m0 -mthumb -msoft-float
M0P_FLAGS= $(SFLAGS) -mcpu=cortex-m0plus -mthumb -msoft-float
M3_FLAGS= $(SFLAGS) -mcpu=cortex-m3 -mthumb -msoft-float
M4FH_FLAGS= $(SFLAGS) -mcpu=cortex-m4 -mthumb -mfloat-abi=hard -mfpu=fpv4-sp-d16
M7SP_FLAGS= $(SFLAGS) -mcpu=cortex-m7 -mthumb -mfloat-abi=hard -mfpu=fpv5-sp-d16
LFLAGS_STM32=$(LFLAGS) main.c -T ld.stm32.basic
include boards.stm32.mk
# 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)
@ -28,11 +34,9 @@ libopencm3/lib/libopencm3_%.a: libopencm3/Makefile
$(MAKE) -C libopencm3
%.bin: %.elf
@#printf " OBJCOPY $(*).bin\n"
$(OBJCOPY) -Obinary $(*).elf $(*).bin
%.hex: %.elf
@#printf " OBJCOPY $(*).hex\n"
$(OBJCOPY) -Oihex $(*).elf $(*).hex
flash:

28
boards.stm32.mk

@ -1,28 +0,0 @@
# Instructions:
# 1) add a rule for your board to the bottom of this file
# 2) profit!
LFLAGS_STM32=$(LFLAGS) template_stm32.c -T ld.stm32.basic
# STM32F1 starts up with HSI at 8Mhz
STM32F1_CFLAGS=$(M3_FLAGS) -DSTM32F1 -DLITTLE_BIT=800000 $(LFLAGS_STM32) -lopencm3_stm32f1
define RAWMakeBoard
$(CC) -DRCC_LED1=$(1) -DPORT_LED1=$(2) -DPIN_LED1=$(3) $(4) -o $(OD)/stm32/$(5)
endef
define MakeBoard
BOARDS_ELF+=$(OD)/stm32/$(1).elf
BOARDS_BIN+=$(OD)/stm32/$(1).bin
BOARDS_HEX+=$(OD)/stm32/$(1).hex
$(OD)/stm32/$(1).elf: template_stm32.c libopencm3/lib/libopencm3_$(5).a
@echo " $(5) -> Creating $(OD)/stm32/$(1).elf"
$(call RAWMakeBoard,RCC_$(2),$(2),$(3),$(4),$(1).elf)
endef
define stm32f1board
$(call MakeBoard,$(1),$(2),$(3),$(STM32F1_CFLAGS),stm32f1)
endef
# make only for bluepill board :)
$(eval $(call stm32f1board,bluepill,GPIOC,GPIO13))

15
main.c

@ -0,0 +1,15 @@
#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/gpio.h>
int main(void) {
rcc_periph_clock_enable(RCC_GPIOC);
gpio_set_mode(GPIOC, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, GPIO13);
gpio_set(GPIOC, GPIO13);
while(1) {
/* wait a little bit */
for (int i = 0; i < 800000; i++) {
__asm__("nop");
}
gpio_toggle(GPIOC, GPIO13);
}
}

15
template_stm32.c

@ -1,15 +0,0 @@
#include <libopencm3/stm32/rcc.h>
#include <libopencm3/stm32/gpio.h>
int main(void) {
rcc_periph_clock_enable(RCC_LED1);
gpio_set_mode(PORT_LED1, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_PUSHPULL, PIN_LED1);
gpio_set(PORT_LED1, PIN_LED1);
while(1) {
/* wait a little bit */
for (int i = 0; i < LITTLE_BIT; i++) {
__asm__("nop");
}
gpio_toggle(PORT_LED1, PIN_LED1);
}
}
Loading…
Cancel
Save