Skip to content

Commit

Permalink
F421: fixed case of ADC.h (matters on Linux)
Browse files Browse the repository at this point in the history
makefile: added -g to CFLAGS

adding -g does not change the size of the build, but gives us debug
symbols to make debugging easier

makefile: fixed use of MCU flags

use the flags for the specific MCU, not just F051

f421: fixed makefile

case sensitive and stray white space

f421: removed duplicate target

makefile: added targets make command

lists targets for convenience

e230: fixed build with makefile

stop overflowing flash

makefile: reduce build size

main gain is using single precision constants

inc: show an error if missing target defines

f415: fixed makefile

case sensitive for linux builds

f421: fixed name of DAKEFPV_F421

show target name instead of "all done"

more useful output

f415: fixed declaration of gpio_mode_QUICK

targets: fixed AT32DEV_F415 build

CI: added a CI build workflow

added vscode build rules

and gdb debug support

moved version to Makefile

avoids shell commands that are a problem on windows

git: ignore generated files

vscode: added STLink and JLink debug setups

CI: added target to build on windows

moved tools to firmware.ardupilot.org

more bandwidth available
  • Loading branch information
tridge authored and ianrmurphy committed Jul 25, 2024
1 parent 2e04461 commit c2aa4c9
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 58 deletions.
135 changes: 77 additions & 58 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@

QUIET = @

# update version numbers here
VERSION_MAJOR := 2
VERSION_MINOR := 12

# tools
CC = $(ARM_SDK_PREFIX)gcc
OBJCOPY = $(ARM_SDK_PREFIX)objcopy
CP = $(ARM_SDK_PREFIX)objcopy
ECHO = echo

# common variables
Expand All @@ -16,104 +20,119 @@ MAIN_INC_DIR := Inc

SRC_DIRS_COMMON := $(MAIN_SRC_DIR)

# Working directories
ROOT := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))
# Include processor specific makefiles
include f051makefile.mk
include g071makefile.mk
include f031makefile.mk
include f421makefile.mk
include e230makefile.mk
include f415makefile.mk

# include the rules for OS independence
include $(ROOT)/make/tools.mk

# supported MCU types
MCU_TYPES := E230 F031 F051 F415 F421 G071
MCU_TYPE := NONE

# Function to include makefile for each MCU type
define INCLUDE_MCU_MAKEFILES
$(foreach MCU_TYPE,$(MCU_TYPES),$(eval include $(call lc,$(MCU_TYPE))makefile.mk))
endef
$(call INCLUDE_MCU_MAKEFILES)
# Default MCU type to F051
MCU_TYPE ?= F051

# additional libs
LIBS := -lnosys

# extract version from Inc/version.h
VERSION_MAJOR := $(shell $(FGREP) "define VERSION_MAJOR" $(MAIN_INC_DIR)/version.h | $(CUT) -d" " -f3 )
VERSION_MINOR := $(shell $(FGREP) "define VERSION_MINOR" $(MAIN_INC_DIR)/version.h | $(CUT) -d" " -f3 )

FIRMWARE_VERSION := $(VERSION_MAJOR).$(VERSION_MINOR)

# Compiler options

CFLAGS_BASE := -DUSE_MAKE -fsingle-precision-constant -fomit-frame-pointer -ffast-math
CFLAGS_BASE += -I$(MAIN_INC_DIR) -g -O3 -Wall -ffunction-sections

CFLAGS_COMMON := $(CFLAGS_BASE) -D$(TARGET)
CFLAGS_COMMON := -DUSE_MAKE -fsingle-precision-constant -fomit-frame-pointer -ffast-math
CFLAGS_COMMON += -I$(MAIN_INC_DIR) -g -O3 -Wall -ffunction-sections
CFLAGS_COMMON += -D$(TARGET)
CFLAGS_COMMON += -DVERSION_MAJOR=$(VERSION_MAJOR) -DVERSION_MINOR=$(VERSION_MINOR)

# Linker options
LDFLAGS_COMMON := -specs=nano.specs $(LIBS) -Wl,--gc-sections -Wl,--print-memory-usage

# Working directories
ROOT := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))

# Search source files
SRC_COMMON := $(foreach dir,$(SRC_DIRS_COMMON),$(wildcard $(dir)/*.[cs]))

FIRMWARE_VERSION := $(VERSION_MAJOR).$(VERSION_MINOR)

TARGET_FNAME = $(IDENTIFIER)_$(TARGET)_$(FIRMWARE_VERSION)
TARGET_BASENAME = $(BIN_DIR)/$(TARGET_FNAME)

# Build tools, so we all share the same versions
# import macros common to all supported build systems
# include $(ROOT)/make/system-id.mk

# configure some directories that are relative to wherever ROOT_DIR is located
OBJ := obj
BIN_DIR := $(ROOT)/$(OBJ)

.PHONY : clean all binary $(foreach MCU,$(MCU_TYPES),$(call lc,$(MCU)))
ALL_TARGETS := $(foreach MCU,$(MCU_TYPES),$(TARGETS_$(MCU)))
all : $(ALL_TARGETS)
TOOLS_DIR ?= $(ROOT)/tools
DL_DIR := $(ROOT)/downloads

# create targets for compiling one mcu type, eg "make f421"
define CREATE_TARGET
$(call lc,$(1)) : $$(TARGETS_$(1))
endef
$(foreach MCU,$(MCU_TYPES),$(eval $(call CREATE_TARGET,$(MCU))))
.PHONY : clean all binary f051 g071 f031 e230 f421 f415
all : $(TARGETS_F051) $(TARGETS_G071) $(TARGETS_F031) $(TARGETS_E230) $(TARGETS_F421) $(TARGETS_F415)
f051 : $(TARGETS_F051)
g071 : $(TARGETS_G071)
f031 : $(TARGETS_F031)
e230 : $(TARGETS_E230)
f421 : $(TARGETS_F421)
f415 : $(TARGETS_F415)

clean :
@echo Removing $(OBJ) directory
@$(RM) -rf $(OBJ)
$(OBJ):
@$(MKDIR) $(OBJ) > $(NUL)

clean :
@echo "Removing $(OBJ) directory"
@$(RMDIR) $(OBJ)

binary : $(TARGET_BASENAME).bin
# we copy debug.elf to give us a constant debug target for vscode
# this means the debug button will always debug the last target built
@$(CP) -f $(OBJ)$(DSEP)$(TARGET_FNAME).elf $(OBJ)$(DSEP)debug.elf > $(NUL)
# also copy the openocd.cfg from the MCU directory to obj/openocd.cfg for auto config of Cortex-Debug
# in vscode
@$(CP) -f Mcu$(DSEP)$(call lc,$(MCU_TYPE))$(DSEP)openocd.cfg $(OBJ)$(DSEP)openocd.cfg > $(NUL)
@$(COPY) $(OBJ)$(DSEP)$(TARGET_FNAME).elf $(OBJ)$(DSEP)debug.elf > $(NUL)
@$(ECHO) done $(TARGET)

# create targets compiling each MCU types targets
define CREATE_MCU_TARGETS
$$(TARGETS_$(1)) :
@$$(MAKE) -s MCU_TYPE=$(1) TARGET=$$@ binary
endef
$(foreach MCU,$(MCU_TYPES),$(eval $(call CREATE_MCU_TARGETS,$(MCU))))
$(TARGETS_F051) :
@$(MAKE) -s MCU_TYPE=F051 TARGET=$@ binary

$(TARGETS_G071) :
@$(MAKE) -s MCU_TYPE=G071 TARGET=$@ binary

$(TARGETS_F031) :
@$(MAKE) -s MCU_TYPE=F031 TARGET=$@ binary

$(TARGETS_E230) :
@$(MAKE) -s MCU_TYPE=E230 TARGET=$@ binary

$(TARGETS_F421) :
@$(MAKE) -s MCU_TYPE=F421 TARGET=$@ binary

$(TARGETS_F415) :
@$(MAKE) -s MCU_TYPE=F415 TARGET=$@ binary

# Compile target
$(TARGET_BASENAME).elf: CFLAGS := $(MCU_$(MCU_TYPE)) $(CFLAGS_$(MCU_TYPE)) $(CFLAGS_COMMON)
$(TARGET_BASENAME).elf: LDFLAGS := $(LDFLAGS_COMMON) $(LDFLAGS_$(MCU_TYPE)) -T$(LDSCRIPT_$(MCU_TYPE))
$(TARGET_BASENAME).elf: $(SRC_COMMON) $(SRC_$(MCU_TYPE))
$(TARGET_BASENAME).elf: $(SRC_COMMON) $(SRC_$(MCU_TYPE)) $(OBJ)
@$(ECHO) Compiling $(notdir $@)
$(QUIRT)$(MKDIR) -p $(OBJ)
$(QUIET)$(CC) $(CFLAGS) $(LDFLAGS) -MMD -MP -MF $(@:.elf=.d) -o $(@) $(SRC_COMMON) $(SRC_$(MCU_TYPE))

# Generate bin and hex files
$(TARGET_BASENAME).bin: $(TARGET_BASENAME).elf
@$(ECHO) Generating $(notdir $@)
$(QUIET)$(OBJCOPY) -O binary $(<) $@
$(QUIET)$(OBJCOPY) $(<) -O ihex $(@:.bin=.hex)
$(QUIET)$(CP) -O binary $(<) $@
$(QUIET)$(CP) $(<) -O ihex $(@:.bin=.hex)

# mkdirs
$(DL_DIR):
$(QUIET)$(MKDIR) $@

# include the targets for installing tools
include $(ROOT)/make/tools_install.mk
$(TOOLS_DIR):
$(QUIET)$(MKDIR) $@

define SHOW_MCU_TARGETS
$(1) Targets $(TARGETS_$(1))\n
endef
# include the tools makefile
include $(ROOT)/make/tools.mk

targets:
$(QUIET)echo List of targets. To build a target use 'make TARGETNAME'
$(QUIET)echo $(ALL_TARGETS)
$(QUIET)echo "Targets for each MCU. To build a target use 'make TARGETNAME'"
$(QUIET)echo "F051 Targets: " $(TARGETS_F051)
$(QUIET)echo "G071 Targets: " $(TARGETS_G071)
$(QUIET)echo "F031 Targets: " $(TARGETS_F031)
$(QUIET)echo "E230 Targets: " $(TARGETS_E230)
$(QUIET)echo "F421 Targets: " $(TARGETS_F421)
$(QUIET)echo "F415 Targets: " $(TARGETS_F415)
1 change: 1 addition & 0 deletions e230makefile.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

TARGETS_E230 := $(call get_targets,E230)


HAL_FOLDER_E230 := $(HAL_FOLDER)/e230

MCU_E230 := -mfloat-abi=soft -mthumb -march=armv8-m.main
Expand Down

0 comments on commit c2aa4c9

Please sign in to comment.