SHARE
TWEET

Untitled

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