From ff2b084d5f44c47a95abf3c30986b110840274d0 Mon Sep 17 00:00:00 2001 From: AndyEveritt <38423143+AndyEveritt@users.noreply.github.com> Date: Fri, 3 Apr 2026 09:44:39 +0000 Subject: [PATCH 01/13] chore: remove hardcoded CROSS_COMPILE path --- Makefile | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 8bec645..2141be6 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,10 @@ # 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. +CROSS_COMPILE ?= arm-none-eabi- export CROSS_COMPILE # Toolchain commands From 2d8c615b2ef3a1c472867b568def5720294540ab Mon Sep 17 00:00:00 2001 From: AndyEveritt <38423143+AndyEveritt@users.noreply.github.com> Date: Tue, 2 Jun 2026 17:17:38 +0000 Subject: [PATCH 02/13] fix: use correct compiler debug flags --- Makefiles/SAM4E.mk | 8 ++------ Makefiles/SAM4E_RTOS.mk | 7 +------ Makefiles/SAM4S.mk | 8 ++------ Makefiles/SAM4S_RTOS.mk | 2 ++ Makefiles/SAMC21.mk | 2 ++ Makefiles/SAMC21_RTOS.mk | 2 ++ Makefiles/SAME51.mk | 2 ++ Makefiles/SAME51_RTOS.mk | 7 +------ Makefiles/SAME70.mk | 8 ++------ Makefiles/SAME70_RTOS.mk | 2 ++ 10 files changed, 18 insertions(+), 30 deletions(-) diff --git a/Makefiles/SAM4E.mk b/Makefiles/SAM4E.mk index 60aa79d..017f7f7 100644 --- a/Makefiles/SAM4E.mk +++ b/Makefiles/SAM4E.mk @@ -30,15 +30,11 @@ SAM4E_CXXFLAGS := -c -std=c++20 \ -Wdouble-promotion \ -Werror -Wnoexcept -Wshadow -Wsign-promo \ -fsingle-precision-constant \ + -Os \ $(SAM4E_INCLUDES) \ $(SAM4E_DEFINES) -# Add debug flags if DEBUG=1 -ifeq ($(DEBUG),1) - SAM4E_CXXFLAGS += -O0 -g3 -else - SAM4E_CXXFLAGS += -Os -endif +SAM4E_CXXFLAGS += $(DEBUG_FLAGS) SAM4E_OBJS := $(SAM4E_CPP_SRCS:%.cpp=$(SAM4E_BUILD_DIR)/%.o) SAM4E_DEPS := $(SAM4E_OBJS:.o=.d) diff --git a/Makefiles/SAM4E_RTOS.mk b/Makefiles/SAM4E_RTOS.mk index 773b2bc..a28033f 100644 --- a/Makefiles/SAM4E_RTOS.mk +++ b/Makefiles/SAM4E_RTOS.mk @@ -48,12 +48,7 @@ SAM4E_RTOS_CXXFLAGS := -c -std=c++20 \ $(SAM4E_RTOS_INCLUDES) \ $(SAM4E_RTOS_DEFINES) -# Add debug flags if DEBUG=1 -ifeq ($(DEBUG),1) -SAM4E_RTOS_CXXFLAGS += -O0 -g3 -else -SAM4E_RTOS_CXXFLAGS += -O2 -endif +SAM4E_RTOS_CXXFLAGS += $(DEBUG_FLAGS) SAM4E_RTOS_OBJS := $(SAM4E_RTOS_CPP_SRCS:%.cpp=$(BUILD_DIR)/%.o) SAM4E_RTOS_DEPS := $(SAM4E_RTOS_OBJS:.o=.d) diff --git a/Makefiles/SAM4S.mk b/Makefiles/SAM4S.mk index a728cdf..be4076c 100644 --- a/Makefiles/SAM4S.mk +++ b/Makefiles/SAM4S.mk @@ -28,15 +28,11 @@ SAM4S_CXXFLAGS := -c -std=c++20 \ -Wdouble-promotion \ -Werror -Wnoexcept -Wshadow -Wsign-promo \ -fsingle-precision-constant \ + -Os \ $(SAM4S_INCLUDES) \ $(SAM4S_DEFINES) -# Add debug flags if DEBUG=1 -ifeq ($(DEBUG),1) - SAM4S_CXXFLAGS += -O0 -g3 -else - SAM4S_CXXFLAGS += -Os -endif +SAM4S_CXXFLAGS += $(DEBUG_FLAGS) SAM4S_OBJS := $(SAM4S_CPP_SRCS:%.cpp=$(SAM4S_BUILD_DIR)/%.o) SAM4S_DEPS := $(SAM4S_OBJS:.o=.d) diff --git a/Makefiles/SAM4S_RTOS.mk b/Makefiles/SAM4S_RTOS.mk index 4144f86..1fecd1b 100644 --- a/Makefiles/SAM4S_RTOS.mk +++ b/Makefiles/SAM4S_RTOS.mk @@ -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) diff --git a/Makefiles/SAMC21.mk b/Makefiles/SAMC21.mk index 128bce7..d25b029 100644 --- a/Makefiles/SAMC21.mk +++ b/Makefiles/SAMC21.mk @@ -32,6 +32,8 @@ CXXFLAGS := -c -std=c++20 \ $(INCLUDES) \ $(DEFINES) +CXXFLAGS += $(DEBUG_FLAGS) + OBJS := $(CPP_SRCS:%.cpp=$(BUILD_DIR)/%.o) DEPS := $(OBJS:.o=.d) diff --git a/Makefiles/SAMC21_RTOS.mk b/Makefiles/SAMC21_RTOS.mk index 637284f..cba9248 100644 --- a/Makefiles/SAMC21_RTOS.mk +++ b/Makefiles/SAMC21_RTOS.mk @@ -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) diff --git a/Makefiles/SAME51.mk b/Makefiles/SAME51.mk index 794f7cf..5ef8c12 100644 --- a/Makefiles/SAME51.mk +++ b/Makefiles/SAME51.mk @@ -34,6 +34,8 @@ CXXFLAGS := -c -std=c++20 \ $(INCLUDES) \ $(DEFINES) +CXXFLAGS += $(DEBUG_FLAGS) + OBJS := $(CPP_SRCS:%.cpp=$(BUILD_DIR)/%.o) DEPS := $(OBJS:.o=.d) diff --git a/Makefiles/SAME51_RTOS.mk b/Makefiles/SAME51_RTOS.mk index 471259b..ccfff6c 100644 --- a/Makefiles/SAME51_RTOS.mk +++ b/Makefiles/SAME51_RTOS.mk @@ -39,12 +39,7 @@ SAME51_RTOS_CXXFLAGS := -c -std=c++20 \ $(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 -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) diff --git a/Makefiles/SAME70.mk b/Makefiles/SAME70.mk index c0d0617..153be42 100644 --- a/Makefiles/SAME70.mk +++ b/Makefiles/SAME70.mk @@ -31,15 +31,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 -endif +SAME70_CXXFLAGS += $(DEBUG_FLAGS) SAME70_OBJS := $(SAME70_CPP_SRCS:%.cpp=$(SAME70_BUILD_DIR)/%.o) SAME70_DEPS := $(SAME70_OBJS:.o=.d) diff --git a/Makefiles/SAME70_RTOS.mk b/Makefiles/SAME70_RTOS.mk index 6c6f045..8a15531 100644 --- a/Makefiles/SAME70_RTOS.mk +++ b/Makefiles/SAME70_RTOS.mk @@ -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) From 854d2f6b56ba8cdf9076cc4a392122d5cdfe9e23 Mon Sep 17 00:00:00 2001 From: AndyEveritt <38423143+AndyEveritt@users.noreply.github.com> Date: Wed, 22 Jul 2026 17:14:35 +0000 Subject: [PATCH 03/13] chore: add cmake script --- RRFLibraries.cmake | 97 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 RRFLibraries.cmake diff --git a/RRFLibraries.cmake b/RRFLibraries.cmake new file mode 100644 index 0000000..2811184 --- /dev/null +++ b/RRFLibraries.cmake @@ -0,0 +1,97 @@ +# 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 +# MCU +# ARCH +# [RTOS] # build the RTOS variant (adds -DRTOS and the FreeRTOS include paths) +# ) + +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 +) + +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) + 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}" "") + if(ARG_UNPARSED_ARGUMENTS) + message(FATAL_ERROR "rrflibraries_add_library: unknown arguments: ${ARG_UNPARSED_ARGUMENTS}") + endif() + + get_enabled_features(_enabled_features) + 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 "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() + + target_compile_options(${_target} PRIVATE + -ffunction-sections + -fdata-sections + -nostdlib + -fno-threadsafe-statics + -fno-rtti + -fno-exceptions + -Wall + -Wundef + -Wdouble-promotion + -Werror=return-type + -Werror + -Wnoexcept + -Wshadow + -Wsign-promo + -fsingle-precision-constant + $<$>:-O2> + $<$:-Og;-g3>) + + target_link_libraries(${_target} PRIVATE ${ARG_ARCH}) +endfunction() From d3d272a35d0586bb96109d4f37e7e4d915d2a848 Mon Sep 17 00:00:00 2001 From: AndyEveritt <38423143+AndyEveritt@users.noreply.github.com> Date: Wed, 22 Jul 2026 18:24:20 +0000 Subject: [PATCH 04/13] fix: cmake feature flag --- RRFLibraries.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RRFLibraries.cmake b/RRFLibraries.cmake index 2811184..96b1cab 100644 --- a/RRFLibraries.cmake +++ b/RRFLibraries.cmake @@ -24,7 +24,7 @@ function(rrflibraries_add_interface OUT_TARGET) message(FATAL_ERROR "rrflibraries_add_interface: unknown arguments: ${ARG_UNPARSED_ARGUMENTS}") endif() - get_enabled_features(_enabled_features) + 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}) @@ -41,7 +41,7 @@ function(rrflibraries_add_library OUT_TARGET) message(FATAL_ERROR "rrflibraries_add_library: unknown arguments: ${ARG_UNPARSED_ARGUMENTS}") endif() - get_enabled_features(_enabled_features) + 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}) From 9de9f359a3447d546cd8d4c2f4ab8733ddbfa3c5 Mon Sep 17 00:00:00 2001 From: AndyEveritt <38423143+AndyEveritt@users.noreply.github.com> Date: Thu, 23 Jul 2026 09:17:01 +0000 Subject: [PATCH 05/13] fix: `misc-unused-parameters` --- src/General/FreelistManager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/General/FreelistManager.h b/src/General/FreelistManager.h index 0793faf..aa2c9c1 100644 --- a/src/General/FreelistManager.h +++ b/src/General/FreelistManager.h @@ -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_ */ From f8c4f563b8b1b2b95384d8913766ea2fb8dab703 Mon Sep 17 00:00:00 2001 From: AndyEveritt <38423143+AndyEveritt@users.noreply.github.com> Date: Thu, 23 Jul 2026 10:29:35 +0000 Subject: [PATCH 06/13] chore: fix clang-tidy warnings `cppcoreguidelines-c-copy-assignment-signiture` `cppcoreguidelines-prefer-member-initializer`, `cppcoreguidelines-special-member-functions`, `mist-unconventional-assign-operator`, `performance-unnecessary-value-param` --- src/General/NamedEnum.h | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/General/NamedEnum.h b/src/General/NamedEnum.h index e8ae91b..5cad10b 100644 --- a/src/General/NamedEnum.h +++ b/src/General/NamedEnum.h @@ -101,27 +101,28 @@ 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(arg); } /* constructor */ \ - explicit _typename(c_string s) noexcept { v = static_cast(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 */ \ - 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 */ \ - bool operator>=(_typename arg) const noexcept { return v >= arg.v; } /* greater-than-or-equal operator */ \ - bool operator<(_typename arg) const noexcept { return v < arg.v; } /* less-than operator */ \ - bool operator<=(_typename arg) const noexcept { return v <= arg.v; } /* less-than-or-equal operator */ \ + _typename(RawType arg) noexcept : v(arg) {} /* constructor - cannot be declared 'explicit' because we need the conversion */ \ + explicit _typename(BaseType arg) noexcept : v(static_cast(arg)) {} /* constructor */ \ + explicit _typename(c_string s) noexcept : v(static_cast(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==(const _typename& arg) const noexcept { return v == arg.v; } /* equality operator */ \ + bool operator!=(const _typename& arg) const noexcept { return v != arg.v; } /* inequality operator */ \ + bool operator>(const _typename& arg) const noexcept { return v > arg.v; } /* greater-than operator */ \ + bool operator>=(const _typename& arg) const noexcept { return v >= arg.v; } /* greater-than-or-equal operator */ \ + bool operator<(const _typename& arg) const noexcept { return v < arg.v; } /* less-than operator */ \ + bool operator<=(const _typename& arg) const noexcept { return v <= arg.v; } /* less-than-or-equal operator */ \ bool operator==(RawType arg) const noexcept { return v == arg; } /* equality operator */ \ bool operator!=(RawType arg) const noexcept { return v != arg; } /* inequality operator */ \ bool operator>(RawType arg) const noexcept { return v > arg; } /* greater-than operator */ \ bool operator>=(RawType arg) const noexcept { return v >= arg; } /* greater-than-or-equal operator */ \ bool operator<(RawType arg) const noexcept { return v < arg; } /* less-than operator */ \ bool operator<=(RawType arg) const noexcept { return v <= arg; } /* less-than-or-equal operator */ \ - const _typename& operator=(RawType arg) noexcept { v = arg; return *this; } /* assignment operator from underlying enum */ \ - void operator=(RawType arg) volatile noexcept { v = arg; } /* assignment operator from underlying enum */ \ - const _typename& operator=(_typename arg) noexcept { v = arg.v; return *this; } /* copy assignment operator */ \ - void operator=(_typename arg) volatile noexcept { v = arg.v; } /* copy assignment operator */ \ + _typename& operator=(RawType arg) noexcept { v = arg; return *this; } /* assignment operator from underlying enum */ \ + _typename& operator=(const _typename& arg) noexcept { v = arg.v; return *this; } /* copy assignment operator */ \ + _typename& operator=(_typename&& arg) noexcept { v = arg.v; return *this; } /* move assignment operator */ \ constexpr RawType RawValue() const noexcept { return v; } /* return the raw enum value, which we can switch on */ \ constexpr BaseType ToBaseType() const noexcept { return static_cast(v); } /* convert to integral base type */ \ static constexpr BaseType ToBaseType(RawType arg) noexcept { return static_cast(arg); } /* convert to integral base type */ \ From a1821981304a63e195981975020ec5d9fcd86729 Mon Sep 17 00:00:00 2001 From: AndyEveritt <38423143+AndyEveritt@users.noreply.github.com> Date: Fri, 24 Jul 2026 08:28:50 +0000 Subject: [PATCH 07/13] Revert "chore: fix clang-tidy warnings `cppcoreguidelines-c-copy-assignment-signiture` `cppcoreguidelines-prefer-member-initializer`, `cppcoreguidelines-special-member-functions`, `mist-unconventional-assign-operator`, `performance-unnecessary-value-param`" This reverts commit f8c4f563b8b1b2b95384d8913766ea2fb8dab703. --- src/General/NamedEnum.h | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/General/NamedEnum.h b/src/General/NamedEnum.h index 5cad10b..e8ae91b 100644 --- a/src/General/NamedEnum.h +++ b/src/General/NamedEnum.h @@ -101,28 +101,27 @@ 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(arg)) {} /* constructor */ \ - explicit _typename(c_string s) noexcept : v(static_cast(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==(const _typename& arg) const noexcept { return v == arg.v; } /* equality operator */ \ - bool operator!=(const _typename& arg) const noexcept { return v != arg.v; } /* inequality operator */ \ - bool operator>(const _typename& arg) const noexcept { return v > arg.v; } /* greater-than operator */ \ - bool operator>=(const _typename& arg) const noexcept { return v >= arg.v; } /* greater-than-or-equal operator */ \ - bool operator<(const _typename& arg) const noexcept { return v < arg.v; } /* less-than operator */ \ - bool operator<=(const _typename& arg) const noexcept { return v <= arg.v; } /* less-than-or-equal operator */ \ + _typename(RawType arg) noexcept { v = arg; } /* constructor - cannot be declared 'explicit' because we need the conversion */ \ + explicit _typename(BaseType arg) noexcept { v = static_cast(arg); } /* constructor */ \ + explicit _typename(c_string s) noexcept { v = static_cast(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 */ \ + 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 */ \ + bool operator>=(_typename arg) const noexcept { return v >= arg.v; } /* greater-than-or-equal operator */ \ + bool operator<(_typename arg) const noexcept { return v < arg.v; } /* less-than operator */ \ + bool operator<=(_typename arg) const noexcept { return v <= arg.v; } /* less-than-or-equal operator */ \ bool operator==(RawType arg) const noexcept { return v == arg; } /* equality operator */ \ bool operator!=(RawType arg) const noexcept { return v != arg; } /* inequality operator */ \ bool operator>(RawType arg) const noexcept { return v > arg; } /* greater-than operator */ \ bool operator>=(RawType arg) const noexcept { return v >= arg; } /* greater-than-or-equal operator */ \ bool operator<(RawType arg) const noexcept { return v < arg; } /* less-than operator */ \ bool operator<=(RawType arg) const noexcept { return v <= arg; } /* less-than-or-equal operator */ \ - _typename& operator=(RawType arg) noexcept { v = arg; return *this; } /* assignment operator from underlying enum */ \ - _typename& operator=(const _typename& arg) noexcept { v = arg.v; return *this; } /* copy assignment operator */ \ - _typename& operator=(_typename&& arg) noexcept { v = arg.v; return *this; } /* move assignment operator */ \ + const _typename& operator=(RawType arg) noexcept { v = arg; return *this; } /* assignment operator from underlying enum */ \ + void operator=(RawType arg) volatile noexcept { v = arg; } /* assignment operator from underlying enum */ \ + const _typename& operator=(_typename arg) noexcept { v = arg.v; return *this; } /* copy assignment operator */ \ + void operator=(_typename arg) volatile noexcept { v = arg.v; } /* copy assignment operator */ \ constexpr RawType RawValue() const noexcept { return v; } /* return the raw enum value, which we can switch on */ \ constexpr BaseType ToBaseType() const noexcept { return static_cast(v); } /* convert to integral base type */ \ static constexpr BaseType ToBaseType(RawType arg) noexcept { return static_cast(arg); } /* convert to integral base type */ \ From c88aa53195ba5d3e8ef6356b24faffee9a185763 Mon Sep 17 00:00:00 2001 From: AndyEveritt <38423143+AndyEveritt@users.noreply.github.com> Date: Tue, 28 Jul 2026 14:15:15 +0000 Subject: [PATCH 08/13] chore: fix clang-tidy warnings again --- src/General/NamedEnum.h | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/General/NamedEnum.h b/src/General/NamedEnum.h index e8ae91b..533aeb6 100644 --- a/src/General/NamedEnum.h +++ b/src/General/NamedEnum.h @@ -94,6 +94,8 @@ 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 { \ @@ -101,11 +103,13 @@ 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(arg); } /* constructor */ \ - explicit _typename(c_string s) noexcept { v = static_cast(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(arg)) {} /* constructor */ \ + explicit _typename(c_string s) noexcept : v(static_cast(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 */ \ @@ -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_ */ From 897c97fbe1868e9d77c95dfebfbf31e6c00c2002 Mon Sep 17 00:00:00 2001 From: AndyEveritt <38423143+AndyEveritt@users.noreply.github.com> Date: Tue, 28 Jul 2026 14:16:27 +0000 Subject: [PATCH 09/13] chore: allow compilation for linux target --- RRFLibraries.cmake | 52 ++++++++++++++++++++++++++++++++++++---- src/General/SimpleMath.h | 4 +++- 2 files changed, 50 insertions(+), 6 deletions(-) diff --git a/RRFLibraries.cmake b/RRFLibraries.cmake index 96b1cab..fbe0485 100644 --- a/RRFLibraries.cmake +++ b/RRFLibraries.cmake @@ -3,10 +3,25 @@ # # rrflibraries_add_library( # TARGET -# MCU +# MCU # ARCH # [RTOS] # build the RTOS variant (adds -DRTOS and the FreeRTOS include paths) +# [EXTRA_COMPILE_OPTIONS ] # ) +# +# 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 @@ -15,6 +30,9 @@ set(RRFLIBRARIES_LIBRARY_FLAGS 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") @@ -36,7 +54,7 @@ function(rrflibraries_add_interface OUT_TARGET) endfunction() function(rrflibraries_add_library OUT_TARGET) - cmake_parse_arguments(PARSE_ARGV 1 ARG "${RRFLIBRARIES_LIBRARY_FLAGS}" "${DEFAULT_LIBRARY_ARGS};${RRFLIBRARIES_LIBRARY_ARGS}" "") + 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() @@ -51,7 +69,10 @@ function(rrflibraries_add_library OUT_TARGET) set(_src "${RRFLIBRARIES_DIR}/src") set(_freertos "${RRFLIBRARIES_DIR}/../FreeRTOS/src") - if(ARG_MCU STREQUAL "SAME70") + 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/") @@ -74,10 +95,30 @@ function(rrflibraries_add_library OUT_TARGET) 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 - -nostdlib -fno-threadsafe-statics -fno-rtti -fno-exceptions @@ -85,11 +126,12 @@ function(rrflibraries_add_library OUT_TARGET) -Wundef -Wdouble-promotion -Werror=return-type - -Werror -Wnoexcept -Wshadow -Wsign-promo -fsingle-precision-constant + ${_freestanding_options} + ${ARG_EXTRA_COMPILE_OPTIONS} $<$>:-O2> $<$:-Og;-g3>) diff --git a/src/General/SimpleMath.h b/src/General/SimpleMath.h index f5ae53a..95e08cd 100644 --- a/src/General/SimpleMath.h +++ b/src/General/SimpleMath.h @@ -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); From 53107ea951ae1e7ae16ba5dc9de7de76bbf66421 Mon Sep 17 00:00:00 2001 From: AndyEveritt <38423143+AndyEveritt@users.noreply.github.com> Date: Thu, 3 Sep 2026 11:16:43 +0000 Subject: [PATCH 10/13] chore: standardise compiler debug flags --- Makefiles/STM32H5_RTOS.mk | 7 +------ Makefiles/STM32H7_RTOS.mk | 7 +------ 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/Makefiles/STM32H5_RTOS.mk b/Makefiles/STM32H5_RTOS.mk index 5b9925e..8067c79 100644 --- a/Makefiles/STM32H5_RTOS.mk +++ b/Makefiles/STM32H5_RTOS.mk @@ -40,12 +40,7 @@ STM32H5_RTOS_CXXFLAGS := -c -std=c++20 \ $(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) diff --git a/Makefiles/STM32H7_RTOS.mk b/Makefiles/STM32H7_RTOS.mk index 8f885f8..5edab54 100644 --- a/Makefiles/STM32H7_RTOS.mk +++ b/Makefiles/STM32H7_RTOS.mk @@ -40,12 +40,7 @@ STM32H7_RTOS_CXXFLAGS := -c -std=c++20 \ $(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) From 05334b7764b5bf9e3b6ee1536a6c74b34a00299e Mon Sep 17 00:00:00 2001 From: AndyEveritt <38423143+AndyEveritt@users.noreply.github.com> Date: Fri, 4 Sep 2026 17:00:03 +0000 Subject: [PATCH 11/13] fix: restore -O2 optimisation --- Makefiles/SAME51_RTOS.mk | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefiles/SAME51_RTOS.mk b/Makefiles/SAME51_RTOS.mk index ccfff6c..b5dbd42 100644 --- a/Makefiles/SAME51_RTOS.mk +++ b/Makefiles/SAME51_RTOS.mk @@ -36,6 +36,7 @@ SAME51_RTOS_CXXFLAGS := -c -std=c++20 \ -fstack-usage \ -fdump-rtl-expand \ -Wall \ + -O2 \ $(SAME51_RTOS_INCLUDES) \ $(SAME51_RTOS_DEFINES) From f921adde3405916812383e4fce1003bb06f78708 Mon Sep 17 00:00:00 2001 From: AndyEveritt <38423143+AndyEveritt@users.noreply.github.com> Date: Fri, 4 Sep 2026 17:03:06 +0000 Subject: [PATCH 12/13] fix: restore -O2 flag for STM --- Makefiles/STM32H5_RTOS.mk | 1 + Makefiles/STM32H7_RTOS.mk | 1 + 2 files changed, 2 insertions(+) diff --git a/Makefiles/STM32H5_RTOS.mk b/Makefiles/STM32H5_RTOS.mk index 8067c79..b2f34ee 100644 --- a/Makefiles/STM32H5_RTOS.mk +++ b/Makefiles/STM32H5_RTOS.mk @@ -37,6 +37,7 @@ STM32H5_RTOS_CXXFLAGS := -c -std=c++20 \ -fstack-usage \ -fdump-rtl-expand \ -Wall \ + -O2 \ $(STM32H5_RTOS_INCLUDES) \ $(STM32H5_RTOS_DEFINES) diff --git a/Makefiles/STM32H7_RTOS.mk b/Makefiles/STM32H7_RTOS.mk index 5edab54..0a447db 100644 --- a/Makefiles/STM32H7_RTOS.mk +++ b/Makefiles/STM32H7_RTOS.mk @@ -37,6 +37,7 @@ STM32H7_RTOS_CXXFLAGS := -c -std=c++20 \ -fstack-usage \ -fdump-rtl-expand \ -Wall \ + -O2 \ $(STM32H7_RTOS_INCLUDES) \ $(STM32H7_RTOS_DEFINES) From 35a245843728af78175667715c8bcf07abef53bd Mon Sep 17 00:00:00 2001 From: AndyEveritt <38423143+AndyEveritt@users.noreply.github.com> Date: Mon, 7 Sep 2026 09:55:23 +0000 Subject: [PATCH 13/13] chore: hardcode toolchain path for none legacy compatibility --- Makefile | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 2640ace..2aafa8e 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,22 @@ # Cross-compiler toolchain. # RepRapFirmware exports CROSS_COMPILE when building this as a submodule. # When building RRFLibraries standalone, fall back to a toolchain on PATH. -CROSS_COMPILE ?= arm-none-eabi- +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