Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
ff2b084
chore: remove hardcoded CROSS_COMPILE path
AndyEveritt Apr 3, 2026
f47b885
Merge remote-tracking branch 'origin/3.7-dev' into 3.7-docker
AndyEveritt Apr 28, 2026
8b7568d
Merge remote-tracking branch 'origin/3.7-dev' into 3.7-docker
AndyEveritt Jun 2, 2026
9b93155
Merge remote-tracking branch 'origin/3.7-dev' into 3.7-docker
AndyEveritt Jun 2, 2026
2d8c615
fix: use correct compiler debug flags
AndyEveritt Jun 2, 2026
810b494
Merge remote-tracking branch 'origin/3.7-dev' into 3.7-docker
AndyEveritt Jun 17, 2026
385609d
Merge branch '3.7-dev' into 3.7-docker
AndyEveritt Jul 9, 2026
854d2f6
chore: add cmake script
AndyEveritt Jul 22, 2026
d3d272a
fix: cmake feature flag
AndyEveritt Jul 22, 2026
9de9f35
fix: `misc-unused-parameters`
AndyEveritt Jul 23, 2026
f8c4f56
chore: fix clang-tidy warnings `cppcoreguidelines-c-copy-assignment-s…
AndyEveritt Jul 23, 2026
a182198
Revert "chore: fix clang-tidy warnings `cppcoreguidelines-c-copy-assi…
AndyEveritt Jul 24, 2026
c88aa53
chore: fix clang-tidy warnings again
AndyEveritt Jul 28, 2026
897c97f
chore: allow compilation for linux target
AndyEveritt Jul 28, 2026
384e06d
Merge remote-tracking branch 'origin/3.7-dev' into 3.7-docker
AndyEveritt Aug 19, 2026
d6be126
Merge remote-tracking branch 'origin/3.7-dev' into 3.7-docker
AndyEveritt Sep 3, 2026
53107ea
chore: standardise compiler debug flags
AndyEveritt Sep 3, 2026
05334b7
fix: restore -O2 optimisation
AndyEveritt Sep 4, 2026
f921add
fix: restore -O2 flag for STM
AndyEveritt Sep 4, 2026
35a2458
chore: hardcode toolchain path for none legacy compatibility
AndyEveritt Sep 7, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
# RRFLibraries Master Makefile
# Builds RRFLibraries for various MCU configurations

# Cross-compiler toolchain (relative to project root)
#CROSS_COMPILE ?= ../arm-gnu-toolchain-13.2.Rel1-x86_64-arm-none-eabi/bin/arm-none-eabi-
CROSS_COMPILE ?= ../arm-gnu-toolchain-15.2.rel1-x86_64-arm-none-eabi/bin/arm-none-eabi-
# Cross-compiler toolchain.
# RepRapFirmware exports CROSS_COMPILE when building this as a submodule.
# When building RRFLibraries standalone, fall back to a toolchain on PATH.
ARM_GNU_TOOLCHAIN_VERSION ?= 15.2.rel1
HOST_ARCH_RAW := $(shell uname -m)

ifeq ($(HOST_ARCH_RAW),aarch64)
ARM_GNU_TOOLCHAIN_HOST_ARCH := aarch64
else ifeq ($(HOST_ARCH_RAW),arm64)
ARM_GNU_TOOLCHAIN_HOST_ARCH := aarch64
else ifeq ($(HOST_ARCH_RAW),x86_64)
ARM_GNU_TOOLCHAIN_HOST_ARCH := x86_64
else ifeq ($(HOST_ARCH_RAW),amd64)
ARM_GNU_TOOLCHAIN_HOST_ARCH := x86_64
else
ARM_GNU_TOOLCHAIN_HOST_ARCH := $(HOST_ARCH_RAW)
endif

CROSS_COMPILE ?= $(abspath ../arm-gnu-toolchain-$(ARM_GNU_TOOLCHAIN_VERSION)-$(ARM_GNU_TOOLCHAIN_HOST_ARCH)-arm-none-eabi/bin/arm-none-eabi-)
export CROSS_COMPILE

# Toolchain commands
Expand Down
2 changes: 2 additions & 0 deletions Makefiles/RP2040_RTOS.mk
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ CXXFLAGS := -c -std=c++20 \
$(INCLUDES) \
$(DEFINES)

CXXFLAGS += $(DEBUG_FLAGS)

OBJS := $(CPP_SRCS:%.cpp=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)

Expand Down
2 changes: 2 additions & 0 deletions Makefiles/SAMC21.mk
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ CXXFLAGS := -c -std=c++20 \
$(INCLUDES) \
$(DEFINES)

CXXFLAGS += $(DEBUG_FLAGS)

OBJS := $(CPP_SRCS:%.cpp=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)

Expand Down
2 changes: 2 additions & 0 deletions Makefiles/SAMC21_RTOS.mk
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ CXXFLAGS := -c -std=c++20 \
$(INCLUDES) \
$(DEFINES)

CXXFLAGS += $(DEBUG_FLAGS)

OBJS := $(CPP_SRCS:%.cpp=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)

Expand Down
2 changes: 2 additions & 0 deletions Makefiles/SAME51.mk
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ CXXFLAGS := -c -std=c++20 \
$(INCLUDES) \
$(DEFINES)

CXXFLAGS += $(DEBUG_FLAGS)

OBJS := $(CPP_SRCS:%.cpp=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)

Expand Down
8 changes: 2 additions & 6 deletions Makefiles/SAME51_RTOS.mk
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,11 @@ SAME51_RTOS_CXXFLAGS := -c -std=c++20 \
-fstack-usage \
-fdump-rtl-expand \
-Wall \
-O2 \
$(SAME51_RTOS_INCLUDES) \
$(SAME51_RTOS_DEFINES)

# Add debug flags if DEBUG=1
ifeq ($(DEBUG),1)
SAME51_RTOS_CXXFLAGS += -O0 -g3
else
SAME51_RTOS_CXXFLAGS += -O2

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is -O2 removed by default?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is accidental. Will fix

endif
SAME51_RTOS_CXXFLAGS += $(DEBUG_FLAGS)

SAME51_RTOS_OBJS := $(SAME51_RTOS_CPP_SRCS:%.cpp=$(SAME51_RTOS_BUILD_DIR)/%.o)
SAME51_RTOS_DEPS := $(SAME51_RTOS_OBJS:.o=.d)
Expand Down
8 changes: 2 additions & 6 deletions Makefiles/SAME70.mk
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,11 @@ SAME70_CXXFLAGS := -c -std=c++20 \
-Wdouble-promotion \
-Werror -Wnoexcept -Wshadow -Wsign-promo \
-fsingle-precision-constant \
-Os \
$(SAME70_INCLUDES) \
$(SAME70_DEFINES)

# Add debug flags if DEBUG=1
ifeq ($(DEBUG),1)
SAME70_CXXFLAGS += -O0 -g3
else
SAME70_CXXFLAGS += -Os
Comment thread
AndyEveritt marked this conversation as resolved.
Resolved
endif
SAME70_CXXFLAGS += $(DEBUG_FLAGS)

SAME70_OBJS := $(SAME70_CPP_SRCS:%.cpp=$(SAME70_BUILD_DIR)/%.o)
SAME70_DEPS := $(SAME70_OBJS:.o=.d)
Expand Down
2 changes: 2 additions & 0 deletions Makefiles/SAME70_RTOS.mk
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ SAME70_RTOS_CXXFLAGS := -c -std=c++20 \
$(SAME70_RTOS_INCLUDES) \
$(SAME70_RTOS_DEFINES)

SAME70_RTOS_CXXFLAGS += $(DEBUG_FLAGS)

SAME70_RTOS_OBJS := $(SAME70_RTOS_CPP_SRCS:%.cpp=$(SAME70_RTOS_BUILD_DIR)/%.o)
SAME70_RTOS_DEPS := $(SAME70_RTOS_OBJS:.o=.d)

Expand Down
8 changes: 2 additions & 6 deletions Makefiles/STM32H5_RTOS.mk
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,11 @@ STM32H5_RTOS_CXXFLAGS := -c -std=c++20 \
-fstack-usage \
-fdump-rtl-expand \
-Wall \
-O2 \
$(STM32H5_RTOS_INCLUDES) \
$(STM32H5_RTOS_DEFINES)

# Add debug flags if DEBUG=1
ifeq ($(DEBUG),1)
STM32H5_RTOS_CXXFLAGS += -O0 -g3
else
STM32H5_RTOS_CXXFLAGS += -O2
endif
STM32H5_RTOS_CXXFLAGS += $(DEBUG_FLAGS)

STM32H5_RTOS_OBJS := $(STM32H5_RTOS_CPP_SRCS:%.cpp=$(STM32H5_RTOS_BUILD_DIR)/%.o)
STM32H5_RTOS_DEPS := $(STM32H5_RTOS_OBJS:.o=.d)
Expand Down
8 changes: 2 additions & 6 deletions Makefiles/STM32H7_RTOS.mk
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,11 @@ STM32H7_RTOS_CXXFLAGS := -c -std=c++20 \
-fstack-usage \
-fdump-rtl-expand \
-Wall \
-O2 \
$(STM32H7_RTOS_INCLUDES) \
$(STM32H7_RTOS_DEFINES)

# Add debug flags if DEBUG=1
ifeq ($(DEBUG),1)
STM32H7_RTOS_CXXFLAGS += -O0 -g3
else
STM32H7_RTOS_CXXFLAGS += -O2
endif
STM32H7_RTOS_CXXFLAGS += $(DEBUG_FLAGS)

STM32H7_RTOS_OBJS := $(STM32H7_RTOS_CPP_SRCS:%.cpp=$(STM32H7_RTOS_BUILD_DIR)/%.o)
STM32H7_RTOS_DEPS := $(STM32H7_RTOS_OBJS:.o=.d)
Expand Down
139 changes: 139 additions & 0 deletions RRFLibraries.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
# RRFLibraries as a reusable CMake component. See lib/FreeRTOS/FreeRTOS.cmake for the rationale
# behind the include()-a-module-and-call-a-function pattern.
#
# rrflibraries_add_library(
# TARGET <name>
# MCU <SAME70|SAME51|SAMC21|HOST>
# ARCH <interface target>
# [RTOS] # build the RTOS variant (adds -DRTOS and the FreeRTOS include paths)
# [EXTRA_COMPILE_OPTIONS <opts...>]
# )
#
# MCU HOST builds for an ordinary hosted target (Linux) rather than a Duet MCU. It exists for the
# SBC-side code, which reuses the portable parts of this library - Bitmap, StringRef, SimpleMath,
# Isqrt and the eCv annotation headers - and must not pull in anything freestanding. Differences
# from an MCU build:
# - RTOSIface/ is excluded; it needs FreeRTOS, and a hosted consumer brings its own threading.
# - the freestanding-only compile options (-nostdlib, -fsingle-precision-constant) are dropped,
# as is -Werror: this is upstream source built for a target it was not written for, so a new
# warning here must not break a downstream project's build.
# - the objects are position-independent, because they get linked into a shared library.
#
# EXTRA_COMPILE_OPTIONS is for options the consumer must impose on this library's own translation
# units, not just on its usage requirements - a forced include being the motivating case (see
# float16_t in DuetSbcInterface/src/Compat).

set(RRFLIBRARIES_DIR "${CMAKE_CURRENT_LIST_DIR}")
set(RRFLIBRARIES_LIBRARY_FLAGS
"RTOS"
)
set(RRFLIBRARIES_LIBRARY_ARGS
"FREERTOS_INTERFACE" # interface target for FreeRTOS, if RTOS is enabled
)
set(RRFLIBRARIES_LIBRARY_MULTI_ARGS
"EXTRA_COMPILE_OPTIONS" # options applied to this library's own sources
)

include("${LIBRARIES_DIR}/LibraryUtils.cmake")

function(rrflibraries_add_interface OUT_TARGET)
cmake_parse_arguments(PARSE_ARGV 1 ARG "${RRFLIBRARIES_LIBRARY_FLAGS}" "${DEFAULT_INTERFACE_ARGS}" "")
if(ARG_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "rrflibraries_add_interface: unknown arguments: ${ARG_UNPARSED_ARGUMENTS}")
endif()

get_enabled_features(_enabled_features ${RRFLIBRARIES_LIBRARY_FLAGS})
make_library_name(_target "RRFLibraries" INTERFACE ${ARG_MCU} ${_enabled_features})
set(${OUT_TARGET} "${_target}" PARENT_SCOPE)
if(TARGET ${_target})
return() # already built for this MCU and feature set
endif()

add_library(${_target} INTERFACE)
target_include_directories(${_target} INTERFACE "${RRFLIBRARIES_DIR}/src")
endfunction()

function(rrflibraries_add_library OUT_TARGET)
cmake_parse_arguments(PARSE_ARGV 1 ARG "${RRFLIBRARIES_LIBRARY_FLAGS}" "${DEFAULT_LIBRARY_ARGS};${RRFLIBRARIES_LIBRARY_ARGS}" "${RRFLIBRARIES_LIBRARY_MULTI_ARGS}")
if(ARG_UNPARSED_ARGUMENTS)
message(FATAL_ERROR "rrflibraries_add_library: unknown arguments: ${ARG_UNPARSED_ARGUMENTS}")
endif()

get_enabled_features(_enabled_features ${RRFLIBRARIES_LIBRARY_FLAGS})
make_library_name(_target "RRFLibraries" STATIC ${ARG_MCU} ${_enabled_features})
set(${OUT_TARGET} "${_target}" PARENT_SCOPE)
if(TARGET ${_target})
return() # already built for this MCU and feature set
endif()

set(_src "${RRFLIBRARIES_DIR}/src")
set(_freertos "${RRFLIBRARIES_DIR}/../FreeRTOS/src")

if(ARG_MCU STREQUAL "HOST")
# RTOSIface is the FreeRTOS shim; a hosted consumer supplies its own synchronisation.
set(_excludes "/RP2040/" "/SAME5x_C21/" "/RTOSIface/")
elseif(ARG_MCU STREQUAL "SAME70")
set(_excludes "/RP2040/" "/SAME5x_C21/")
elseif(ARG_MCU STREQUAL "SAME51")
set(_excludes "/RP2040/")
elseif(ARG_MCU STREQUAL "SAMC21")
set(_excludes "/RP2040/")
else()
message(FATAL_ERROR "rrflibraries_add_library: unsupported MCU '${ARG_MCU}'")
endif()

file(GLOB_RECURSE _srcs CONFIGURE_DEPENDS "${_src}/*.cpp")
foreach(_ex IN LISTS _excludes)
list(FILTER _srcs EXCLUDE REGEX "${_ex}")
endforeach()

add_library(${_target} STATIC ${_srcs})

target_link_libraries(${_target} PUBLIC I_${_target}) # link own interface target

if(ARG_RTOS)
target_link_libraries(${_target} PRIVATE ${ARG_FREERTOS_INTERFACE})
endif()

# Options that only make sense freestanding, or that turn an upstream warning into a downstream
# build failure. A HOST build is this source compiled for a target it was not written for, so it
# opts out of both groups.
#
# -fsingle-precision-constant is deliberately NOT in this group: it decides whether a literal
# like 0.0 is float or double, so dropping it would silently change the results of the motion
# maths relative to the firmware. It stays PRIVATE to this library's own sources either way.
set(_freestanding_options
-nostdlib
-Werror)
if(ARG_MCU STREQUAL "HOST")
set(_freestanding_options)
# C++20 for this library's own sources (SafeVsnprintf.cpp uses std::bit_cast), which is what
# the firmware projects already compile it as. PRIVATE, so a C++17 consumer stays C++17 -
# nothing in the headers needs more than C++17.
set_target_properties(${_target} PROPERTIES
POSITION_INDEPENDENT_CODE ON
CXX_STANDARD 20
CXX_STANDARD_REQUIRED ON)
endif()

target_compile_options(${_target} PRIVATE
-ffunction-sections
-fdata-sections
-fno-threadsafe-statics
-fno-rtti
-fno-exceptions
-Wall
-Wundef
-Wdouble-promotion
-Werror=return-type
-Wnoexcept
-Wshadow
-Wsign-promo
-fsingle-precision-constant
${_freestanding_options}
${ARG_EXTRA_COMPILE_OPTIONS}
$<$<NOT:$<CONFIG:Debug>>:-O2>
$<$<CONFIG:Debug>:-Og;-g3>)

target_link_libraries(${_target} PRIVATE ${ARG_ARCH})
endfunction()
2 changes: 1 addition & 1 deletion src/General/FreelistManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ namespace FreelistManager

// Call this macro within a class public section to use freelist new and delete
#define DECLARE_FREELIST_NEW_DELETE(_Type) \
void* operator new(size_t sz) noexcept { return FreelistManager::Allocate<_Type>(); } \
void* operator new(size_t /* sz */) noexcept { return FreelistManager::Allocate<_Type>(); } \
void operator delete(void* p) noexcept { FreelistManager::Release<_Type>(p); }

#endif /* SRC_LIBRARIES_GENERAL_FREELISTMANAGER_H_ */
15 changes: 10 additions & 5 deletions src/General/NamedEnum.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,22 @@ static inline constexpr c_string SkipLeadingUnderscore(c_string s) noexcept
// If any of the names is a C++ reserved word or starts with a digit, prefix it with a single underscore
// BaseType must be unsigned for IsValid and ToString to work correctly.

// TODO: determine if these linting checks are false positives or not
// NOLINTBEGIN(cppcoreguidelines-c-copy-assignment-signature,misc-unconventional-assign-operator,performance-unnecessary-value-param,cppcoreguidelines-special-member-functions)
#define NamedEnum(_typename, _baseType, _v1, ...) \
static_assert((_baseType)0 < (_baseType)-1, "base type must be unsigned"); \
class _typename final { \
public: \
typedef _baseType BaseType; /* alias for the base type */ \
enum RawType : BaseType { _v1 = 0, __VA_ARGS__ }; /* underlying enumeration */ \
static constexpr unsigned int NumValues = VA_SIZE(__VA_ARGS__) + 1; /* count of members */ \
_typename(RawType arg) noexcept { v = arg; } /* constructor - cannot be declared 'explicit' because we need the conversion */ \
explicit _typename(BaseType arg) noexcept { v = static_cast<RawType>(arg); } /* constructor */ \
explicit _typename(c_string s) noexcept { v = static_cast<RawType>(NamedEnumLookup(s, _names, NumValues)); } /* constructor from string */ \
_typename(const _typename& arg) noexcept { v = arg.v; } /* copy constructor */ \
_typename(const volatile _typename& arg) noexcept { v = arg.v; } /* copy constructor */ \
_typename(RawType arg) noexcept : v(arg) {} /* constructor - cannot be declared 'explicit' because we need the conversion */ \
explicit _typename(BaseType arg) noexcept : v(static_cast<RawType>(arg)) {} /* constructor */ \
explicit _typename(c_string s) noexcept : v(static_cast<RawType>(NamedEnumLookup(s, _names, NumValues))) {} /* constructor from string */ \
_typename(const _typename& arg) noexcept : v(arg.v) {} /* copy constructor */ \
_typename(const volatile _typename& arg) noexcept : v(arg.v) {} /* copy constructor */ \
_typename(_typename&& arg) noexcept : v(arg.v) {} /* move constructor */ \
~_typename() = default; /* destructor */ \
bool operator==(_typename arg) const noexcept { return v == arg.v; } /* equality operator */ \
bool operator!=(_typename arg) const noexcept { return v != arg.v; } /* inequality operator */ \
bool operator>(_typename arg) const noexcept { return v > arg.v; } /* greater-than operator */ \
Expand Down Expand Up @@ -133,5 +137,6 @@ private: \
RawType v; \
static constexpr c_string _names[NumValues] = { STRINGLIST(_v1, __VA_ARGS__) }; \
}
// NOLINTEND(cppcoreguidelines-c-copy-assignment-signature,misc-unconventional-assign-operator,performance-unnecessary-value-param,cppcoreguidelines-special-member-functions)

#endif /* SRC_NAMEDENUM_H_ */
4 changes: 3 additions & 1 deletion src/General/SimpleMath.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ inline unsigned int LowestSetBitNumber(unsigned int val) noexcept
return (unsigned int)__builtin_ctz(val);
}

static_assert(sizeof(uint32_t) == sizeof(unsigned long));
// Each overload forwards to the builtin for its own parameter type, so the set is correct whether
// uint32_t/uint64_t map onto unsigned long (ILP32, every Duet MCU) or not (LP64 hosts).
static_assert(sizeof(unsigned long) >= sizeof(uint32_t));
inline unsigned int LowestSetBitNumber(unsigned long val) noexcept
{
return (unsigned int)__builtin_ctzl(val);
Expand Down
Loading