Advertisement
Guest User

Makefile for Custom Artemis Project

a guest
Oct 14th, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Make 12.28 KB | None | 0 0
  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. # COM_PORT is the serial port to use for uploading. For example COM#### on Windows or /dev/cu.usbserial-#### on *nix
  80. COM_PORT            ?=
  81. # 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
  82. ASB_UPLOAD_BAUD         ?=
  83. # SVL_UPLOAD_BAUD is the baud rate setting of the SparkFun Variable Loader (SVL). Defaults to 921600 if unset
  84. SVL_UPLOAD_BAUD         ?=
  85. # PYTHON3 should evaluate to a call to the Python3 executable on your machine
  86. PYTHON3                         ?=
  87.  
  88. # *Optionally* specify absolute paths to the SDK and the BSP
  89. # Make sure to use / instead of \ when on Windows
  90. SDKPATH         =$(HOME)/AmbiqSDK#          #?=# Set as the path to the SDK root if not located at ../../../../..
  91. COMMONPATH      =$(SDKPATH)/boards_sfe/common#              ?=# Set as the path to the BSP if not located at ../../../../common
  92. BOARDPATH       =$(SDKPATH)/boards_sfe/redboard_artemis#                ?=# Set as the path to the board if not located at ../../..
  93. PROJECTPATH     =..#            ?=# Set as the path to the project if not located at ../..
  94.  
  95. ### Project Settings
  96. TARGET := example
  97. COMPILERNAME := gcc
  98. PROJECT := example_gcc
  99. CONFIG := bin
  100.  
  101. ## User Source Files
  102. USER_INCLUDE_DIRS    = -I../src/inc1
  103. USER_INCLUDE_DIRS   += -I../src/inc2
  104.  
  105. USER_SOURCEDIRS      = ../src
  106. USER_SOURCEDIRS     += ../src/inc1
  107. USER_SOURCEDIRS     += ../src/inc2
  108.  
  109. USER_MAIN_SRC        = main.c
  110. USER_SOURCE_FILES    = inc1.c
  111. USER_SOURCE_FILES   += inc2.c
  112.  
  113. #******************************************************************************
  114. #
  115. # Warning Messages
  116. #
  117. #******************************************************************************
  118. ifeq ($(COM_PORT),)
  119.     COM_PORT=COM4
  120.     $(warning warning: you have not defined COM_PORT. Assuming it is COM4)
  121. endif
  122. ifeq ($(PYTHON3),)
  123.     PYTHON3=python3
  124.     $(warning warning: you have not defined PYTHON3. assuming it is accessible by 'python3')
  125. endif
  126. ifeq ($(ASB_UPLOAD_BAUD),)
  127.     ASB_UPLOAD_BAUD=115200
  128.     $(warning defaulting to 115200 baud for ASB)
  129. endif
  130. ifeq ($(SVL_UPLOAD_BAUD),)
  131.     SVL_UPLOAD_BAUD=921600
  132.     $(warning defaulting to 921600 baud for SVL)
  133. endif
  134.  
  135. ifeq ($(SDKPATH),)
  136.     SDKPATH         =../../../../..
  137.     $(warning warning: you have not defined SDKPATH so will continue assuming that the SDK root is at $(SDKPATH))
  138. else
  139. # When the SDKPATH is given export it
  140. export SDKPATH
  141. endif
  142.  
  143. ifeq ($(COMMONPATH),)
  144.     COMMONPATH          =../../../../common
  145.     $(warning warning: you have not defined COMMONPATH so will continue assuming that the COMMON root is at $(COMMONPATH))
  146. else
  147. # When the COMMONPATH is given export it
  148. export COMMONPATH
  149. endif
  150.  
  151. ifeq ($(BOARDPATH),)
  152.     BOARDPATH           =../../..
  153.     $(warning warning: you have not defined BOARDPATH so will continue assuming that the BOARD root is at $(BOARDPATH))
  154. else
  155. # When the BOARDPATH is given export it
  156. export BOARDPATH
  157. endif
  158.  
  159. ifeq ($(PROJECTPATH),)
  160.     PROJECTPATH         =..
  161.     $(warning warning: you have not defined PROJECTPATH so will continue assuming that the PROJECT root is at $(PROJECTPATH))
  162. else
  163. # When the PROJECTPATH is given export it
  164. export PROJECTPATH
  165. endif
  166.  
  167. #******************************************************************************
  168. #
  169. # User Defines / Includes / Sources / Libraries
  170. #
  171. #******************************************************************************
  172.  
  173. # Global Defines
  174. DEFINES=  -DPART_$(PART)
  175. DEFINES+= -DAM_CUSTOM_BDADDR
  176. DEFINES+= -DAM_PACKAGE_BGA
  177. DEFINES+= -DWSF_TRACE_ENABLED
  178. DEFINES+= -DAM_DEBUG_PRINTF
  179. DEFINES+= -DAM_PART_APOLLO3
  180. DEFINES+=
  181.  
  182. # Includes (Add paths to where example header files are located)
  183. INCLUDES=
  184. INCLUDES+= -I$(PROJECTPATH)/src
  185. INCLUDES+= -I$(BOARDPATH)/bsp
  186. INCLUDES+= -I$(SDKPATH)
  187. INCLUDES+= -I$(SDKPATH)/utils
  188. INCLUDES+= -I$(SDKPATH)/devices
  189. INCLUDES+= -I$(SDKPATH)/mcu/apollo3
  190. INCLUDES+= -I$(SDKPATH)/CMSIS/AmbiqMicro/Include
  191. INCLUDES+= -I$(SDKPATH)/CMSIS/ARM/Include
  192. INCLUDES+= ${USER_INCLUDE_DIRS}
  193. INCLUDES+=
  194.  
  195. # Compilation Units (Add all the .c files you need to compile)
  196. SRC = ${USER_MAIN_SRC}
  197. SRC += ${USER_SOURCE_FILES}
  198. # SRC=
  199. # SRC+= main.c
  200. # SRC+= inc1.c
  201. # SRC+= inc2.c
  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)/examples/hello_world_uart
  209. VPATH+= $(COMMONPATH)/tools_sfe/templates
  210. VPATH+= ${USER_SOURCEDIRS}
  211. VPATH+=
  212.  
  213. # LIBS (Precompiled libraries to include in the linker step)
  214. LIBS=
  215. LIBS+= $(BOARDPATH)/bsp/gcc/bin/libam_bsp.a
  216. LIBS+= $(SDKPATH)/mcu/apollo3/hal/gcc/bin/libam_hal.a
  217. LIBS+=
  218.  
  219.  
  220.  
  221. #******************************************************************************
  222. #
  223. # Warning Messages
  224. #
  225. #******************************************************************************
  226. ### Bootloader Tools
  227. AMBIQ_BIN2BOARD=$(PYTHON3) $(COMMONPATH)/tools_sfe/ambiq/ambiq_bin2board.py
  228. ARTEMIS_SVL=$(PYTHON3) $(COMMONPATH)/tools_sfe/artemis/artemis_svl.py
  229.  
  230.  
  231. SHELL:=/bin/bash
  232. #### Setup ####
  233.  
  234. TOOLCHAIN ?= arm-none-eabi
  235. PART = apollo3
  236. CPU = cortex-m4
  237. FPU = fpv4-sp-d16
  238. # Default to FPU hardware calling convention.  However, some customers and/or
  239. # applications may need the software calling convention.
  240. #FABI = softfp
  241. FABI = hard
  242.  
  243. STARTUP_FILE := ./startup_$(COMPILERNAME).c
  244.  
  245. #### Required Executables ####
  246. CC = $(TOOLCHAIN)-gcc
  247. GCC = $(TOOLCHAIN)-gcc
  248. CPP = $(TOOLCHAIN)-cpp
  249. LD = $(TOOLCHAIN)-ld
  250. CP = $(TOOLCHAIN)-objcopy
  251. OD = $(TOOLCHAIN)-objdump
  252. RD = $(TOOLCHAIN)-readelf
  253. AR = $(TOOLCHAIN)-ar
  254. SIZE = $(TOOLCHAIN)-size
  255. RM = $(shell which rm 2>/dev/null)
  256.  
  257. EXECUTABLES = CC LD CP OD AR RD SIZE GCC
  258. K := $(foreach exec,$(EXECUTABLES),\
  259.         $(if $(shell which $($(exec)) 2>/dev/null),,\
  260.         $(info $(exec) not found on PATH ($($(exec))).)$(exec)))
  261. $(if $(strip $(value K)),$(info Required Program(s) $(strip $(value K)) not found))
  262.  
  263. ifneq ($(strip $(value K)),)
  264. all clean:
  265.     $(info Tools $(TOOLCHAIN)-$(COMPILERNAME) not installed.)
  266.     $(RM) -rf bin
  267. else
  268.  
  269.  
  270.  
  271. #******************************************************************************
  272. #
  273. # Machinery
  274. #
  275. #******************************************************************************
  276.  
  277. CSRC = $(filter %.c,$(SRC))
  278. ASRC = $(filter %.s,$(SRC))
  279.  
  280. OBJS = $(CSRC:%.c=$(CONFIG)/%.o)
  281. OBJS+= $(ASRC:%.s=$(CONFIG)/%.o)
  282.  
  283. DEPS = $(CSRC:%.c=$(CONFIG)/%.d)
  284. DEPS+= $(ASRC:%.s=$(CONFIG)/%.d)
  285.  
  286. CFLAGS = -mthumb -mcpu=$(CPU) -mfpu=$(FPU) -mfloat-abi=$(FABI)
  287. CFLAGS+= -ffunction-sections -fdata-sections
  288. CFLAGS+= -MMD -MP -std=c99 -Wall -g
  289. CFLAGS+= -O0
  290. CFLAGS+= $(DEFINES)
  291. CFLAGS+= $(INCLUDES)
  292. CFLAGS+=
  293.  
  294. LFLAGS = -mthumb -mcpu=$(CPU) -mfpu=$(FPU) -mfloat-abi=$(FABI)
  295. LFLAGS+= -nostartfiles -static
  296. LFLAGS+= -Wl,--gc-sections,--entry,Reset_Handler,-Map,$(CONFIG)/$(TARGET).map
  297. LFLAGS+= -Wl,--start-group -lm -lc -lgcc $(LIBS) -Wl,--end-group
  298. LFLAGS+=
  299.  
  300. # Additional user specified CFLAGS
  301. CFLAGS+=$(EXTRA_CFLAGS)
  302.  
  303. CPFLAGS = -Obinary
  304.  
  305. ODFLAGS = -S
  306.  
  307. #******************************************************************************
  308. #
  309. # Targets / Rules
  310. #
  311. #******************************************************************************
  312. all: directories $(CONFIG)/$(TARGET)_asb.bin
  313.  
  314. directories: $(CONFIG)
  315.  
  316. $(CONFIG):
  317.     @mkdir -p $@
  318.  
  319. $(CONFIG)/%.o: %.c $(CONFIG)/%.d
  320.     @echo " Compiling $(COMPILERNAME) $<" ;\
  321.     $(CC) -c $(CFLAGS) $< -o $@
  322.  
  323. $(CONFIG)/%.o: %.s $(CONFIG)/%.d
  324.     @echo " Assembling $(COMPILERNAME) $<" ;\
  325.     $(CC) -c $(CFLAGS) $< -o $@
  326.  
  327. $(CONFIG)/$(TARGET)_asb.axf: LINKER_FILE = $(COMMONPATH)/tools_sfe/templates/asb_linker.ld
  328. $(CONFIG)/$(TARGET)_asb.axf: $(OBJS) $(LIBS)
  329.     @echo " Linking $(COMPILERNAME) $@ with script $(LINKER_FILE)";\
  330.     $(CC) -Wl,-T,$(LINKER_FILE) -o $@ $(OBJS) $(LFLAGS)
  331.  
  332. $(CONFIG)/$(TARGET)_svl.axf: LINKER_FILE = $(COMMONPATH)/tools_sfe/templates/asb_svl_linker.ld
  333. $(CONFIG)/$(TARGET)_svl.axf: $(OBJS) $(LIBS)
  334.     @echo " Linking $(COMPILERNAME) $@ with script $(LINKER_FILE)";\
  335.     $(CC) -Wl,-T,$(LINKER_FILE) -o $@ $(OBJS) $(LFLAGS)
  336.  
  337. $(CONFIG)/$(TARGET)_%.bin: $(CONFIG)/$(TARGET)_%.axf
  338.     @echo " Copying $(COMPILERNAME) $@..." ;\
  339.     $(CP) $(CPFLAGS) $< $@ ;\
  340.     $(OD) $(ODFLAGS) $< > $(CONFIG)/$(TARGET).lst
  341.  
  342. bootload_asb: $(CONFIG)/$(TARGET)_asb.bin
  343.     $(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
  344.  
  345. bootload_svl: $(CONFIG)/$(TARGET)_svl.bin
  346.     $(ARTEMIS_SVL) $(COM_PORT) -f $(CONFIG)/$(TARGET)_svl.bin -b $(SVL_UPLOAD_BAUD) -v
  347.  
  348. bootload: bootload_svl
  349.  
  350. clean:
  351.     @echo "Cleaning..." ;\
  352.     $(RM) -f $(OBJS) $(DEPS) \
  353.         $(CONFIG)/$(TARGET).bin $(CONFIG)/$(TARGET).axf \
  354.         $(CONFIG)/$(TARGET).lst $(CONFIG)/$(TARGET).map
  355.  
  356. $(CONFIG)/%.d: ;
  357.  
  358. $(SDKPATH)/mcu/apollo3/hal/gcc/bin/libam_hal.a:
  359.     $(MAKE) -C $(SDKPATH)/mcu/apollo3/hal/gcc
  360.  
  361. $(SDKPATH)/third_party/uecc/gcc/bin/lib_uecc.a:
  362.     $(MAKE) -C $(SDKPATH)/third_party/uecc
  363.  
  364. $(BOARDPATH)/bsp/gcc/bin/libam_bsp.a:
  365.     $(MAKE) -C $(BOARDPATH)/bsp/gcc
  366.  
  367. # Automatically include any generated dependencies
  368. -include $(DEPS)
  369. endif
  370. .PHONY: all clean directories bootload bootload_asb bootload_svl
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement