Full color support, rework the directory structure
This commit is contained in:
177
firmware/Makefile
Normal file
177
firmware/Makefile
Normal file
@@ -0,0 +1,177 @@
|
||||
# Copyright 2019, Max Regan
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person
|
||||
# obtaining a copy of this software and associated documentation files
|
||||
# (the "Software"), to deal in the Software without restriction,
|
||||
# including without limitation the rights to use, copy, modify, merge,
|
||||
# publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
# and to permit persons to whom the Software is furnished to do so,
|
||||
# subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||||
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
#
|
||||
# Tools
|
||||
#
|
||||
|
||||
TOOL_PREFIX ?= arm-none-eabi-
|
||||
CC = $(TOOL_PREFIX)gcc
|
||||
CXX = $(TOOL_PREFIX)g++
|
||||
CPP = $(TOOL_PREFIX)cpp
|
||||
AS = $(TOOL_PREFIX)as
|
||||
LD = $(TOOL_PREFIX)g++
|
||||
OBJCOPY = $(TOOL_PREFIX)objcopy
|
||||
STM32_PROG = STM32_Programmer.sh
|
||||
#
|
||||
# Device Variables
|
||||
#
|
||||
|
||||
DEVICE_TYPE ?= stm32l031k6
|
||||
DEVICE_FAMILY = stm32l031xx
|
||||
DEVICE_LINE = stm32l0xx
|
||||
|
||||
STACK_SIZE ?= 768
|
||||
HEAP_SIZE ?= 0
|
||||
|
||||
#
|
||||
# Filenames and paths
|
||||
#
|
||||
|
||||
# Ignores dotfiles and other garbage some tools leave behind
|
||||
define find_important
|
||||
$(shell find $(1) -type f -and -name $(2) -and -not -iname "*~" -and -not -iname "*#*" -and -not \( -path "*.cquery_cached_index*" \) -and -not \( -path "*build*" \) )
|
||||
endef
|
||||
|
||||
FONTS := small large_digits
|
||||
FONT_GEN_DIR := build/gen/fonts
|
||||
FONT_C_FILES := $(patsubst %,$(FONT_GEN_DIR)/%.c,$(FONTS))
|
||||
FONT_H_FILES := $(patsubst %,$(FONT_GEN_DIR)/%.h,$(FONTS))
|
||||
|
||||
C_SOURCES := $(call find_important, $(SOURCEDIR), '*.c') $(FONT_C_FILES)
|
||||
CXX_SOURCES := $(call find_important, $(SOURCEDIR), '*.cpp')
|
||||
S_SOURCES := $(call find_important, $(SOURCEDIR), '*.s')
|
||||
SPP_SOURCES := Bsp/Mcu/$(DEVICE_TYPE).S
|
||||
SOURCES = $(C_SOURCES) $(S_SOURCES) $(SPP_SOURCES) $(CPP_SOURCES)
|
||||
|
||||
C_OBJS := $(patsubst %.c,%.o,$(C_SOURCES))
|
||||
CXX_OBJS := $(patsubst %.cpp,%.o,$(CXX_SOURCES))
|
||||
S_OBJS := $(patsubst %.s,%.o,$(S_SOURCES))
|
||||
SPP_OBJS := $(patsubst %.S,%.o,$(SPP_SOURCES))
|
||||
OBJS = $(C_OBJS) $(S_OBJS) $(SPP_OBJS) $(CXX_OBJS)
|
||||
|
||||
LINKER_SCRIPT ?= Bsp/Mcu/$(DEVICE_TYPE).ld
|
||||
|
||||
OUTPUT_NAME ?= watch
|
||||
OUTPUT_BIN ?= $(OUTPUT_NAME).bin
|
||||
OUTPUT_ELF ?= $(OUTPUT_NAME).elf
|
||||
OUTPUT_MAP ?= $(OUTPUT_NAME).map
|
||||
|
||||
#
|
||||
# Flags
|
||||
#
|
||||
|
||||
DEVICE_DEFINE = $(subst XX,xx,$(shell echo $(DEVICE_FAMILY) | tr '[:lower:]' '[:upper:]'))
|
||||
|
||||
CPU_FLAGS = -mthumb -mcpu=cortex-m0plus -mfloat-abi=soft
|
||||
|
||||
# C pedantism
|
||||
CFLAGS = -Wall -Wextra -pedantic -Werror -Wcast-align
|
||||
CXX_FLAGS = -Wsuggest-override -Wsuggest-final-methods -Wsuggest-final-types
|
||||
# Debug/optimization
|
||||
CFLAGS += -Os -ggdb
|
||||
CFLAGS += -fdata-sections -ffunction-sections
|
||||
# Architecture
|
||||
CFLAGS += $(CPU_FLAGS)
|
||||
CFLAGS += -ffreestanding
|
||||
CFLAGS += -fstack-usage -Wstack-usage=128
|
||||
# Defines
|
||||
CFLAGS += -D$(DEVICE_DEFINE)
|
||||
# Includes
|
||||
CFLAGS += -I./ThirdParty/stm32/$(DEVICE_LINE)/Include
|
||||
CFLAGS += -I./ThirdParty/CMSIS/Core/Include
|
||||
CFLAGS += -I./build/gen/
|
||||
CFLAGS += -I.
|
||||
|
||||
CXX_FLAGS += -std=c++14 -fno-exceptions -fno-rtti -fno-use-cxa-atexit
|
||||
|
||||
# Startup Definitions
|
||||
ASFLAGS += $(CPU_FLAGS)
|
||||
ASFLAGS += -D__STARTUP_CLEAR_BSS
|
||||
ASFLAGS += -D__HEAP_SIZE=$(HEAP_SIZE)
|
||||
ASFLAGS += -D__STACK_SIZE=$(STACK_SIZE)
|
||||
|
||||
LDFLAGS += $(CPU_FLAGS)
|
||||
LDFLAGS += -Wl,--gc-sections -Wl,--build-id=none -static
|
||||
LDFLAGS += -Wl,--wrap=malloc -Wl,--wrap=free # Fail to link if dynamic allocation is sneaking through
|
||||
LDFLAGS += -Wl,-print-memory-usage
|
||||
LDFLAGS += -nostartfiles
|
||||
|
||||
#
|
||||
# Default Target
|
||||
#
|
||||
.PHONY: build
|
||||
build: $(OUTPUT_BIN)
|
||||
|
||||
#
|
||||
# Build Logic
|
||||
#
|
||||
|
||||
%.o: %.c $(FONT_H_FILES)
|
||||
@echo "CC $@"
|
||||
@$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
%.o: %.S $(FONT_H_FILES)
|
||||
@echo "AS $@"
|
||||
@$(CC) $(ASFLAGS) -c $< -o $@
|
||||
|
||||
%.o: %.cpp $(FONT_H_FILES)
|
||||
@echo "CXX $@"
|
||||
@$(CXX) $(CXX_FLAGS) $(CFLAGS) -c $< -o $@
|
||||
|
||||
SMALL_FONT=ThirdParty/fonts/roboto_mono/RobotoMono-Medium.ttf
|
||||
$(FONT_GEN_DIR)/small.h $(FONT_GEN_DIR)/small.c: Gen/fixedfont-to-c.py Gen/font.py
|
||||
@echo "GEN $@"
|
||||
@mkdir -p $(FONT_GEN_DIR)
|
||||
@Gen/fixedfont-to-c.py $(patsubst .%,%,$(suffix $@)) $(SMALL_FONT) "$@" -s 18 --header-dir "Bsp/" --name font_small
|
||||
@$(call gen_font,$(FONT),29,small)
|
||||
|
||||
LARGE_FONT=ThirdParty/fonts/roboto_mono/RobotoMono-Bold.ttf
|
||||
$(FONT_GEN_DIR)/large_digits.h $(FONT_GEN_DIR)/large_digits.c: Gen/fixedfont-to-c.py Gen/font.py
|
||||
@echo "GEN $@"
|
||||
@mkdir -p $(FONT_GEN_DIR)
|
||||
@Gen/fixedfont-to-c.py $(patsubst .%,%,$(suffix $@)) $(LARGE_FONT) "$@" -s 70 --header-dir "Bsp/" --name font_large_digits -c "01234567890:"
|
||||
|
||||
$(OUTPUT_BIN): $(OUTPUT_ELF)
|
||||
@echo "OBJCOPY $@"
|
||||
@$(OBJCOPY) -O binary $(OUTPUT_ELF) $(OUTPUT_BIN)
|
||||
|
||||
$(OUTPUT_MAP) $(OUTPUT_ELF): $(LINKER_SCRIPT) $(OBJS)
|
||||
@echo "LD $@"
|
||||
@$(LD) -T $(LINKER_SCRIPT) $(LDFLAGS) -o $(OUTPUT_ELF) $(OBJS) -Wl,-Map=$(OUTPUT_MAP)
|
||||
|
||||
#
|
||||
# Utilities
|
||||
#
|
||||
|
||||
STM32FLASH_DEVICE = /dev/ttyUSB0
|
||||
|
||||
.PHONY: flash
|
||||
flash: $(OUTPUT_BIN)
|
||||
@echo "FLASH $(OUTPUT_BIN)"
|
||||
$(STM32_PROG) --connect port=SWD reset=Hwrst -w $(OUTPUT_BIN) 0x8000000 -v --go
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
@echo "RM $(OBJS)"
|
||||
@rm -f $(OBJS) $(OUTPUT_BIN) $(OUTPUT_ELF) $(FONT_C_FILES) $(OUTPUT_MAP) ./*.su
|
||||
@rm -rf build/
|
||||
Reference in New Issue
Block a user