From bf862b89048e99a25a1484f425c72b5c15ecf3ec Mon Sep 17 00:00:00 2001 From: Aymane Bahssain Date: Mon, 12 Jan 2026 13:58:03 +0100 Subject: [PATCH 1/6] core: extend PinMode enum with INPUT_FLOATING and INPUT_ANALOG Signed-off-by: Aymane Bahssain --- Common.h | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Common.h b/Common.h index 9b28f40a..9a86cb5e 100644 --- a/Common.h +++ b/Common.h @@ -36,11 +36,14 @@ typedef enum { } PinStatus; typedef enum { - INPUT = 0x0, - OUTPUT = 0x1, - INPUT_PULLUP = 0x2, - INPUT_PULLDOWN = 0x3, - OUTPUT_OPENDRAIN = 0x4, + INPUT = 0x0, + OUTPUT = 0x1, + INPUT_PULLUP = 0x2, + INPUT_FLOATING = INPUT, + INPUT_PULLDOWN = 0x3, + OUTPUT_OPENDRAIN = 0x4, + OUTPUT_OPEN_DRAIN = OUTPUT_OPENDRAIN, + INPUT_ANALOG = 0x5, } PinMode; typedef enum { From 9b1c7e7fcabee8c542230f2cba62340c5477c553 Mon Sep 17 00:00:00 2001 From: Aymane Bahssain Date: Mon, 12 Jan 2026 13:50:42 +0100 Subject: [PATCH 2/6] feat: deprecate boolean typedef in favor of bool Ref: arduino/ArduinoCore-API#242 Signed-off-by: Aymane Bahssain --- Common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Common.h b/Common.h index 9a86cb5e..79e6984a 100644 --- a/Common.h +++ b/Common.h @@ -96,7 +96,7 @@ typedef void (*voidFuncPtrParam)(void*); #endif /* TODO: request for removal */ -typedef bool boolean; +typedef bool boolean __attribute__((deprecated)); typedef uint8_t byte; typedef uint16_t word; From 1df3863fb9c842cc7b06b97e616d13449e9530f9 Mon Sep 17 00:00:00 2001 From: Aymane Bahssain Date: Mon, 12 Jan 2026 13:51:15 +0100 Subject: [PATCH 3/6] core: declare initVariant() as weak Signed-off-by: Aymane Bahssain --- Common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Common.h b/Common.h index 79e6984a..8ccf5b0c 100644 --- a/Common.h +++ b/Common.h @@ -101,7 +101,7 @@ typedef uint8_t byte; typedef uint16_t word; void init(void); -void initVariant(void); +void initVariant(void) __attribute__((weak)); #ifndef HOST int atexit(void (*func)()) __attribute__((weak)); From e17f3acb72d6fc97bbc0877759eae1d30935e701 Mon Sep 17 00:00:00 2001 From: Aymane Bahssain Date: Mon, 12 Jan 2026 14:01:26 +0100 Subject: [PATCH 4/6] fix: update pulseIn signatures to use pin_size_t - Change pulseIn and pulseInLong prototypes from uint8_t pin to pin_size_t pin. Signed-off-by: Aymane Bahssain --- Common.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Common.h b/Common.h index 8ccf5b0c..4e881f8e 100644 --- a/Common.h +++ b/Common.h @@ -178,8 +178,8 @@ uint16_t makeWord(byte h, byte l); #define word(...) makeWord(__VA_ARGS__) -unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); -unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); +unsigned long pulseIn(pin_size_t pin, uint8_t state, unsigned long timeout = 1000000L); +unsigned long pulseInLong(pin_size_t pin, uint8_t state, unsigned long timeout = 1000000L); void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0); void noTone(uint8_t _pin); From 83d33bae94881d77960812e6bbd570759eae39d0 Mon Sep 17 00:00:00 2001 From: Aymane Bahssain Date: Tue, 13 Jan 2026 10:07:14 +0100 Subject: [PATCH 5/6] feat: enhance Print class with float support and printf functionality - Add float overloads to Print::print/println - Enhance Print with printf() and vprintf() helpers Signed-off-by: Aymane Bahssain --- Print.cpp | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ Print.h | 8 ++++++ 2 files changed, 82 insertions(+) diff --git a/Print.cpp b/Print.cpp index 4a6e942a..54319f17 100644 --- a/Print.cpp +++ b/Print.cpp @@ -24,6 +24,14 @@ #include "Print.h" +#ifdef ARDUINO_ARCH_STM32 +#include +#include "uart.h" +#if defined (VIRTIO_LOG) + #include "virtio_log.h" +#endif +#endif + using namespace arduino; // Public Methods ////////////////////////////////////////////////////////////// @@ -130,6 +138,11 @@ size_t Print::print(unsigned long long n, int base) else return printULLNumber(n, base); } +size_t Print::print(float n, int digits) +{ + return printFloat(n, digits); +} + size_t Print::print(double n, int digits) { return printFloat(n, digits); @@ -222,6 +235,13 @@ size_t Print::println(unsigned long long num, int base) return n; } +size_t Print::println(float num, int digits) +{ + size_t n = print(num, digits); + n += println(); + return n; +} + size_t Print::println(double num, int digits) { size_t n = print(num, digits); @@ -236,6 +256,60 @@ size_t Print::println(const Printable& x) return n; } +#ifdef ARDUINO_ARCH_STM32 +extern "C" { + __attribute__((weak)) + int _write(int file, char *ptr, int len) + { + switch (file) { + case STDOUT_FILENO: + case STDERR_FILENO: + /* Used for core_debug() */ +#if defined (VIRTIO_LOG) + virtio_log((uint8_t *)ptr, (uint32_t)len); +#elif defined(HAL_UART_MODULE_ENABLED) && !defined(HAL_UART_MODULE_ONLY) + uart_debug_write((uint8_t *)ptr, (uint32_t)len); +#endif + break; + case STDIN_FILENO: + break; + default: + ((class Print *)file)->write((uint8_t *)ptr, len); + break; + } + return len; + } +} +#endif + +int Print::printf(const char *format, ...) +{ + va_list ap; + va_start(ap, format); + int retval = vdprintf((int)this, format, ap); + va_end(ap); + return retval; +} + +int Print::printf(const __FlashStringHelper *format, ...) +{ + va_list ap; + va_start(ap, format); + int retval = vdprintf((int)this, (const char *)format, ap); + va_end(ap); + return retval; +} + +int Print::vprintf(const char *format, va_list ap) +{ + return vdprintf((int)this, format, ap); +} + +int Print::vprintf(const __FlashStringHelper *format, va_list ap) +{ + return vdprintf((int)this, (const char *)format, ap); +} + // Private Methods ///////////////////////////////////////////////////////////// size_t Print::printNumber(unsigned long n, uint8_t base) diff --git a/Print.h b/Print.h index 2016d7d5..0782b8ee 100644 --- a/Print.h +++ b/Print.h @@ -21,6 +21,7 @@ #include #include // for size_t +#include // for printf #include "String.h" #include "Printable.h" @@ -72,6 +73,7 @@ class Print size_t print(unsigned long, int = DEC); size_t print(long long, int = DEC); size_t print(unsigned long long, int = DEC); + size_t print(float, int = 2); size_t print(double, int = 2); size_t print(const Printable&); @@ -86,10 +88,16 @@ class Print size_t println(unsigned long, int = DEC); size_t println(long long, int = DEC); size_t println(unsigned long long, int = DEC); + size_t println(float, int = 2); size_t println(double, int = 2); size_t println(const Printable&); size_t println(void); + int printf(const char *format, ...); + int printf(const __FlashStringHelper *format, ...); + int vprintf(const __FlashStringHelper *format, va_list ap); + int vprintf(const char *format, va_list ap); + virtual void flush() { /* Empty implementation for backward compatibility */ } }; From 4ebb2e690b14adf9c034431c734293c8a51196e4 Mon Sep 17 00:00:00 2001 From: Aymane Bahssain Date: Wed, 21 Jan 2026 09:52:20 +0100 Subject: [PATCH 6/6] feat(spi): make SPISettings constructors constexpr SPISettings was originally implemented with init_AlwaysInline / init_MightInline helpers, using runtime initialization only. This change: - removes init_AlwaysInline / init_MightInline helpers, - replaces them with constexpr constructors that directly initialize the members, - keeps the existing API surface refs: stm32duino/Arduino_Core_STM32#2204 stm32duino/Arduino_Core_STM32#2201 --- HardwareSPI.h | 47 ++++++++++++++++++----------------------------- 1 file changed, 18 insertions(+), 29 deletions(-) diff --git a/HardwareSPI.h b/HardwareSPI.h index 6be2b927..70a1d435 100644 --- a/HardwareSPI.h +++ b/HardwareSPI.h @@ -45,24 +45,25 @@ typedef enum { class SPISettings { public: - SPISettings(uint32_t clock, BitOrder bitOrder, SPIMode dataMode, SPIBusMode busMode = SPI_CONTROLLER) { - if (__builtin_constant_p(clock)) { - init_AlwaysInline(clock, bitOrder, dataMode, busMode); - } else { - init_MightInline(clock, bitOrder, dataMode, busMode); - } - } - - SPISettings(uint32_t clock, BitOrder bitOrder, int dataMode, SPIBusMode busMode = SPI_CONTROLLER) { - if (__builtin_constant_p(clock)) { - init_AlwaysInline(clock, bitOrder, (SPIMode)dataMode, busMode); - } else { - init_MightInline(clock, bitOrder, (SPIMode)dataMode, busMode); - } - } - + constexpr SPISettings(uint32_t clock, BitOrder bitOrder, SPIMode dataMode, SPIBusMode busMode = SPI_CONTROLLER) + : clockFreq(clock), + dataMode(dataMode), + bitOrder(bitOrder), + busMode(busMode) + { } + constexpr SPISettings(uint32_t clock, BitOrder bitOrder, int dataMode, SPIBusMode busMode = SPI_CONTROLLER) + : clockFreq(clock), + dataMode((SPIMode)dataMode), + bitOrder(bitOrder), + busMode(busMode) + { } // Default speed set to 4MHz, SPI mode set to MODE 0 and Bit order set to MSB first. - SPISettings() { init_AlwaysInline(4000000, MSBFIRST, SPI_MODE0, SPI_CONTROLLER); } + constexpr SPISettings() + : clockFreq(4000000), + dataMode(SPI_MODE0), + bitOrder(MSBFIRST), + busMode(SPI_CONTROLLER) + { } bool operator==(const SPISettings& rhs) const { @@ -94,18 +95,6 @@ class SPISettings { } private: - void init_MightInline(uint32_t clock, BitOrder bitOrder, SPIMode dataMode, SPIBusMode busMode) { - init_AlwaysInline(clock, bitOrder, dataMode, busMode); - } - - // Core developer MUST use an helper function in beginTransaction() to use this data - void init_AlwaysInline(uint32_t clock, BitOrder bitOrder, SPIMode dataMode, SPIBusMode busMode) __attribute__((__always_inline__)) { - this->clockFreq = clock; - this->dataMode = dataMode; - this->bitOrder = bitOrder; - this->busMode = busMode; - } - uint32_t clockFreq; SPIMode dataMode; BitOrder bitOrder;