stm32cube-gcc/Makefile

200 lines
5.4 KiB
Makefile
Raw Permalink Normal View History

2015-02-08 22:53:23 +01:00
# STM32 Makefile for GNU toolchain and openocd
#
2015-05-02 17:09:19 +02:00
# This Makefile fetches the Cube firmware package from ST's' website.
# This includes: CMSIS, STM32 HAL, BSPs, USB drivers and examples.
#
# Usage:
# make cube Download and unzip Cube firmware
# make program Flash the board with OpenOCD
# make openocd Start OpenOCD
# make debug Start GDB and attach to OpenOCD
# make dirs Create subdirs like obj, dep, ..
# make template Prepare a simple example project in this dir
#
# Copyright 2015 Steffen Vogel
2015-02-08 22:53:23 +01:00
# License http://www.gnu.org/licenses/gpl.txt GNU Public License
# Author Steffen Vogel <post@steffenvogel.de>
# Link http://www.steffenvogel.de
#
# edited for the STM32F4-Discovery
2015-02-08 22:53:23 +01:00
# A name common to all output files (elf, map, hex, bin, lst)
TARGET = demo
# Take a look into $(CUBE_DIR)/Drivers/BSP for available BSPs
# name needed in upper case and lower case
BOARD = STM32F446ZE-Nucleo
BOARD_UC = STM32F4xx_Nucleo_144
BOARD_LC = stm32f4xx_nucleo_144
BSP_BASE = $(BOARD_LC)
2015-02-08 22:53:23 +01:00
OCDFLAGS = -f board/stm32f4discovery.cfg
GDBFLAGS =
2015-02-08 22:53:23 +01:00
#EXAMPLE = Templates
EXAMPLE = Examples/GPIO/GPIO_IOToggle
2015-02-08 22:53:23 +01:00
# MCU family and type in various capitalizations o_O
MCU_FAMILY = stm32f4xx
MCU_LC = stm32f446xx
MCU_MC = STM32F446xx
MCU_UC = STM32F446ZE
# path of the ld-file inside the example directories
LDFILE = $(EXAMPLE)/SW4STM32/$(BOARD_UC)/$(MCU_UC)Tx_FLASH.ld
#LDFILE = $(EXAMPLE)/TrueSTUDIO/$(BOARD_UC)/$(MCU_UC)_FLASH.ld
2015-02-08 22:53:23 +01:00
# Your C files from the /src directory
SRCS = main.c
SRCS += system_$(MCU_FAMILY).c
SRCS += stm32f4xx_it.c
2015-02-08 22:53:23 +01:00
2015-05-02 17:10:33 +02:00
# Basic HAL libraries
SRCS += stm32f4xx_hal_rcc.c stm32f4xx_hal_rcc_ex.c stm32f4xx_hal.c stm32f4xx_hal_cortex.c stm32f4xx_hal_gpio.c stm32f4xx_hal_pwr_ex.c $(BSP_BASE).c
2015-05-02 17:10:33 +02:00
# Directories
OCD_DIR = /usr/share/openocd/scripts
2015-02-08 22:53:23 +01:00
CUBE_DIR = cube
BSP_DIR = $(CUBE_DIR)/Drivers/BSP/$(BOARD_UC)
HAL_DIR = $(CUBE_DIR)/Drivers/STM32F4xx_HAL_Driver
2015-02-08 22:53:23 +01:00
CMSIS_DIR = $(CUBE_DIR)/Drivers/CMSIS
DEV_DIR = $(CMSIS_DIR)/Device/ST/STM32F4xx
2015-02-08 22:53:23 +01:00
CUBE_URL = http://www.st.com/st-web-ui/static/active/en/st_prod_software_internet/resource/technical/software/firmware/stm32cubef4.zip
2015-02-08 22:53:23 +01:00
# that's it, no need to change anything below this line!
###############################################################################
# Toolchain
PREFIX = arm-none-eabi
CC = $(PREFIX)-gcc
AR = $(PREFIX)-ar
OBJCOPY = $(PREFIX)-objcopy
OBJDUMP = $(PREFIX)-objdump
SIZE = $(PREFIX)-size
GDB = $(PREFIX)-gdb
OCD = openocd
###############################################################################
# Options
# Defines
2015-05-02 17:10:33 +02:00
DEFS = -D$(MCU_MC) -DUSE_HAL_DRIVER
2015-02-08 22:53:23 +01:00
2015-05-02 17:11:42 +02:00
# Debug specific definitions for semihosting
DEFS += -DUSE_DBPRINTF
2015-02-08 22:53:23 +01:00
# Include search paths (-I)
2015-05-02 17:10:33 +02:00
INCS = -Isrc
INCS += -I$(BSP_DIR)
INCS += -I$(CMSIS_DIR)/Include
INCS += -I$(DEV_DIR)/Include
INCS += -I$(HAL_DIR)/Inc
2015-02-08 22:53:23 +01:00
# Library search paths
2015-05-02 17:10:33 +02:00
LIBS = -L$(CMSIS_DIR)/Lib
2015-02-08 22:53:23 +01:00
# Compiler flags
CFLAGS = -Wall -g -std=c99 -Os
CFLAGS += -mlittle-endian -mcpu=cortex-m4 -march=armv7e-m -mthumb
CFLAGS += -mfpu=fpv4-sp-d16 -mfloat-abi=hard
CFLAGS += -ffunction-sections -fdata-sections
CFLAGS += $(INCS) $(DEFS)
# Linker flags
2015-05-02 17:10:33 +02:00
LDFLAGS = -Wl,--gc-sections -Wl,-Map=$(TARGET).map $(LIBS) -T$(MCU_LC).ld
2015-02-08 22:53:23 +01:00
2015-05-02 17:11:42 +02:00
# Enable Semihosting
LDFLAGS += --specs=rdimon.specs -lc -lrdimon
2015-02-08 22:53:23 +01:00
# Source search paths
VPATH = ./src
2015-05-02 17:11:42 +02:00
VPATH += $(BSP_DIR)
2015-02-08 22:53:23 +01:00
VPATH += $(HAL_DIR)/Src
VPATH += $(DEV_DIR)/Source/
OBJS = $(addprefix obj/,$(SRCS:.c=.o))
DEPS = $(addprefix dep/,$(SRCS:.c=.d))
# Prettify output
V = 0
ifeq ($V, 0)
Q = @
P = > /dev/null
endif
###################################################
2015-02-08 23:22:40 +01:00
.PHONY: all dirs program debug template clean
2015-02-08 22:53:23 +01:00
all: $(TARGET).bin
2015-02-08 22:53:23 +01:00
-include $(DEPS)
2015-02-08 23:22:40 +01:00
dirs: dep obj cube
2015-02-08 22:53:23 +01:00
dep obj src:
@echo "[MKDIR] $@"
$Qmkdir -p $@
obj/%.o : %.c | dirs
@echo "[CC] $(notdir $<)"
$Q$(CC) $(CFLAGS) -c -o $@ $< -MMD -MF dep/$(*F).d
$(TARGET).elf: $(OBJS)
@echo "[LD] $(TARGET).elf"
$Q$(CC) $(CFLAGS) $(LDFLAGS) src/startup_$(MCU_LC).s $^ -o $@
@echo "[OBJDUMP] $(TARGET).lst"
$Q$(OBJDUMP) -St $(TARGET).elf >$(TARGET).lst
@echo "[SIZE] $(TARGET).elf"
$(SIZE) $(TARGET).elf
$(TARGET).bin: $(TARGET).elf
@echo "[OBJCOPY] $(TARGET).bin"
$Q$(OBJCOPY) -O binary $< $@
openocd:
$(OCD) -s $(OCD_DIR) $(OCDFLAGS)
2015-02-08 22:53:23 +01:00
program: all
$(OCD) -s $(OCD_DIR) $(OCDFLAGS) -c "program $(TARGET).elf verify reset"
2015-02-08 22:53:23 +01:00
debug:
2015-05-02 17:11:42 +02:00
@if ! nc -z localhost 3333; then \
echo "\n\t[Error] OpenOCD is not running! Start it with: 'make openocd'\n"; exit 1; \
else \
$(GDB) -ex "target extended localhost:3333" \
-ex "monitor arm semihosting enable" \
-ex "monitor reset halt" \
-ex "load" \
-ex "monitor reset init" \
$(GDBFLAGS) $(TARGET).elf; \
fi
2015-02-08 22:53:23 +01:00
cube:
2015-05-02 17:10:33 +02:00
rm -fr $(CUBE_DIR)
wget -O /tmp/cube.zip $(CUBE_URL)
unzip /tmp/cube.zip
mv STM32Cube* $(CUBE_DIR)
chmod -R u+w $(CUBE_DIR)
rm -f /tmp/cube.zip
2015-02-08 22:53:23 +01:00
2015-02-08 23:22:40 +01:00
template: cube src
cp -ri $(CUBE_DIR)/Projects/$(BOARD)/$(EXAMPLE)/Src/* src
cp -ri $(CUBE_DIR)/Projects/$(BOARD)/$(EXAMPLE)/Inc/* src
cp -i $(DEV_DIR)/Source/Templates/gcc/startup_$(MCU_LC).s src
cp -i $(CUBE_DIR)/Projects/$(BOARD)/$(LDFILE) $(MCU_LC).ld
2015-02-08 22:53:23 +01:00
clean:
@echo "[RM] $(TARGET).bin"; rm -f $(TARGET).bin
2015-02-08 22:53:23 +01:00
@echo "[RM] $(TARGET).elf"; rm -f $(TARGET).elf
@echo "[RM] $(TARGET).map"; rm -f $(TARGET).map
@echo "[RM] $(TARGET).lst"; rm -f $(TARGET).lst
@echo "[RMDIR] dep" ; rm -fr dep
@echo "[RMDIR] obj" ; rm -fr obj