subrepo:
  subdir:   "libopencm3"
  merged:   "88e91c9a7cce"
upstream:
  origin:   "https://github.com/libopencm3/libopencm3.git"
  branch:   "master"
  commit:   "88e91c9a7cce"
git-subrepo:
  version:  "0.4.3"
  origin:   "???"
  commit:   "???"
This commit is contained in:
2023-01-21 21:54:42 +02:00
parent f01f2a30fa
commit 054740c5de
1205 changed files with 191912 additions and 0 deletions

121
libopencm3/mk/README Normal file
View File

@@ -0,0 +1,121 @@
-------------------------------------------------------------------------------
README
-------------------------------------------------------------------------------
This directory contains makefile modular support files, that can be used in
your project.
Each module is packaged with two inclusion makefiles, <module>-config.mk and
<module>-rules.mk. The first one defines some new variables for the make, or
appends values to the existing variables for the make. The second defines rules
for support building.
So in your project, the <module>-config.mk should be included at some place,
where you are defining variables (near the beginning of the file), and file
<module>-rules.mk should be included in the rules part of makefile (somewhere
near to the end of file).
Example makefile using the gcc compiler module together with the linker script
generator module:
>>>>>>
DEVICE =
OPENCM3_DIR =
OBJS += foo.o
CFLAGS += -Os -ggdb3
CPPFLAGS += -MD
LDFLAGS += -static -nostartfiles
LDLIBS += -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group
include $(OPENCM3_DIR)/mk/genlink-config.mk
include $(OPENCM3_DIR)/mk/gcc-config.mk
.PHONY: clean all
all: binary.elf binary.hex
clean:
$(Q)$(RM) -rf binary.* *.o
include $(OPENCM3_DIR)/mk/genlink-rules.mk
include $(OPENCM3_DIR)/mk/gcc-rules.mk
<<<<<<
MODULES
=======
-------------------------------------------------------------------------------
gcc
-------------------------------------------------------------------------------
This module adds an extended support for GCC toolchain. This adds rules,
necessary for compiling C and C++ files into elf binary, and rules for
generation of bin, hex, or srec output files for flashing.
Variables to control the build process (should be set in your makefile):
------------------------------------------------------------------------
CFLAGS C compiler flags
CXXFLAGS C++ compiler flags
CPPFLAGS C preprocessor flags (used for C and for C++ compiler)
LDFLAGS Linker flags
ARCH_FLAGS Architecture specification flags (-mcpu, -march etc )
Variables to tell gcc about project dependencies and input files
----------------------------------------------------------------
LDSCRIPT Linker script file name (can be generated or fixed)
LIBDEPS Array of library filenames that should be rebuilt if needed
LDLIBS Array of libraries to be linked with (array of -l<libname>)
OBJS Array of object files to be built
-------------------------------------------------------------------------------
genlink
-------------------------------------------------------------------------------
This module adds an support for the user to the linker script generator. The
linker script will be generated as the file $(DEVICE).ld in the project folder,
and automatically be used for the linking process.
Additionally the matching library is added to the LDLIBS variable.
Variables to control the build process (should be set in your makefile):
------------------------------------------------------------------------
DEVICE The full device part name used for the compilation process.
OPENCM3_DIR The root path of libopencm3 library.
Output variables from this module:
----------------------------------
CPPFLAGS (appended)
- Appends the chip family to the CPPFLAGS. For example -DSTM32F1
- Appends the include path for libopencm3
ARCH_FLAGS (replaced)
- Architecture build flags for specified chip.
* No needed to handle this variable if you use module <gcc> too.
LDSCRIPT (replaced)
- Linker script generated file.
* No needed to handle this variable if you use module <gcc> too.
LDLIBS (appended)
- LDLIBS += -lopencm3_$(family) is appended to link against the
matching library.
LDFLAGS (appended)
- LDFLAGS += -L$(OPENCM3_DIR)/lib is appended to make sure the
matching library can be found.
family,cpu,fpu (replaced)
- these are used internally to create the above variables
Temporary variables that you should not use in your makefile:
-------------------------------------------------------------
GENLINK_DEFS
GENLINK_ARCH
GENLINK_LIB

View File

@@ -0,0 +1,37 @@
##
## This file is part of the libopencm3 project.
##
## Copyright (C) 2014 Frantisek Burian <BuFran@seznam.cz>
##
## This library is free software: you can redistribute it and/or modify
## it under the terms of the GNU Lesser General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This library is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public License
## along with this library. If not, see <http://www.gnu.org/licenses/>.
##
###############################################################################
# The support makefile for GCC compiler toolchain, the rules part.
#
# please read mk/README for specification how to use this file in your project
PREFIX ?= arm-none-eabi
#PREFIX ?= arm-elf
CC := $(PREFIX)-gcc
CXX := $(PREFIX)-g++
LD := $(PREFIX)-gcc
AR := $(PREFIX)-ar
AS := $(PREFIX)-as
OBJCOPY := $(PREFIX)-objcopy
OBJDUMP := $(PREFIX)-objdump
GDB := $(PREFIX)-gdb
SIZE := $(PREFIX)-size

View File

@@ -0,0 +1,56 @@
##
## This file is part of the libopencm3 project.
##
## Copyright (C) 2014 Frantisek Burian <BuFran@seznam.cz>
##
## This library is free software: you can redistribute it and/or modify
## it under the terms of the GNU Lesser General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This library is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public License
## along with this library. If not, see <http://www.gnu.org/licenses/>.
##
###############################################################################
# The support makefile for GCC compiler toolchain, the rules part.
#
# please read mk/README for specification how to use this file in your project
#
%.bin: %.elf
@printf " OBJCOPY $@\n"
$(Q)$(OBJCOPY) -Obinary $< $@
%.hex: %.elf
@printf " OBJCOPY $@\n"
$(Q)$(OBJCOPY) -Oihex $< $@
%.srec: %.elf
@printf " OBJCOPY $@\n"
$(Q)$(OBJCOPY) -Osrec $< $@
%.list: %.elf
@printf " OBJDUMP $@\n"
$(Q)$(OBJDUMP) -S $< > $@
%.elf: $(OBJS) $(LDSCRIPT) $(LIBDEPS)
@printf " LD $(*).elf\n"
$(Q)$(LD) $(OBJS) $(LDLIBS) $(LDFLAGS) -T$(LDSCRIPT) $(ARCH_FLAGS) -o $@
%.o: %.c
@printf " CC $<\n"
$(Q)$(CC) $(CFLAGS) $(CPPFLAGS) $(ARCH_FLAGS) -o $@ -c $<
%.o: %.cxx
@printf " CXX $<\n"
$(Q)$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(ARCH_FLAGS) -o $@ -c $<
%.o: %.cpp
@printf " CXX $(*).cpp\n"
$(Q)$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(ARCH_FLAGS) -o $@ -c $<

View File

@@ -0,0 +1,84 @@
##
## This file is part of the libopencm3 project.
##
## Copyright (C) 2014 Frantisek Burian <BuFran@seznam.cz>
##
## This library is free software: you can redistribute it and/or modify
## it under the terms of the GNU Lesser General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This library is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public License
## along with this library. If not, see <http://www.gnu.org/licenses/>.
##
ifeq ($(DEVICE),)
$(warning no DEVICE specified for linker script generator)
endif
LDSCRIPT = generated.$(DEVICE).ld
DEVICES_DATA = $(OPENCM3_DIR)/ld/devices.data
genlink_family :=$(shell $(OPENCM3_DIR)/scripts/genlink.py $(DEVICES_DATA) $(DEVICE) FAMILY)
genlink_subfamily :=$(shell $(OPENCM3_DIR)/scripts/genlink.py $(DEVICES_DATA) $(DEVICE) SUBFAMILY)
genlink_cpu :=$(shell $(OPENCM3_DIR)/scripts/genlink.py $(DEVICES_DATA) $(DEVICE) CPU)
genlink_fpu :=$(shell $(OPENCM3_DIR)/scripts/genlink.py $(DEVICES_DATA) $(DEVICE) FPU)
genlink_cppflags :=$(shell $(OPENCM3_DIR)/scripts/genlink.py $(DEVICES_DATA) $(DEVICE) CPPFLAGS)
CPPFLAGS += $(genlink_cppflags)
ARCH_FLAGS :=-mcpu=$(genlink_cpu)
ifeq ($(genlink_cpu),$(filter $(genlink_cpu),cortex-m0 cortex-m0plus cortex-m3 cortex-m4 cortex-m7))
ARCH_FLAGS +=-mthumb
endif
ifeq ($(genlink_fpu),soft)
ARCH_FLAGS += -msoft-float
else ifeq ($(genlink_fpu),hard-fpv4-sp-d16)
ARCH_FLAGS += -mfloat-abi=hard -mfpu=fpv4-sp-d16
else ifeq ($(genlink_fpu),hard-fpv5-d16)
ARCH_FLAGS += -mfloat-abi=hard -mfpu=fpv5-d16
else ifeq ($(genlink_fpu),hard-fpv5-sp-d16)
ARCH_FLAGS += -mfloat-abi=hard -mfpu=fpv5-sp-d16
else
$(warning No match for the FPU flags)
endif
ifeq ($(genlink_family),)
$(warning $(DEVICE) not found in $(DEVICES_DATA))
endif
# only append to LDFLAGS if the library file exists to not break builds
# where those are provided by different means
ifneq (,$(wildcard $(OPENCM3_DIR)/lib/libopencm3_$(genlink_family).a))
LIBNAME = opencm3_$(genlink_family)
else
ifneq (,$(wildcard $(OPENCM3_DIR)/lib/libopencm3_$(genlink_subfamily).a))
LIBNAME = opencm3_$(genlink_subfamily)
else
$(warning $(OPENCM3_DIR)/lib/libopencm3_$(genlink_family).a library variant for the selected device does not exist.)
endif
endif
LDLIBS += -l$(LIBNAME)
LIBDEPS += $(OPENCM3_DIR)/lib/lib$(LIBNAME).a
# only append to LDLIBS if the directory exists
ifneq (,$(wildcard $(OPENCM3_DIR)/lib))
LDFLAGS += -L$(OPENCM3_DIR)/lib
else
$(warning $(OPENCM3_DIR)/lib as given be OPENCM3_DIR does not exist.)
endif
# only append include path to CPPFLAGS if the directory exists
ifneq (,$(wildcard $(OPENCM3_DIR)/include))
CPPFLAGS += -I$(OPENCM3_DIR)/include
else
$(warning $(OPENCM3_DIR)/include as given be OPENCM3_DIR does not exist.)
endif

View File

@@ -0,0 +1,22 @@
##
## This file is part of the libopencm3 project.
##
## Copyright (C) 2014 Frantisek Burian <BuFran@seznam.cz>
##
## This library is free software: you can redistribute it and/or modify
## it under the terms of the GNU Lesser General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## This library is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public License
## along with this library. If not, see <http://www.gnu.org/licenses/>.
##
$(LDSCRIPT): $(OPENCM3_DIR)/ld/linker.ld.S $(DEVICES_DATA)
@printf " GENLNK $(DEVICE)\n"
$(Q)$(CPP) $(ARCH_FLAGS) $(shell $(OPENCM3_DIR)/scripts/genlink.py $(DEVICES_DATA) $(DEVICE) DEFS) -P -E $< -o $@