将我自己的 header 文件添加到 ATSAMA5D36 开发板库的代码中
Add my own header files to a code for ATSAMA5D36 development board libraries
我正在研究 USB CDC Serial,用于通过 SAMA5D36 开发板发送和接收数据。我需要将我创建的 headers 集成到代码中。
我可以将自己的 headers 和 .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)
我是这个东西的新手,感谢任何帮助。
提前致谢
首先阅读 documentation of GNU make
. Then read about Invoking GCC and the documentation of the ld
linker(因为 make
和您的 Makefile
可能会调用这些)。
您可能想添加(适当地,在您的 Makefile
中):
some INCLUDES += -I
some-includedir-path 行,
some LIB_PATH += -L
some-libdir-path 行,
并扩充 LIBS =
行。
添加这些的地方很重要。
不要忘记检查您是否在法律上允许更改 Makefile
。所以研究它的许可证或版权(也许在你的律师的帮助下)。我想你可以,但我不是律师(你可能会调查 open source licenses ...)
顺便说一句,您可以使用 remake(带有其标志 -x
)来调试您的 Makefile
我正在研究 USB CDC Serial,用于通过 SAMA5D36 开发板发送和接收数据。我需要将我创建的 headers 集成到代码中。
我可以将自己的 headers 和 .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)
我是这个东西的新手,感谢任何帮助。
提前致谢
首先阅读 documentation of GNU make
. Then read about Invoking GCC and the documentation of the ld
linker(因为 make
和您的 Makefile
可能会调用这些)。
您可能想添加(适当地,在您的 Makefile
中):
some
INCLUDES += -I
some-includedir-path 行,some
LIB_PATH += -L
some-libdir-path 行,并扩充
LIBS =
行。
添加这些的地方很重要。
不要忘记检查您是否在法律上允许更改 Makefile
。所以研究它的许可证或版权(也许在你的律师的帮助下)。我想你可以,但我不是律师(你可能会调查 open source licenses ...)
顺便说一句,您可以使用 remake(带有其标志 -x
)来调试您的 Makefile