将我自己的头文件添加到 ATSAMA5D36 开发板库的代码中
Posted
技术标签:
【中文标题】将我自己的头文件添加到 ATSAMA5D36 开发板库的代码中【英文标题】:Add my own header files to a code for ATSAMA5D36 development board libraries 【发布时间】:2018-08-20 10:18:28 【问题描述】:我正在开发 USB CDC Serial,用于通过 SAMA5D36 开发板发送和接收数据。我需要将我创建的标头集成到代码中。
我可以将我自己的头文件和 .c 文件添加到 make 文件中吗? 我在下面给出了make文件文本。 在这个 make 文件中添加的位置令人困惑。
# ---------------------------------------------- ------------------------------
# SAM Software Package License
# ----------------------------------------------------------------------------
# Copyright (c) 2013, Atmel Corporation
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# - Redistributions of source code must retain the above copyright notice,
# this list of conditions and the disclaimer below.
#
# Atmel's name may not be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# DISCLAIMER: THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
# DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
# OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# ----------------------------------------------------------------------------
# Makefile for compiling the USB CDC Serial Converter Example project
#-------------------------------------------------------------------------------
# User-modifiable options
#-------------------------------------------------------------------------------
# Chip & board used for compilation
# (can be overriden by adding CHIP=chip and BOARD=board to the command-line)
CHIP = sama5d3x
BOARD = sama5d3x_ek
# Defines which are the available memory targets for the sama5d3x-EK board.
MEMORIES = ddram
# Trace level used for compilation
# (can be overriden by adding TRACE_LEVEL=#number to the command-line)
# TRACE_LEVEL_DEBUG 5
# TRACE_LEVEL_INFO 4
# TRACE_LEVEL_WARNING 3
# TRACE_LEVEL_ERROR 2
# TRACE_LEVEL_FATAL 1
# TRACE_LEVEL_NO_TRACE 0
TRACE_LEVEL = 4
# Optimization level, put in comment for debugging
OPTIMIZATION =
# Output file basename
OUTPUT = usb_cdc_serial_$(BOARD)_$(CHIP)
# Output directories
BIN = bin
OBJ = obj
#-------------------------------------------------------------------------------
# Tools
#-------------------------------------------------------------------------------
# Tool suffix when cross-compiling
CROSS_COMPILE = arm-none-eabi-
# Libraries
LIBRARIES = ../../../../libraries
# Chip library directory
CHIP_LIB = $(LIBRARIES)/libchip_sama5d3x
# Board library directory
BOARD_LIB = $(LIBRARIES)/libboard_sama5d3x-ek
# storageMedia library directory
STORAGEMEDIA_LIB = $(LIBRARIES)/libstoragemedia
# Sdmmc library directory
SDMMC_LIB = $(LIBRARIES)/libsdmmc
# USB library directory
USB_LIB = $(LIBRARIES)/usb
LIBS = -Wl,--start-group -lgcc -lc -lchip_$(CHIP)_gcc_rel -lboard_$(BOARD)_gcc_rel -lsdmmc_gcc_rel -lstoragemedia_gcc_rel -lusb_gcc_rel -Wl,--end-group
LIB_PATH = -L$(CHIP_LIB)/lib
LIB_PATH += -L$(BOARD_LIB)/lib
LIB_PATH += -L$(STORAGEMEDIA_LIB)/lib
LIB_PATH += -L$(SDMMC_LIB)/lib
LIB_PATH += -L$(USB_LIB)/lib
LIB_PATH+=-L=/lib
LIB_PATH+=-L=/../lib/gcc/arm-none-eabi/4.4.1
# Compilation tools
CC = $(CROSS_COMPILE)gcc
LD = $(CROSS_COMPILE)ld
SIZE = $(CROSS_COMPILE)size
STRIP = $(CROSS_COMPILE)strip
OBJCOPY = $(CROSS_COMPILE)objcopy
GDB = $(CROSS_COMPILE)gdb
NM = $(CROSS_COMPILE)nm
# Flags
INCLUDES = -I$(CHIP_LIB)
INCLUDES += -I$(BOARD_LIB)
INCLUDES += -I$(STORAGEMEDIA_LIB)
INCLUDES += -I$(SDMMC_LIB)
INCLUDES += -I$(USB_LIB)/include
INCLUDES += -I$(LIBRARIES)
CFLAGS += -Wall -Wchar-subscripts -Wcomment -Wformat=2 -Wimplicit-int
CFLAGS += -Werror-implicit-function-declaration -Wmain -Wparentheses
CFLAGS += -Wsequence-point -Wreturn-type -Wswitch -Wtrigraphs -Wunused
CFLAGS += -Wuninitialized -Wunknown-pragmas -Wfloat-equal -Wundef
CFLAGS += -Wshadow -Wpointer-arith -Wbad-function-cast -Wwrite-strings
CFLAGS += -Wsign-compare -Waggregate-return -Wstrict-prototypes
CFLAGS += -Wmissing-prototypes -Wmissing-declarations
CFLAGS += -Wformat -Wmissing-format-attribute -Wno-deprecated-declarations
CFLAGS += -Wredundant-decls -Wnested-externs -Wlong-long
CFLAGS += -Wunreachable-code
# To reduce application size use only integer printf function.
CFLAGS += -Dprintf=iprintf
# -mlong-calls -Wall
CFLAGS += -ffunction-sections
CFLAGS += -g $(OPTIMIZATION) $(INCLUDES) -D$(CHIP) -DTRACE_LEVEL=$(TRACE_LEVEL)
ASFLAGS = -Wall -g $(OPTIMIZATION) $(INCLUDES) -D$(CHIP) -D__ASSEMBLY__
LDFLAGS= -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=entry -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbols
LD_OPTIONAL=-Wl,--print-gc-sections -Wl,--stats
#-------------------------------------------------------------------------------
# Files
#-------------------------------------------------------------------------------
# Directories where source files can be found
VPATH += ../..
# Objects built from C source files
C_OBJECTS += main.o
C_OBJECTS += USBDDriverDescriptors.o
# Append OBJ and BIN directories to output filename
OUTPUT := $(BIN)/$(OUTPUT)
#-------------------------------------------------------------------------------
# Rules
#-------------------------------------------------------------------------------
all: $(BIN) $(OBJ) $(MEMORIES)
$(BIN) $(OBJ):
mkdir $@
define RULES
C_OBJECTS_$(1) = $(addprefix $(OBJ)/$(1)_, $(C_OBJECTS))
ASM_OBJECTS_$(1) = $(addprefix $(OBJ)/$(1)_, $(ASM_OBJECTS))
$(1): $$(ASM_OBJECTS_$(1)) $$(C_OBJECTS_$(1))
$(CC) $(LIB_PATH) $(LDFLAGS) $(LD_OPTIONAL) -T"$(BOARD_LIB)/resources/gcc/$(CHIP)/$$@.ld" -Wl,-Map,$(OUTPUT)-$$@.map -o $(OUTPUT)-$$@.elf $$^ $(LIBS)
$(NM) $(OUTPUT)-$$@.elf >$(OUTPUT)-$$@.elf.txt
$(OBJCOPY) -O binary $(OUTPUT)-$$@.elf $(OUTPUT)-$$@.bin
$(SIZE) $$^ $(OUTPUT)-$$@.elf
$$(C_OBJECTS_$(1)): $(OBJ)/$(1)_%.o: %.c Makefile $(OBJ) $(BIN)
$(CC) $(CFLAGS) -D$(1) -c -o $$@ $$<
$$(ASM_OBJECTS_$(1)): $(OBJ)/$(1)_%.o: %.S Makefile $(OBJ) $(BIN)
$(CC) $(ASFLAGS) -D$(1) -c -o $$@ $$<
debug_$(1): $(1)
$(GDB) -x "$(BOARD_LIB)/resources/gcc/sama5d3x-ek-$(1).gdb" -ex "reset" -readnow -se $(OUTPUT)-$(1).elf
endef
$(foreach MEMORY, $(MEMORIES), $(eval $(call RULES,$(MEMORY))))
clean:
-cs-rm -fR $(OBJ) $(BIN)
我是这个东西的新手,任何帮助表示赞赏。
提前致谢
【问题讨论】:
【参考方案1】:首先阅读documentation of GNU make
。然后阅读Invoking GCC 和documentation of the ld
linker(因为make
和你的Makefile
可能会调用这些)。
您可能想要添加(适当地,在您的Makefile
中):
一些 INCLUDES += -I
some-includedir-path 行,
一些 LIB_PATH += -L
some-libdir-path 行,
并增加LIBS =
行。
添加这些的地方很重要。
不要忘记检查您是否在法律上允许更改 Makefile
。所以研究它的许可或版权(也许在你的律师的帮助下)。我想你可以,但我不是律师(你可以看看open source licenses ...)
顺便说一句,您可以使用remake(带有标志-x
)来调试您的Makefile
【讨论】:
我可以添加同一个make文件吗? 谢谢巴西尔 Starynkevitch 如果合适,请随意投票或接受该答案 我的声望太低,不能投抱歉。以上是关于将我自己的头文件添加到 ATSAMA5D36 开发板库的代码中的主要内容,如果未能解决你的问题,请参考以下文章
如何将我自己的 XML 配置文件添加到 Windows 服务 C#
新手请教:我自创建了c语言头文件,可是为啥运行时自己的头文件不能包含进去。请高手为我解答。谢了!