Init project

This commit is contained in:
Maximilian Grau 2021-01-06 00:58:55 +01:00
parent 702fa003b1
commit 7cc9eca65f
120 changed files with 105353 additions and 0 deletions

36
core/mk/gcc-config.mk Normal file
View file

@ -0,0 +1,36 @@
##
## 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
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

34
core/mk/include.mk Normal file
View file

@ -0,0 +1,34 @@
ifeq ($(RELEASE),1)
CONFIGURATION := release
RELEASE_OPT ?= 3
OPTIMIZATION := -O$(RELEASE_OPT) -g
else
CONFIGURATION := debug
OPTIMIZATION := -Og -g
DEFS += DEBUG
endif
ROOTDIR := $(dir $(firstword $(MAKEFILE_LIST)))
BASEDIR := $(dir $(lastword $(MAKEFILE_LIST)))../
MXDIR := $(ROOTDIR)cubemx/
OUTPUT_DIR := $(ROOTDIR)build/$(CONFIGURATION)/
OBJDIR := $(OUTPUT_DIR)/obj
INCDIRS += \
$(BASEDIR)include \
SOURCES += \
$(BASEDIR)src/abi.cpp \
$(BASEDIR)src/std.cpp
# CubeMX
include cubemx/Makefile
SOURCES += $(foreach source,$(C_SOURCES) $(ASM_SOURCES),$(MXDIR)$(source))
INCDIRS += $(C_INCLUDES:-I%=$(MXDIR)%)
INCDIRS += $(AS_INCLUDES:-I%=$(MXDIR)%)
LDSCRIPT := $(MXDIR)$(LDSCRIPT)
# Include actual rules
include $(BASEDIR)mk/rules.mk

100
core/mk/rules.mk Normal file
View file

@ -0,0 +1,100 @@
STFLASH = $(shell which st-flash)
JFLASH = $(shell which JLinkExe)
# Object files
TMP1 := $(patsubst %.c, $(OBJDIR)/%.o, $(SOURCES))
TMP2 := $(patsubst %.cpp, $(OBJDIR)/%.o, $(TMP1))
TMP3 := $(patsubst %.cxx, $(OBJDIR)/%.o, $(TMP2))
OBJS := $(patsubst %.s, $(OBJDIR)/%.o, $(TMP3))
BINARY := $(OUTPUT_DIR)$(TARGET)
# C/C++ standards
CSTD ?= c11
CXXSTD ?= c++17
# Compiler flags
SPECS ?= --specs=nano.specs
CFLAGS += -std=$(CSTD) $(OPTIMIZATION) -fno-builtin-log
CPPFLAGS += -ffunction-sections -fdata-sections -fno-common
CPPFLAGS += -pedantic -Wall -Wextra
CPPFLAGS += -Wno-unused-parameter -Wno-unused-variable
CPPFLAGS += -fexec-charset=cp1252
CPPFLAGS += $(DEFS:%=-D%)
CPPFLAGS += $(C_DEFS) $(AS_DEFS)
CPPFLAGS += $(INCDIRS:%=-I%)
CPPFLAGS += -MMD -MP -MF"$(@:%.o=%.d)"
CPPFLAGS += $(SPECS)
CXXFLAGS += -std=$(CXXSTD) $(OPTIMIZATION)
CXXFLAGS += -fno-exceptions -fno-rtti -fno-unwind-tables -Wno-register -fno-math-errno
# Linker flags
LDFLAGS += $(SPECS)
LDFLAGS += --static
LDFLAGS += -Wl,--gc-sections
LDFLAGS += -Wl,--print-memory-usage
LDFLAGS += -Wl,-Map=$(BINARY).map
LDLIBS += -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group
# Be silent per default, but 'make V=1' will show all compiler calls.
ifneq ($(V),1)
Q := @
endif
# Toolchain stuff
include $(BASEDIR)mk/gcc-config.mk
# Rules
.PHONY: clean all stflash jflash
.SECONDARY:
all: $(BINARY).bin $(BINARY).list
print-%:
@echo $*=$($*)
%.bin: %.elf
@printf " OBJCOPY $@\n"
$(Q)$(OBJCOPY) -Obinary $< $@
%.list: %.elf
@printf " OBJDUMP $@\n"
$(Q)$(OBJDUMP) -S $< > $@
%.elf: $(OBJS) $(LIBDEPS)
@printf " LD $@\n"
$(Q)$(LD) $(OBJS) $(LDLIBS) $(LDFLAGS) -T$(LDSCRIPT) $(MCU) -o $@
$(OBJDIR)/%.o: %.s
@printf " AS $<\n"
@mkdir -p $(dir $@)
$(Q)$(CC) -x assembler-with-cpp $(CFLAGS) $(CPPFLAGS) $(MCU) -c $< -o $@
$(OBJDIR)/%.o: %.c
@printf " CC $<\n"
@mkdir -p $(dir $@)
$(Q)$(CC) $(CFLAGS) $(CPPFLAGS) $(MCU) -c $< -o $@
$(OBJDIR)/%.o: %.cpp
@printf " CXX $<\n"
@mkdir -p $(dir $@)
$(Q)$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(MCU) -c $< -o $@
$(OBJDIR)/%.o: %.cxx
@printf " CXX $<\n"
@mkdir -p $(dir $@)
$(Q)$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(MCU) -c $< -o $@
clean:
@$(RM) -Rf build dsdlc_generated
stflash:$(BINARY).bin
$(STFLASH) $(FLASHSIZE) write $(BINARY).bin 0x8000000
jflash: $(BINARY).bin
$(JFLASH) -Autoconnect 1 -Device $(DEVICE) -If SWD -Speed 4000 -CommandFile flash_commands.jlink
-include $(OBJS:.o=.d)

116
core/src/abi.cpp Normal file
View file

@ -0,0 +1,116 @@
#include <cstddef>
#if FW_USE_RTOS
extern "C"
{
#include <FreeRTOS.h>
#include <task.h>
}
#endif
void *operator new(std::size_t size)
{
#if FW_USE_RTOS
return pvPortMalloc(size);
#else
return reinterpret_cast<void *>(0xffffffff);
#endif
}
void *operator new[](std::size_t size)
{
return operator new(size);
}
void operator delete(void *ptr)
{
#if FW_USE_RTOS
vPortFree(ptr);
#else
while (1)
{
}
#endif
}
void operator delete(void *ptr, unsigned int)
{
operator delete(ptr);
}
void operator delete[](void *ptr)
{
operator delete(ptr);
}
void operator delete[](void *ptr, unsigned int)
{
operator delete[](ptr);
}
extern "C"
{
int __aeabi_atexit(void *, void (*)(void *), void *)
{
return 0;
}
/**
* Many faulty implementations are available where __guard is defined as a 64-bit integer by
*
* __extension__ typedef int __guard __attribute__((mode(__DI__)));
*
* This is correct for the Generic C++ ABI (GC++ABI), but not for the ARM C++ ABI. See section
* 3.1 "Summary of differences from and additions to the generic C++ ABI" of "C++ ABI for the
* ARM Architectur" (version 2.10):
*
* ===
*
* GC++ABI §2.8 Initialization guard variables
* Static initialization guard variables are 4 bytes long not 8, and there is a different
* protocol for using them which allows a guard variable to implement a semaphore when used as
* the target of ARM SWP or LDREX and STREX instructions. See §3.2.3.
*
* GC++ABI §3.3.2 One-time construction API
* The type of parameters to __cxa_guard_acquire, __cxa_guard_release and __cxa_guard_abort is
* 'int*' (not '__int64_t*'), and use of fields in the guard variable differs. See §3.2.3.
*
* ===
*
* Using a 64-bit here will lead to reading beyond the actual guard variable and can thus lead
* to serious bugs.
*/
typedef int __guard;
void __cxa_atexit(void (*)(void *), void *, void *)
{
}
int __cxa_guard_acquire(__guard *g)
{
return !*g;
}
void __cxa_guard_release(__guard *g)
{
*g = 1;
}
void __cxa_guard_abort(__guard *)
{
}
void __cxa_pure_virtual()
{
while (1)
{
}
}
// some functions in cmath follow the compiler flag -fno-math-errno
// but not so for std::pow...
void __errno() {
}
}

10
core/src/std.cpp Normal file
View file

@ -0,0 +1,10 @@
namespace std
{
void __throw_bad_function_call()
{
}
void __throw_out_of_range_fmt(char const *, ...)
{
}
} // namespace std