stm32g0cube-projects/myapps/OLD/first-hal/Makefile

146 lines
3 KiB
Makefile
Raw Normal View History

2025-08-23 02:26:08 +10:00
######################################
# target
######################################
TARGET = stm32g0_blinky
2025-08-23 11:49:01 +10:00
PART = STM32G030xx
PYOCD_TARGET = stm32g030f6px
2025-08-23 02:26:08 +10:00
######################################
# building variables
######################################
# debug build?
DEBUG = 1
# optimization for size
OPT = -Os
#######################################
# paths
#######################################
# Build path
BUILD_DIR = build
VND_DIR = ../../vendor
######################################
# source
######################################
# C sources
include hal.mk
C_SOURCES += \
$(VND_DIR)/STM32CubeG0/Drivers/CMSIS/Device/ST/STM32G0xx/Source/Templates/system_stm32g0xx.c \
src/main.c
# ASM sources
ASM_SOURCES = \
$(VND_DIR)/STM32CubeG0/Drivers/CMSIS/Device/ST/STM32G0xx/Source/Templates/gcc/startup_stm32g030xx.s
#######################################
# binaries
#######################################
PREFIX = arm-none-eabi-
CC = $(PREFIX)gcc
CP = $(PREFIX)objcopy
#SZ = $(PREFIX)size
BIN = $(CP) -O binary -S
#######################################
# CFLAGS
#######################################
# cpu
CPU = \
-mcpu=cortex-m0plus \
-mthumb
DEFINES = -D$(PART)
# fpu
FPU =
# float-abi
FLOAT-ABI =
# mcu
MCU = $(CPU) $(FPU) $(FLOAT-ABI)
# C includes
C_INCLUDES += \
-Isrc/inc \
-I$(VND_DIR)/STM32CubeG0/Drivers/CMSIS/Core/Include \
-I$(VND_DIR)/STM32CubeG0/Drivers/CMSIS/Device/ST/STM32G0xx/Include
# compile gcc flags
ADDN_CFLAGS = \
-Wall \
-fno-common \
-fdata-sections \
-ffunction-sections
CFLAGS = $(MCU) $(ADDN_CFLAGS) $(C_INCLUDES) $(OPT) $(DEFINES)
ifeq ($(DEBUG), 1)
CFLAGS += -ggdb3
endif
# Generate dependency information
#CFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"
#######################################
# LDFLAGS
#######################################
# link script
LDSCRIPT = $(VND_DIR)/Ld/STM32G030F6MX_FLASH.ld
LIBDIR =
LDFLAGS = \
$(MCU) \
-T $(LDSCRIPT) \
--specs=nano.specs \
-Wl,--gc-sections \
-Wl,--print-memory-usage \
-Wl,--no-warn-rwx-segments
# default action: build all
all: $(BUILD_DIR)/$(TARGET).elf $(BUILD_DIR)/$(TARGET).bin
#######################################
# build the application
#######################################
# list of objects
OBJECTS = $(addprefix $(BUILD_DIR)/,$(notdir $(C_SOURCES:.c=.o)))
vpath %.c $(sort $(dir $(C_SOURCES)))
$(BUILD_DIR)/%.o: %.c Makefile | $(BUILD_DIR)
$(CC) -c $(CFLAGS) -Wa,-a,-ad,-alms=$(BUILD_DIR)/$(notdir $(<:.c=.lst)) $< -o $@
#$(LUAOBJECTS) $(OBJECTS)
$(BUILD_DIR)/$(TARGET).elf: $(OBJECTS) Makefile
$(CC) $(OBJECTS) $(LDFLAGS) $(ASM_SOURCES) -o $@
$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf | $(BUILD_DIR)
$(BIN) $< $@
$(BUILD_DIR):
mkdir $@
#######################################
# Program
#######################################
flash: $(BUILD_DIR)/$(TARGET).bin
2025-08-23 11:49:01 +10:00
pyocd load --target $(PYOCD_TARGET) $(BUILD_DIR)/$(TARGET).bin
2025-08-23 02:26:08 +10:00
#######################################
# clean up
#######################################
clean:
-rm -fR $(BUILD_DIR)
# *** EOF ***