2020-11-23 21:48:35 -05:00
|
|
|
# Makefile -- stm32bringup
|
2024-09-20 03:27:09 -04:00
|
|
|
# Copyright © 2020-2024 Renaud Fivet
|
2020-11-23 21:48:35 -05:00
|
|
|
|
|
|
|
### Build environment selection
|
|
|
|
|
|
|
|
ifeq (linux, $(findstring linux, $(MAKE_HOST)))
|
2021-02-12 21:47:22 -05:00
|
|
|
INSTALLDIR = $(HOME)/Packages
|
2021-02-24 21:15:55 -05:00
|
|
|
#REVDIR = gcc-arm-none-eabi-9-2019-q4-major
|
|
|
|
#REVDIR = gcc-arm-none-eabi-9-2020-q2-update
|
2021-09-27 22:07:06 -04:00
|
|
|
#REVDIR = gcc-arm-none-eabi-10-2020-q4-major
|
2022-01-30 21:24:30 -05:00
|
|
|
#REVDIR = gcc-arm-none-eabi-10.3-2021.07
|
2022-03-10 01:06:57 -05:00
|
|
|
#REVDIR = gcc-arm-none-eabi-10.3-2021.10
|
2022-08-23 02:54:00 -04:00
|
|
|
#REVDIR = gcc-arm-11.2-2022.02-x86_64-arm-none-eabi
|
2023-02-21 22:11:16 -05:00
|
|
|
#REVDIR = arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi
|
2023-05-30 00:12:13 -04:00
|
|
|
#REVDIR = arm-gnu-toolchain-12.2.rel1-x86_64-arm-none-eabi
|
2023-11-21 02:11:50 -05:00
|
|
|
#REVDIR = arm-gnu-toolchain-12.2.mpacbti-rel1-x86_64-arm-none-eabi
|
2024-09-20 03:27:09 -04:00
|
|
|
#REVDIR = arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi
|
|
|
|
REVDIR = arm-gnu-toolchain-13.3.rel1-x86_64-arm-none-eabi
|
2020-11-23 21:48:35 -05:00
|
|
|
else
|
2021-02-24 21:15:55 -05:00
|
|
|
DRIVE = d
|
2021-02-12 21:47:22 -05:00
|
|
|
ifeq (cygwin, $(findstring cygwin, $(MAKE_HOST)))
|
2021-02-24 21:15:55 -05:00
|
|
|
OSDRIVE = /cygdrive/$(DRIVE)
|
2021-02-12 21:47:22 -05:00
|
|
|
else ifeq (msys, $(findstring msys, $(MAKE_HOST)))
|
2021-02-24 21:15:55 -05:00
|
|
|
OSDRIVE = /$(DRIVE)
|
2021-02-12 21:47:22 -05:00
|
|
|
else
|
2021-02-24 21:15:55 -05:00
|
|
|
OSDRIVE = $(DRIVE):
|
2021-02-12 21:47:22 -05:00
|
|
|
endif
|
2021-02-24 21:15:55 -05:00
|
|
|
INSTALLDIR = $(OSDRIVE)/Program Files (x86)
|
|
|
|
#REVDIR = GNU Tools ARM Embedded/5.4 2016q2
|
|
|
|
#REVDIR = GNU Tools ARM Embedded/6 2017-q2-update
|
|
|
|
#REVDIR = GNU Tools ARM Embedded/7 2017-q4-major
|
|
|
|
#REVDIR = GNU Tools ARM Embedded/7 2018-q2-update
|
|
|
|
#REVDIR = GNU Tools ARM Embedded/9 2019-q4-major
|
|
|
|
#REVDIR = GNU Arm Embedded Toolchain/9 2020-q2-update
|
2021-09-27 22:07:06 -04:00
|
|
|
#REVDIR = GNU Arm Embedded Toolchain/10 2020-q4-major
|
2022-01-29 21:52:03 -05:00
|
|
|
#REVDIR = GNU Arm Embedded Toolchain/10 2021.07
|
2022-03-10 01:06:57 -05:00
|
|
|
#REVDIR = GNU Arm Embedded Toolchain/10 2021.10
|
2022-08-23 02:54:00 -04:00
|
|
|
#REVDIR = GNU Arm Embedded Toolchain/gcc-arm-11.2-2022.02-mingw-w64-i686-arm-none-eabi
|
2023-02-21 22:11:16 -05:00
|
|
|
#REVDIR = GNU Arm Embedded Toolchain/arm-gnu-toolchain-11.3.rel1-mingw-w64-i686-arm-none-eabi
|
2023-05-30 00:12:13 -04:00
|
|
|
#REVDIR = GNU Arm Embedded Toolchain/arm-gnu-toolchain-12.2.rel1-mingw-w64-i686-arm-none-eabi
|
2023-11-21 02:11:50 -05:00
|
|
|
#REVDIR = GNU Arm Embedded Toolchain/arm-gnu-toolchain-12.2.mpacbti-rel1-mingw-w64-i686-arm-none-eabi
|
2024-09-20 03:27:09 -04:00
|
|
|
#REVDIR = GNU Arm Embedded Toolchain/arm-gnu-toolchain-13.2.Rel1-mingw-w64-i686-arm-none-eabi
|
|
|
|
REVDIR = GNU Arm Embedded Toolchain/arm-gnu-toolchain-13.3.rel1-mingw-w64-i686-arm-none-eabi
|
2020-11-23 21:48:35 -05:00
|
|
|
endif
|
|
|
|
|
2021-02-24 21:15:55 -05:00
|
|
|
GCCDIR = $(INSTALLDIR)/$(REVDIR)
|
2021-02-12 21:47:22 -05:00
|
|
|
export PATH := $(GCCDIR)/bin:$(PATH)
|
|
|
|
|
|
|
|
BINPFX = @arm-none-eabi-
|
2020-12-05 05:08:25 -05:00
|
|
|
AR = $(BINPFX)ar
|
2020-11-23 21:48:35 -05:00
|
|
|
CC = $(BINPFX)gcc
|
|
|
|
OBJCOPY = $(BINPFX)objcopy
|
|
|
|
OBJDUMP = $(BINPFX)objdump
|
|
|
|
SIZE = $(BINPFX)size
|
|
|
|
|
|
|
|
### STM32F030F4P6 based board
|
|
|
|
|
2021-06-08 04:45:53 -04:00
|
|
|
PROJECT = f030f4
|
2021-03-03 02:02:02 -05:00
|
|
|
|
2021-06-18 01:24:54 -04:00
|
|
|
### Memory Models
|
2021-06-21 23:53:36 -04:00
|
|
|
# By default we use the memory mapping from linker script
|
2021-06-18 01:24:54 -04:00
|
|
|
|
|
|
|
# In RAM Execution, load and start by USART bootloader
|
2021-03-06 21:21:10 -05:00
|
|
|
# Bootloader uses first 2K of RAM, execution from bootloader
|
2021-03-03 02:02:02 -05:00
|
|
|
#FLASHSTART = 0x20000800
|
|
|
|
#FLASHSIZE = 2K
|
|
|
|
#RAMSTART = 0x20000000
|
|
|
|
#RAMSIZE = 2K
|
|
|
|
|
2021-06-18 01:24:54 -04:00
|
|
|
# In RAM Execution, load and start via SWD
|
|
|
|
# 4K RAM available, execution via SWD
|
|
|
|
#FLASHSTART = 0x20000000
|
|
|
|
#FLASHSIZE = 3K
|
|
|
|
#RAMSTART = 0x20000C00
|
|
|
|
#RAMSIZE = 1K
|
|
|
|
|
2021-03-06 21:21:10 -05:00
|
|
|
# In Flash Execution
|
2021-06-18 01:24:54 -04:00
|
|
|
# if FLASHSTART is not at beginning of FLASH: execution via bootloader or SWD
|
2021-06-21 23:53:36 -04:00
|
|
|
#FLASHSTART = 0x08000000
|
|
|
|
#FLASHSIZE = 16K
|
|
|
|
#RAMSTART = 0x20000000
|
|
|
|
#RAMSIZE = 4K
|
2021-03-06 21:21:10 -05:00
|
|
|
|
2021-06-21 23:53:36 -04:00
|
|
|
# ISR vector copied and mapped to RAM when FLASHSTART != 0x08000000
|
2021-06-18 01:24:54 -04:00
|
|
|
ifdef FLASHSTART
|
|
|
|
ifneq ($(FLASHSTART),0x08000000)
|
|
|
|
ifeq ($(FLASHSTART),0x20000000)
|
|
|
|
# Map isr vector in RAM
|
|
|
|
RAMISRV := 1
|
|
|
|
else
|
|
|
|
# Copy and map isr vector in RAM
|
|
|
|
RAMISRV := 2
|
|
|
|
endif
|
|
|
|
endif
|
2021-06-21 23:53:36 -04:00
|
|
|
BINLOC = $(FLASHSTART)
|
|
|
|
else
|
|
|
|
BINLOC = 0x08000000
|
2021-03-06 21:21:10 -05:00
|
|
|
endif
|
2021-03-03 02:02:02 -05:00
|
|
|
|
2021-06-21 23:53:36 -04:00
|
|
|
# build options
|
|
|
|
CRC32SIGN := 1
|
|
|
|
|
|
|
|
|
2020-11-23 21:48:35 -05:00
|
|
|
#SRCS = boot.c
|
|
|
|
#SRCS = ledon.c
|
|
|
|
#SRCS = blink.c
|
|
|
|
#SRCS = ledtick.c
|
|
|
|
#SRCS = cstartup.c
|
2020-11-27 23:54:11 -05:00
|
|
|
#SRCS = startup.c init.c success.c
|
2020-11-27 23:58:58 -05:00
|
|
|
#SRCS = startup.c board.c success.c
|
2020-12-02 22:15:47 -05:00
|
|
|
#SRCS = startup.c usart1tx.c hello.c
|
2020-12-04 19:13:29 -05:00
|
|
|
#SRCS = startup.c uplow.1.c uptime.1.c
|
2020-12-05 05:08:25 -05:00
|
|
|
#SRCS = startup.c uplow.2.c uptime.c printf.c putchar.c
|
|
|
|
#SRCS = startup.c uplow.2.c uptime.c
|
2020-12-07 04:36:11 -05:00
|
|
|
#SRCS = startup.c uplow.2.c hello.c
|
2020-12-08 03:45:48 -05:00
|
|
|
#SRCS = startup.c clocks.c uptime.c
|
2020-12-14 20:41:12 -05:00
|
|
|
#SRCS = startup.txeie.c txeie.c uptime.c
|
2020-12-18 19:39:18 -05:00
|
|
|
#SRCS = startup.txeie.c gpioa.c dht11main.c dht11.c
|
2020-12-29 01:26:39 -05:00
|
|
|
#SRCS = startup.txeie.c gpioa.c ds18b20main.c ds18b20.c
|
2021-02-09 02:36:03 -05:00
|
|
|
#SRCS = startup.txeie.c adc.c adcmain.c
|
2021-03-03 02:02:02 -05:00
|
|
|
#SRCS = startup.txeie.c adc.c adccalib.c ds18b20.c
|
2021-06-21 23:53:36 -04:00
|
|
|
#SRCS = startup.ram.c txeie.c uptime.1.c
|
|
|
|
SRCS = startup.crc.c txeie.c uptime.1.c
|
2022-02-03 20:28:40 -05:00
|
|
|
LIBSRCS = printf.c putchar.c puts.c # memset.c memcpy.c
|
|
|
|
ALLSRCS = $(SRCS) $(LIBSRCS)
|
2021-03-03 02:02:02 -05:00
|
|
|
|
2021-09-27 22:07:06 -04:00
|
|
|
CPU = -mthumb -mcpu=cortex-m0 --specs=nano.specs
|
2021-03-03 02:02:02 -05:00
|
|
|
ifdef RAMISRV
|
|
|
|
CDEFINES = -DRAMISRV=$(RAMISRV)
|
|
|
|
endif
|
2021-06-21 23:53:36 -04:00
|
|
|
ifdef CRC32SIGN
|
|
|
|
CDEFINES += -DCRC32SIGN=$(CRC32SIGN)
|
|
|
|
endif
|
|
|
|
WARNINGS=-pedantic -Wall -Wextra -Wstrict-prototypes
|
2021-03-03 02:02:02 -05:00
|
|
|
CFLAGS = $(CPU) -g $(WARNINGS) -Os $(CDEFINES)
|
|
|
|
|
|
|
|
LD_SCRIPT = generic.ld
|
2021-06-18 01:24:54 -04:00
|
|
|
ifdef FLASHSTART
|
|
|
|
LDOPTS =--defsym FLASHSTART=$(FLASHSTART) --defsym FLASHSIZE=$(FLASHSIZE)
|
|
|
|
LDOPTS +=--defsym RAMSTART=$(RAMSTART) --defsym RAMSIZE=$(RAMSIZE)
|
|
|
|
endif
|
2021-06-08 04:45:53 -04:00
|
|
|
LDOPTS +=-Map=$(subst .elf,.map,$@) -cref --print-memory-usage
|
|
|
|
comma :=,
|
|
|
|
space :=$() # one space before the comment
|
|
|
|
LDFLAGS =-Wl,$(subst $(space),$(comma),$(LDOPTS))
|
2020-11-23 21:48:35 -05:00
|
|
|
|
|
|
|
### Build rules
|
|
|
|
|
2021-02-24 21:15:55 -05:00
|
|
|
.PHONY: clean all version
|
2020-11-23 21:48:35 -05:00
|
|
|
|
2021-06-21 23:53:36 -04:00
|
|
|
all: $(PROJECT).$(BINLOC).bin $(PROJECT).hex
|
2020-11-23 21:48:35 -05:00
|
|
|
|
2021-02-24 21:15:55 -05:00
|
|
|
version:
|
|
|
|
@echo make $(MAKE_VERSION) $(MAKE_HOST)
|
|
|
|
@echo PATH="$(PATH)"
|
2021-03-03 02:02:02 -05:00
|
|
|
$(CC) --version
|
2021-02-24 21:15:55 -05:00
|
|
|
|
2020-11-23 21:48:35 -05:00
|
|
|
clean:
|
|
|
|
@echo CLEAN
|
2022-02-03 20:28:40 -05:00
|
|
|
@rm -f *.dep *.o *.elf *.map *.lst *.bin *.hex *.a
|
2020-11-23 21:48:35 -05:00
|
|
|
|
2022-02-03 20:28:40 -05:00
|
|
|
$(PROJECT).elf: $(SRCS:.c=.o) libstm32.a
|
2021-06-08 04:45:53 -04:00
|
|
|
boot.elf: boot.o
|
|
|
|
ledon.elf: ledon.o
|
|
|
|
blink.elf: blink.o
|
|
|
|
ledtick.elf: ledtick.o
|
|
|
|
cstartup.elf: cstartup.o
|
2020-11-23 21:48:35 -05:00
|
|
|
|
2021-06-08 04:45:53 -04:00
|
|
|
%.elf:
|
2020-11-23 21:48:35 -05:00
|
|
|
@echo $@
|
2021-06-08 04:45:53 -04:00
|
|
|
$(CC) $(CPU) -T$(LD_SCRIPT) $(LDFLAGS) -nostartfiles -o $@ $+
|
2021-09-27 22:07:06 -04:00
|
|
|
$(SIZE) $@
|
2021-06-08 04:45:53 -04:00
|
|
|
$(OBJDUMP) -hS $@ > $(subst .elf,.lst,$@)
|
2020-11-23 21:48:35 -05:00
|
|
|
|
|
|
|
%.bin: %.elf
|
|
|
|
@echo $@
|
|
|
|
$(OBJCOPY) -O binary $< $@
|
|
|
|
|
2021-06-21 23:53:36 -04:00
|
|
|
%.$(BINLOC).bin: %.elf
|
2021-06-08 04:45:53 -04:00
|
|
|
@echo $@
|
|
|
|
$(OBJCOPY) -O binary $< $@
|
2021-06-21 23:53:36 -04:00
|
|
|
ifdef CRC32SIGN
|
|
|
|
crc32/sign32 $@
|
|
|
|
mv signed.bin $@
|
|
|
|
|
|
|
|
%.hex: %.$(BINLOC).bin
|
|
|
|
@echo $@
|
2021-09-27 22:07:06 -04:00
|
|
|
$(OBJCOPY) --change-address=$(BINLOC) -I binary -O ihex $< $@
|
2021-06-21 23:53:36 -04:00
|
|
|
endif
|
2021-06-08 04:45:53 -04:00
|
|
|
|
2020-11-23 21:48:35 -05:00
|
|
|
%.hex: %.elf
|
|
|
|
@echo $@
|
|
|
|
$(OBJCOPY) -O ihex $< $@
|
2020-12-05 05:08:25 -05:00
|
|
|
|
2022-02-03 20:28:40 -05:00
|
|
|
libstm32.a: $(LIBSRCS:.c=.o)
|
2020-12-05 05:08:25 -05:00
|
|
|
$(AR) rc $@ $?
|
2022-01-29 21:52:03 -05:00
|
|
|
|
2022-02-03 20:28:40 -05:00
|
|
|
%.dep: %.c
|
|
|
|
@echo $@
|
|
|
|
$(CC) $(CDEFINES) -MM $< > $@
|
2022-01-29 21:52:03 -05:00
|
|
|
|
2022-02-03 20:28:40 -05:00
|
|
|
ifneq ($(MAKECMDGOALS),clean)
|
|
|
|
include $(ALLSRCS:.c=.dep)
|
|
|
|
endif
|