|
| 1 | +#****************************************************************************** |
| 2 | +# |
| 3 | +# Makefile - Rules for building the libraries, examples and docs. |
| 4 | +# |
| 5 | +# Copyright (c) 2019, Ambiq Micro |
| 6 | +# All rights reserved. |
| 7 | +# |
| 8 | +# Redistribution and use in source and binary forms, with or without |
| 9 | +# modification, are permitted provided that the following conditions are met: |
| 10 | +# |
| 11 | +# 1. Redistributions of source code must retain the above copyright notice, |
| 12 | +# this list of conditions and the following disclaimer. |
| 13 | +# |
| 14 | +# 2. Redistributions in binary form must reproduce the above copyright |
| 15 | +# notice, this list of conditions and the following disclaimer in the |
| 16 | +# documentation and/or other materials provided with the distribution. |
| 17 | +# |
| 18 | +# 3. Neither the name of the copyright holder nor the names of its |
| 19 | +# contributors may be used to endorse or promote products derived from this |
| 20 | +# software without specific prior written permission. |
| 21 | +# |
| 22 | +# Third party software included in this distribution is subject to the |
| 23 | +# additional license terms as defined in the /docs/licenses directory. |
| 24 | +# |
| 25 | +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 26 | +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 27 | +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 28 | +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 29 | +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 30 | +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 31 | +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 32 | +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 33 | +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 34 | +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 35 | +# POSSIBILITY OF SUCH DAMAGE. |
| 36 | +# |
| 37 | +# This is part of revision 2.1.0 of the AmbiqSuite Development Package. |
| 38 | +# |
| 39 | +#****************************************************************************** |
| 40 | + |
| 41 | +#****************************************************************************** |
| 42 | +# |
| 43 | +# This is an example makefile for SparkFun Apollo3 boards as used in the |
| 44 | +# AmbiqSuite SDK. |
| 45 | +# |
| 46 | +# Recommended usage |
| 47 | +# make |
| 48 | +# make bootload_svl (uses the SparkFun Variable Loader to upload code) |
| 49 | +# make bootload_asb (uses the Ambiq Secure Bootlaoder to upload code) |
| 50 | +# make clean |
| 51 | +# |
| 52 | +# Filepaths |
| 53 | +# You can relocate this makefile easily by providing the path to the root of |
| 54 | +# the AmbiqSuite SDK. If that path is not specified then this file will |
| 55 | +# assume that it is located in |
| 56 | +# <AmbiqSDKRoot>/boards/<your_board>/examples/<your_example>/gcc |
| 57 | +# and use relative paths |
| 58 | +# |
| 59 | +# User Configuration |
| 60 | +# You must also specify which COM_PORT to use if you want to use the |
| 61 | +# 'bootlaoder' targets. |
| 62 | +# Windows example: COM_PORT=COM4 |
| 63 | +# *nix example: COM_PORT=/dev/usbserialxxxx |
| 64 | +# |
| 65 | +# Python vs. Executable |
| 66 | +# For simplicity the upload tools are called as Python scripts by default. |
| 67 | +# Make sure PYTHON is set to the appropriate command to run Python3 from the |
| 68 | +# command line. |
| 69 | +# |
| 70 | +#****************************************************************************** |
| 71 | + |
| 72 | + |
| 73 | +#****************************************************************************** |
| 74 | +# |
| 75 | +# User Options |
| 76 | +# |
| 77 | +#****************************************************************************** |
| 78 | + |
| 79 | +# You can override these values on the command line e.g. make bootload COM_PORT=/dev/cu*** |
| 80 | +# COM_PORT is the serial port to use for uploading. For example COM#### on Windows or /dev/cu.usbserial-#### on *nix |
| 81 | +COM_PORT ?= |
| 82 | +# ASB_UPLOAD_BAUD is the baud rate setting of the Ambiq Secue Bootloader (ASB) as it is configured on the Apollo3. Defautls to 115200 if unset |
| 83 | +ASB_UPLOAD_BAUD ?= |
| 84 | +# SVL_UPLOAD_BAUD is the baud rate setting of the SparkFun Variable Loader (SVL). Defaults to 921600 if unset |
| 85 | +SVL_UPLOAD_BAUD ?= |
| 86 | +# PYTHON3 should evaluate to a call to the Python3 executable on your machine |
| 87 | +PYTHON3 ?= |
| 88 | + |
| 89 | +# *Optionally* specify absolute paths to the SDK and the BSP |
| 90 | +# You can do this on the command line - e.g. make bootload SDKPATH=~/$AMBIQ_SDK_ROOT_PATH |
| 91 | +# Make sure to use / instead of \ when on Windows |
| 92 | +SDKPATH ?=# Set as the path to the SDK root if not located at ../../../../.. |
| 93 | +COMMONPATH ?=# Set as the path to the BSP common folder if not located at ../../../../common |
| 94 | +BOARDPATH ?=# Set as the path to the board if not located at ../../.. |
| 95 | +PROJECTPATH ?=# Set as the path to the project if not located at .. |
| 96 | + |
| 97 | +### Project Settings |
| 98 | +TARGET := linker_tests |
| 99 | +COMPILERNAME := gcc |
| 100 | +PROJECT := $(TARGET)_gcc |
| 101 | + |
| 102 | + |
| 103 | +#****************************************************************************** |
| 104 | +# |
| 105 | +# Warning Messages |
| 106 | +# |
| 107 | +#****************************************************************************** |
| 108 | +ifeq ($(COM_PORT),) |
| 109 | + COM_PORT=COM4 |
| 110 | + $(warning warning: you have not defined COM_PORT. Assuming it is COM4) |
| 111 | +endif |
| 112 | +ifeq ($(PYTHON3),) |
| 113 | + PYTHON3=python3 |
| 114 | + $(warning warning: you have not defined PYTHON3. assuming it is accessible by 'python3') |
| 115 | +endif |
| 116 | +ifeq ($(ASB_UPLOAD_BAUD),) |
| 117 | + ASB_UPLOAD_BAUD=115200 |
| 118 | + $(warning defaulting to 115200 baud for ASB) |
| 119 | +endif |
| 120 | +ifeq ($(SVL_UPLOAD_BAUD),) |
| 121 | + SVL_UPLOAD_BAUD=921600 |
| 122 | + $(warning defaulting to 921600 baud for SVL) |
| 123 | +endif |
| 124 | + |
| 125 | +ifeq ($(SDKPATH),) |
| 126 | + SDKPATH =../../../../.. |
| 127 | + $(warning warning: you have not defined SDKPATH so will continue assuming that the SDK root is at $(SDKPATH)) |
| 128 | +else |
| 129 | +# When the SDKPATH is given export it |
| 130 | +export SDKPATH |
| 131 | +endif |
| 132 | + |
| 133 | +ifeq ($(COMMONPATH),) |
| 134 | + COMMONPATH =../../../../common |
| 135 | + $(warning warning: you have not defined COMMONPATH so will continue assuming that the COMMON root is at $(COMMONPATH)) |
| 136 | +else |
| 137 | +# When the COMMONPATH is given export it |
| 138 | +export COMMONPATH |
| 139 | +endif |
| 140 | + |
| 141 | +ifeq ($(BOARDPATH),) |
| 142 | + BOARDPATH =../../.. |
| 143 | + $(warning warning: you have not defined BOARDPATH so will continue assuming that the BOARD root is at $(BOARDPATH)) |
| 144 | +else |
| 145 | +# When the BOARDPATH is given export it |
| 146 | +export BOARDPATH |
| 147 | +endif |
| 148 | + |
| 149 | +ifeq ($(PROJECTPATH),) |
| 150 | + PROJECTPATH =.. |
| 151 | + $(warning warning: you have not defined PROJECTPATH so will continue assuming that the PROJECT root is at $(PROJECTPATH)) |
| 152 | +else |
| 153 | +# When the PROJECTPATH is given export it |
| 154 | +export PROJECTPATH |
| 155 | +endif |
| 156 | + |
| 157 | +# Build Dir |
| 158 | +CONFIG := $(PROJECTPATH)/gcc/bin |
| 159 | + |
| 160 | +#****************************************************************************** |
| 161 | +# |
| 162 | +# User Defines / Includes / Sources / Libraries |
| 163 | +# |
| 164 | +#****************************************************************************** |
| 165 | + |
| 166 | +# Global Defines |
| 167 | +DEFINES= -DPART_$(PART) |
| 168 | +DEFINES+= -DAM_CUSTOM_BDADDR |
| 169 | +DEFINES+= -DAM_PACKAGE_BGA |
| 170 | +DEFINES+= -DWSF_TRACE_ENABLED |
| 171 | +DEFINES+= -DAM_DEBUG_PRINTF |
| 172 | +DEFINES+= -DAM_PART_APOLLO3 |
| 173 | +DEFINES+= |
| 174 | + |
| 175 | +# Includes (Add paths to where example header files are located) |
| 176 | +INCLUDES= |
| 177 | +INCLUDES+= -I$(PROJECTPATH)/src |
| 178 | +INCLUDES+= -I$(BOARDPATH)/bsp |
| 179 | +INCLUDES+= -I$(SDKPATH) |
| 180 | +INCLUDES+= -I$(SDKPATH)/utils |
| 181 | +INCLUDES+= -I$(SDKPATH)/devices |
| 182 | +INCLUDES+= -I$(SDKPATH)/mcu/apollo3 |
| 183 | +INCLUDES+= -I$(SDKPATH)/CMSIS/AmbiqMicro/Include |
| 184 | +INCLUDES+= -I$(SDKPATH)/CMSIS/ARM/Include |
| 185 | +INCLUDES+= -I$(COMMONPATH)/examples/linker_tests |
| 186 | +INCLUDES+= -I$(COMMONPATH)/examples/linker_tests/test_framework |
| 187 | +INCLUDES+= -I$(COMMONPATH)/examples/linker_tests/tests |
| 188 | +INCLUDES+= -I$(COMMONPATH)/examples/linker_tests/tests/heap |
| 189 | +INCLUDES+= -I$(COMMONPATH)/examples/linker_tests/tests/stack |
| 190 | +INCLUDES+= |
| 191 | + |
| 192 | +# Compilation Units (Add all the .c files you need to compile) |
| 193 | +SRC= |
| 194 | +SRC+= main.cpp |
| 195 | +SRC+= am_util_stdio.c |
| 196 | +SRC+= startup_gcc.c |
| 197 | +SRC+= system.c |
| 198 | +SRC+= test_framework.cpp |
| 199 | +SRC+= tests.cpp |
| 200 | +SRC+= test_heap.cpp |
| 201 | +SRC+= test_stack.cpp |
| 202 | +SRC+= |
| 203 | + |
| 204 | +# VPATH (Add paths to where your source files are located) |
| 205 | +VPATH= |
| 206 | +VPATH+= $(PROJECTPATH)/src |
| 207 | +VPATH+= $(SDKPATH)/utils |
| 208 | +VPATH+= $(COMMONPATH)/tools_sfe/templates |
| 209 | +VPATH+= $(COMMONPATH)/examples/linker_tests |
| 210 | +VPATH+= $(COMMONPATH)/examples/linker_tests/test_framework |
| 211 | +VPATH+= $(COMMONPATH)/examples/linker_tests/tests |
| 212 | +VPATH+= $(COMMONPATH)/examples/linker_tests/tests/heap |
| 213 | +VPATH+= $(COMMONPATH)/examples/linker_tests/tests/stack |
| 214 | +VPATH+= |
| 215 | + |
| 216 | +# LIBS (Precompiled libraries to include in the linker step) |
| 217 | +LIBS= |
| 218 | +LIBS+= $(BOARDPATH)/bsp/gcc/bin/libam_bsp.a |
| 219 | +LIBS+= $(SDKPATH)/mcu/apollo3/hal/gcc/bin/libam_hal.a |
| 220 | +LIBS+= |
| 221 | + |
| 222 | + |
| 223 | + |
| 224 | +#****************************************************************************** |
| 225 | +# |
| 226 | +# Warning Messages |
| 227 | +# |
| 228 | +#****************************************************************************** |
| 229 | +### Bootloader Tools |
| 230 | +AMBIQ_BIN2BOARD=$(PYTHON3) $(COMMONPATH)/tools_sfe/ambiq/ambiq_bin2board.py |
| 231 | +ARTEMIS_SVL=$(PYTHON3) $(COMMONPATH)/tools_sfe/artemis/artemis_svl.py |
| 232 | + |
| 233 | + |
| 234 | +SHELL:=/bin/bash |
| 235 | +#### Setup #### |
| 236 | + |
| 237 | +TOOLCHAIN ?= arm-none-eabi |
| 238 | +PART = apollo3 |
| 239 | +CPU = cortex-m4 |
| 240 | +FPU = fpv4-sp-d16 |
| 241 | +# Default to FPU hardware calling convention. However, some customers and/or |
| 242 | +# applications may need the software calling convention. |
| 243 | +#FABI = softfp |
| 244 | +FABI = hard |
| 245 | + |
| 246 | +STARTUP_FILE := ./startup_$(COMPILERNAME).c |
| 247 | + |
| 248 | +#### Required Executables #### |
| 249 | +CC = $(TOOLCHAIN)-gcc |
| 250 | +GCC = $(TOOLCHAIN)-gcc |
| 251 | +CPP = $(TOOLCHAIN)-cpp |
| 252 | +CXX = $(TOOLCHAIN)-g++ |
| 253 | +LD = $(TOOLCHAIN)-ld |
| 254 | +CP = $(TOOLCHAIN)-objcopy |
| 255 | +OD = $(TOOLCHAIN)-objdump |
| 256 | +RD = $(TOOLCHAIN)-readelf |
| 257 | +AR = $(TOOLCHAIN)-ar |
| 258 | +SIZE = $(TOOLCHAIN)-size |
| 259 | +RM = $(shell which rm 2>/dev/null) |
| 260 | + |
| 261 | +EXECUTABLES = CC LD CP OD AR RD SIZE GCC CXX |
| 262 | +K := $(foreach exec,$(EXECUTABLES),\ |
| 263 | + $(if $(shell which $($(exec)) 2>/dev/null),,\ |
| 264 | + $(info $(exec) not found on PATH ($($(exec))).)$(exec))) |
| 265 | +$(if $(strip $(value K)),$(info Required Program(s) $(strip $(value K)) not found)) |
| 266 | + |
| 267 | +ifneq ($(strip $(value K)),) |
| 268 | +all clean: |
| 269 | + $(info Tools $(TOOLCHAIN)-$(COMPILERNAME) not installed.) |
| 270 | + $(RM) -rf bin |
| 271 | +else |
| 272 | + |
| 273 | + |
| 274 | + |
| 275 | +#****************************************************************************** |
| 276 | +# |
| 277 | +# Machinery |
| 278 | +# |
| 279 | +#****************************************************************************** |
| 280 | + |
| 281 | +XSRC = $(filter %.cpp,$(SRC)) |
| 282 | +ZSRC = $(filter %.cc,$(SRC)) |
| 283 | +CSRC = $(filter %.c,$(SRC)) |
| 284 | +ASRC = $(filter %.s,$(SRC)) |
| 285 | + |
| 286 | +OBJS = $(XSRC:%.cpp=$(CONFIG)/%.o) |
| 287 | +OBJS+= $(ZSRC:%.cc=$(CONFIG)/%.o) |
| 288 | +OBJS+= $(CSRC:%.c=$(CONFIG)/%.o) |
| 289 | +OBJS+= $(ASRC:%.s=$(CONFIG)/%.o) |
| 290 | + |
| 291 | +DEPS = $(XSRC:%.cpp=$(CONFIG)/%.d) |
| 292 | +DEPS+= $(ZSRC:%.cc=$(CONFIG)/%.d) |
| 293 | +DEPS+= $(CSRC:%.c=$(CONFIG)/%.d) |
| 294 | +DEPS+= $(ASRC:%.s=$(CONFIG)/%.d) |
| 295 | + |
| 296 | +CSTD = -std=c99 |
| 297 | + |
| 298 | +CFLAGS = -mthumb -mcpu=$(CPU) -mfpu=$(FPU) -mfloat-abi=$(FABI) |
| 299 | +CFLAGS+= -ffunction-sections -fdata-sections |
| 300 | +CFLAGS+= -MMD -MP -Wall -g |
| 301 | +CFLAGS+= -O0 |
| 302 | +CFLAGS+= $(DEFINES) |
| 303 | +CFLAGS+= $(INCLUDES) |
| 304 | +CFLAGS+= |
| 305 | + |
| 306 | +XSTD = -std=gnu++11 |
| 307 | + |
| 308 | +XFLAGS = $(CFLAGS) |
| 309 | +XFLAGS+= -fno-exceptions -fno-threadsafe-statics # added -fno-threadsafe-statics to allow static local contructors |
| 310 | + |
| 311 | +LFLAGS = -mthumb -mcpu=$(CPU) -mfpu=$(FPU) -mfloat-abi=$(FABI) |
| 312 | +LFLAGS+= -nostartfiles -static |
| 313 | +LFLAGS+= -Wl,--gc-sections,--entry,Reset_Handler,-Map,$(CONFIG)/$(TARGET).map |
| 314 | +LFLAGS+= -Wl,--start-group -lm -lc -lgcc $(LIBS) -Wl,--end-group |
| 315 | +LFLAGS+= |
| 316 | + |
| 317 | +# Additional user specified CFLAGS |
| 318 | +CFLAGS+=$(EXTRA_CFLAGS) |
| 319 | + |
| 320 | +CPFLAGS = -Obinary |
| 321 | + |
| 322 | +ODFLAGS = -S |
| 323 | + |
| 324 | +#****************************************************************************** |
| 325 | +# |
| 326 | +# Targets / Rules |
| 327 | +# |
| 328 | +#****************************************************************************** |
| 329 | +all: asb |
| 330 | +asb: directories $(CONFIG)/$(TARGET)_asb.bin |
| 331 | +svl: directories $(CONFIG)/$(TARGET)_svl.bin |
| 332 | + |
| 333 | +directories: $(CONFIG) |
| 334 | + |
| 335 | +$(CONFIG): |
| 336 | + @mkdir -p $@ |
| 337 | + |
| 338 | +$(CONFIG)/%.o: %.cpp $(CONFIG)/%.d |
| 339 | + @echo " Compiling $(COMPILERNAME) $<" ;\ |
| 340 | + $(CXX) -c $(XSTD) $(XFLAGS) $< -o $@ |
| 341 | + |
| 342 | +$(CONFIG)/%.o: %.cc $(CONFIG)/%.d |
| 343 | + @echo " Compiling $(COMPILERNAME) $<" ;\ |
| 344 | + $(CXX) -c $(XSTD) $(XFLAGS) $< -o $@ |
| 345 | + |
| 346 | +$(CONFIG)/%.o: %.c $(CONFIG)/%.d |
| 347 | + @echo " Compiling $(COMPILERNAME) $<" ;\ |
| 348 | + $(CC) -c $(CFLAGS) $< -o $@ |
| 349 | + |
| 350 | +$(CONFIG)/%.o: %.s $(CONFIG)/%.d |
| 351 | + @echo " Assembling $(COMPILERNAME) $<" ;\ |
| 352 | + $(CC) -c $(CFLAGS) $< -o $@ |
| 353 | + |
| 354 | +$(CONFIG)/$(TARGET)_asb.axf: LINKER_FILE = $(COMMONPATH)/tools_sfe/templates/asb_linker.ld |
| 355 | +$(CONFIG)/$(TARGET)_asb.axf: $(OBJS) $(LIBS) |
| 356 | + @echo " Linking $(COMPILERNAME) $@ with script $(LINKER_FILE)";\ |
| 357 | + $(CC) -Wl,-T,$(LINKER_FILE) -o $@ $(OBJS) $(LFLAGS) |
| 358 | + |
| 359 | +$(CONFIG)/$(TARGET)_svl.axf: LINKER_FILE = $(COMMONPATH)/tools_sfe/templates/asb_svl_linker.ld |
| 360 | +$(CONFIG)/$(TARGET)_svl.axf: $(OBJS) $(LIBS) |
| 361 | + @echo " Linking $(COMPILERNAME) $@ with script $(LINKER_FILE)";\ |
| 362 | + $(CC) -Wl,-T,$(LINKER_FILE) -o $@ $(OBJS) $(LFLAGS) |
| 363 | + |
| 364 | +$(CONFIG)/$(TARGET)_%.bin: $(CONFIG)/$(TARGET)_%.axf |
| 365 | + @echo " Copying $(COMPILERNAME) $@..." ;\ |
| 366 | + $(CP) $(CPFLAGS) $< $@ ;\ |
| 367 | + $(OD) $(ODFLAGS) $< > $(CONFIG)/$(TARGET).lst |
| 368 | + |
| 369 | +bootload_asb: directories $(CONFIG)/$(TARGET)_asb.bin |
| 370 | + $(AMBIQ_BIN2BOARD) --bin $(CONFIG)/$(TARGET)_asb.bin --load-address-blob 0x20000 --magic-num 0xCB -o $(CONFIG)/$(TARGET) --version 0x0 --load-address-wired 0xC000 -i 6 --options 0x1 -b $(ASB_UPLOAD_BAUD) -port $(COM_PORT) -r 2 -v |
| 371 | + |
| 372 | +bootload_svl: directories $(CONFIG)/$(TARGET)_svl.bin |
| 373 | + $(ARTEMIS_SVL) $(COM_PORT) -f $(CONFIG)/$(TARGET)_svl.bin -b $(SVL_UPLOAD_BAUD) -v |
| 374 | + |
| 375 | +bootload: bootload_svl |
| 376 | + |
| 377 | +clean: |
| 378 | + @echo "Cleaning..." ;\ |
| 379 | + $(RM) -R -f $(CONFIG) |
| 380 | + |
| 381 | +$(CONFIG)/%.d: ; |
| 382 | + |
| 383 | +$(SDKPATH)/mcu/apollo3/hal/gcc/bin/libam_hal.a: |
| 384 | + $(MAKE) -C $(SDKPATH)/mcu/apollo3/hal/gcc |
| 385 | + |
| 386 | +$(SDKPATH)/third_party/uecc/gcc/bin/lib_uecc.a: |
| 387 | + $(MAKE) -C $(SDKPATH)/third_party/uecc |
| 388 | + |
| 389 | +$(BOARDPATH)/bsp/gcc/bin/libam_bsp.a: |
| 390 | + $(MAKE) -C $(BOARDPATH)/bsp/gcc |
| 391 | + |
| 392 | +# Automatically include any generated dependencies |
| 393 | +-include $(DEPS) |
| 394 | +endif |
| 395 | +.PHONY: all clean directories bootload bootload_asb bootload_svl |
0 commit comments