Skip to content

Commit

Permalink
Sync up the VS Code starter projects with the upgraded Makefile system
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake-Carter committed Aug 17, 2022
1 parent 4395d7b commit ee446ee
Show file tree
Hide file tree
Showing 6 changed files with 470 additions and 102 deletions.
273 changes: 223 additions & 50 deletions MaximSDK/Inject/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,84 +30,257 @@
# * ownership rights.
# *******************************************************************************

###############################################################################
# Main configuration
# Below are the most commonly needed configuration options for this Makefile.
# You shouldn't need to touch anything else unless advanced configuration is required.
# ** Readme! **
# Don't edit this file! Edit "project.mk" instead...

# Source files to compile for this project (add path to VPATH below)
SRCS += main.c
# This is the core Makefile for a MaximSDK project. The configuration below
# is made to be suitable for most use-cases, and you normally shouldn't ever
# need to edit this file directly. Instead, if you do need to modify the build system
# for your project use the "project.mk" file to override and/or add to the
# various "API"-like configuration variables that are available.

# Where to find source files for this project
VPATH += ./src
# You can also set most configuration variables on the command-line or in your
# system's environment variables. If you're using a supported IDE, it will
# offer its own options for overriding the available configuration variables.

# Where to find header files for this project
IPATH += ./src
# For more details on what configuration variables are available, see the sections
# of this Makefile below. Each section contains a description and a list of
# options.

# Set compiler flags
PROJ_CFLAGS+=-Wall # Enable warnings
PROJ_CFLAGS+=-DMXC_ASSERT_ENABLE # Enable assertion checking for development
# For a more comprehensive overview of Make itself, see https://www.gnu.org/software/make/manual/

# Set compiler optimization level
MXC_OPTIMIZE_CFLAGS=-Og

###############################################################################
# *******************************************************************************
# Set the target microcontroller and board to compile for.

# Every TARGET microcontroller has some Board Support Packages (BSPs) that are available
# for it under the MaximSDK/Libraries/Boards/TARGET folder. The BSP that gets
# selected is MaximSDK/Libraries/Boards/TARGET/BOARD.

# Configuration Variables:
# - TARGET : Override the default target microcontroller. Ex: TARGET=MAX78000
# - BOARD : Override the default BSP (case sensitive). Ex: BOARD=EvKit_V1, BOARD=FTHR_RevA

# Set the MAKE variable. This eliminates issues with some setups
MAKE=make

ifeq "$(TARGET)" ""
$(error target must be specified! Set the TARGET variable.)
# Default target microcontroller
TARGET := MAX78000
TARGET_UC := MAX78000
TARGET_LC := max78000
else
# "TARGET" has been overridden in the environment or on the command-line.
# We need to calculate an upper and lowercase version of the part number,
# because paths on Linux and MacOS are case-sensitive.
TARGET_UC := $(subst m,M,$(subst a,A,$(subst x,X,$(TARGET))))
TARGET_LC := $(subst M,m,$(subst A,a,$(subst X,x,$(TARGET))))
endif

# Default board used. This is overridden in settings.json
ifeq "$(BOARD)" ""
$(error board must be specified! Set the BOARD variable.)
endif
# Default board.
BOARD ?= EvKit_V1

# Set output filename
ifeq "$(PROJECT)" ""
PROJECT=$(TARGET)
# *******************************************************************************
# Locate the MaximSDK

# This Makefile needs to know where to find the MaximSDK, and the MAXIM_PATH variable
# should point to the root directory of the MaximSDK installation. Setting this manually
# is usually only required if you're working on the command-line.

# If MAXIM_PATH is not specified, we assume the project still lives inside of the MaximSDK
# and move up from this project's original location.

# Configuration Variables:
# - MAXIM_PATH : Tell this Makefile where to find the MaximSDK. Ex: MAXIM_PATH=C:/MaximSDK


ifneq "$(MAXIM_PATH)" ""
# Sanitize MAXIM_PATH for backslashes
MAXIM_PATH := $(subst \,/,$(MAXIM_PATH))
# Locate some other useful paths...
LIBS_DIR := $(abspath $(MAXIM_PATH)/Libraries)
CMSIS_ROOT := $(LIBS_DIR)/CMSIS
endif

# Create Target name variables
TARGET_UC:=$(shell echo $(TARGET) | tr a-z A-Z)
TARGET_LC:=$(shell echo $(TARGET) | tr A-Z a-z)
# *******************************************************************************
# Include project Makefile. We do this after formulating TARGET, BOARD, and MAXIM_PATH
# in case project.mk needs to reference those values. However, we also include
# this as early as possible in the Makefile so that it can append to or override
# the variables below.


# Select 'GCC' or 'IAR' compiler
COMPILER=GCC
include ./project.mk
$(info Loaded project.mk)

# *******************************************************************************
# Final path sanitization and re-calculation. No options here.

# This is the path to the CMSIS root directory
ifeq "$(MAXIM_PATH)" ""
LIBS_DIR=../../../Libraries
# MAXIM_PATH is still not defined...
DEPTH := ../../../
MAXIM_PATH := $(abspath $(DEPTH))
$(warning Warning: MAXIM_PATH is not set! It's recommended to set MAXIM_PATH in your environment or in project.mk)
$(warning Warning: Attempting to use $(MAXIM_PATH) calculated from relative path)
else
LIBS_DIR=/$(subst \,/,$(subst :,,$(MAXIM_PATH))/Libraries)
# Sanitize MAXIM_PATH for backslashes
MAXIM_PATH := $(subst \,/,$(MAXIM_PATH))
endif
#LIBS_DIR = ./Libraries

CMSIS_ROOT=$(LIBS_DIR)/CMSIS
# Final recalculation of LIBS_DIR/CMSIS_ROOT
LIBS_DIR := $(abspath $(MAXIM_PATH)/Libraries)
CMSIS_ROOT := $(LIBS_DIR)/CMSIS

#Use this for other library make files so they are all based off the same as root as the project
# One final UC/LC check in case user set TARGET in project.mk
TARGET_UC := $(subst m,M,$(subst a,A,$(subst x,X,$(TARGET))))
TARGET_LC := $(subst M,m,$(subst A,a,$(subst X,x,$(TARGET))))

export TARGET
export TARGET_UC
export TARGET_LC
export CMSIS_ROOT
# TODO: Remove dependency on exports for these variables.

# *******************************************************************************
# Set up search paths, and auto-detect all source code on those paths.

# The following paths are searched by default, where "./" is the project directory.
# ./
# ├─ *.h
# ├─ *.c
# ├─include (optional)
# └─ *.h
# ├─src (optional)
# └─ *.c

# Configuration Variables:
# - VPATH : Tell this Makefile to search additional locations for source (.c) files.
# You should use the "+=" operator with this option.
# Ex: VPATH += your/new/path
# - IPATH : Tell this Makefile to search additional locations for header (.h) files.
# You should use the "+=" operator with this option.
# Ex: VPATH += your/new/path
# - SRCS : Tell this Makefile to explicitly add a source (.c) file to the build.
# This is really only useful if you want to add a source file that isn't
# on any VPATH, in which case you can add the full path to the file here.
# You should use the "+=" operator with this option.
# Ex: SRCS += your/specific/source/file.c
# - AUTOSEARCH : Set whether this Makefile should automatically detect .c files on
# VPATH and add them to the build. This is enabled by default. Set
# to 0 to disable. If autosearch is disabled, source files must be
# manually added to SRCS.
# Ex: AUTOSEARCH = 0


# Where to find source files for this project.
VPATH += .
VPATH := $(VPATH)

# Where to find header files for this project
IPATH += .
IPATH := $(IPATH)

AUTOSEARCH ?= 1
ifeq ($(AUTOSEARCH), 1)
# Auto-detect all C source files on VPATH
SRCS += $(wildcard $(addsuffix /*.c, $(VPATH)))
endif

# Collapse SRCS before passing them on to the next stage
SRCS := $(SRCS)

# *******************************************************************************
# Set the output filename

# Configuration Variables:
# - PROJECT : Override the default output filename. Ex: PROJECT=MyProject


# The default value creates a file named after the target micro. Ex: MAX78000.elf
PROJECT ?= $(TARGET_UC)

# *******************************************************************************
# Compiler options

# Configuration Variables:
# - MXC_OPTIMIZE_CFLAGS : Override the default compiler optimization level.
# Ex: MXC_OPTIMIZE_CFLAGS = -O2
# - PROJ_CFLAGS : Add additional compiler flags to the build.
# You should use the "+=" operator with this option.
# Ex: PROJ_CFLAGS += -Wextra
# - MFLOAT_ABI : Set the floating point acceleration level.
# The only options are "hard", "soft", or "softfp".
# Ex: MFLOAT_ABI = hard
# - LINKERFILE : Override the default linkerfile.
# Ex: LINKERFILE = customlinkerfile.ld


# Select 'GCC' or 'IAR' compiler
ifeq "$(COMPILER)" ""
COMPILER := GCC
endif

# Set compiler optimization level
ifeq "$(MAKECMDGOALS)" "release"
# Optimization level for "release" builds
MXC_OPTIMIZE_CFLAGS := -O2
else
# Optimization level for default builds
MXC_OPTIMIZE_CFLAGS := -Og
endif

# Set compiler flags
PROJ_CFLAGS += -Wall # Enable warnings
PROJ_CFLAGS += -DMXC_ASSERT_ENABLE

# Set hardware floating point acceleration.
# Options are:
# - hard
# - soft
# - softfp (default if MFLOAT_ABI is not set)
MFLOAT_ABI ?= softfp
# MFLOAT_ABI must be exported to other Makefiles, who check this too
export MFLOAT_ABI

# Set the default linkerfile. Since the core Makefiles later add the location of Maxim's
# linkerfiles to VPATH, and the local project directory has also been added to VPATH, Make
# will search both locations for the specified linkerfile if it can't find it by its path alone.
# The result is that overriding LINKERFILE with the filename of one of Maxim's alternate linkerfiles
# (ex: LINKERFILE=max78000_arm.ld) will work just the same as LINKERFILE=mycustom.ld
# even if mycustom.ld lives locally to this project.

ifeq "$(RISCV_CORE)" ""
# Default linkerfile is only specified for standard Arm-core projects.
# Otherwise, gcc_riscv.mk sets the appropriate riscv linkerfile.
LINKERFILE ?= $(CMSIS_ROOT)/Device/Maxim/$(TARGET_UC)/Source/GCC/$(TARGET_LC).ld
endif

# This path contains system-level intialization files for the target micro. Add to the build.
VPATH += $(CMSIS_ROOT)/Device/Maxim/$(TARGET_UC)/Source

# Point this variable to a linker file to override the default file
LINKER=$(TARGET_LC).ld
LINKERFILE=$(CMSIS_ROOT)/Device/Maxim/$(TARGET_UC)/Source/GCC/$(LINKER)
# *******************************************************************************
# Libraries

# This section offers "toggle switches" to include or exclude the libraries that
# are available in the MaximSDK. Set a configuration variable to 1 to include the
# library in the build, or 0 to exclude.

################################################################################
# Include external library makefiles here
# Each library may also have its own library specific configuration variables. See
# Libraries/libs.mk for more details.

# Include the BSP
BOARD_DIR=$(LIBS_DIR)/Boards/$(TARGET_UC)/$(BOARD)
include $(BOARD_DIR)/board.mk
# Configuration variables:
# - LIB_BOARD : Include the Board-Support Package (BSP) library. (Enabled by default)
# - LIB_PERIPHDRIVERS : Include the peripheral driver library. (Enabled by default)
# - LIB_CMSIS_DSP : Include the CMSIS-DSP library.
# - LIB_CORDIO : Include the Cordio BLE library
# - LIB_FCL : Include the Free Cryptographic Library (FCL)
# - LIB_FREERTOS : Include the FreeRTOS and FreeRTOS-Plus-CLI libraries
# - LIB_LC3 : Include the Low Complexity Communication Codec (LC3) library
# - LIB_LTTLEFS : Include the "little file system" (littleFS) library
# - LIB_LWIP : Include the lwIP library
# - LIB_MAXUSB : Include the MAXUSB library
# - LIB_SDHC : Include the SDHC library

# Include the peripheral driver
PERIPH_DRIVER_DIR=$(LIBS_DIR)/PeriphDrivers
include $(PERIPH_DRIVER_DIR)/periphdriver.mk
export PERIPH_DRIVER_DIR
include $(LIBS_DIR)/libs.mk

################################################################################
# *******************************************************************************
# Include the rules for building for this target. All other makefiles should be
# included before this one.
include $(CMSIS_ROOT)/Device/Maxim/$(TARGET_UC)/Source/$(COMPILER)/$(TARGET_LC).mk
Expand Down
11 changes: 11 additions & 0 deletions MaximSDK/Inject/project.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# This file can be used for project configuration.
# It's a sibling to the core "Makefile", which offers
# various configuration variables that you can set here
# if the default setup isn't suitable.

# See the comments in the "Makefile" for a detailed
# description of the default behavior and the full list of
# available options.



2 changes: 1 addition & 1 deletion MaximSDK/New_Project/.vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"intelliSenseMode": "gcc-arm",
"compilerPath": "${config:ARM_GCC_path}/bin/arm-none-eabi-gcc.exe",
"browse": {
"path": [
"path": [
"${default}"
]
}
Expand Down
Loading

0 comments on commit ee446ee

Please sign in to comment.