From 1f88ab58c1256defbdf02764b80f43288527ad28 Mon Sep 17 00:00:00 2001 From: gojimmypi Date: Fri, 18 Apr 2025 14:29:32 +0200 Subject: [PATCH] Fix Arduino progmem print, AVR WOLFSSL_USER_IO --- IDE/ARDUINO/wolfssl-arduino.cpp | 26 +++++++++++++++++++++++- IDE/ARDUINO/wolfssl-arduino.sh | 8 ++++++++ examples/configs/user_settings_arduino.h | 4 ++++ wolfssl/wolfcrypt/settings.h | 1 + 4 files changed, 38 insertions(+), 1 deletion(-) diff --git a/IDE/ARDUINO/wolfssl-arduino.cpp b/IDE/ARDUINO/wolfssl-arduino.cpp index 3d3c78735..19c50a684 100644 --- a/IDE/ARDUINO/wolfssl-arduino.cpp +++ b/IDE/ARDUINO/wolfssl-arduino.cpp @@ -25,9 +25,33 @@ /* Function to allow wolfcrypt to use Arduino Serial.print for debug messages. * See wolfssl/wolfcrypt/logging.c */ +#if defined(__AVR__) +#include /* Required for PROGMEM handling on AVR */ +#endif + int wolfSSL_Arduino_Serial_Print(const char* const s) { /* Reminder: Serial.print is only available in C++ */ - Serial.println(F(s)); + int is_progmem = 0; + +#if defined(__AVR__) + const char* t; + t = s; + + /* Safely check if `s` is in PROGMEM, 0x8000 is typical for AVR flash */ + if (reinterpret_cast(t) >= 0x8000) { + while (pgm_read_byte(t)) { + Serial.write(pgm_read_byte(t++)); + } + Serial.println(); + is_progmem = 1; + } +#endif + + /* Print normally for non-AVR boards or RAM-stored strings */ + if (!is_progmem) { + Serial.println(s); + } + return 0; }; diff --git a/IDE/ARDUINO/wolfssl-arduino.sh b/IDE/ARDUINO/wolfssl-arduino.sh index 0b9a3f32d..d05a84802 100755 --- a/IDE/ARDUINO/wolfssl-arduino.sh +++ b/IDE/ARDUINO/wolfssl-arduino.sh @@ -262,6 +262,11 @@ if [ "$THIS_DIR" = "ARDUINO" ]; then # Copy examples mkdir -p ".${ROOT_SRC_DIR}"/examples + EXAMPLES_DIR_REAL_PATH=$(realpath ".${EXAMPLES_DIR}") + echo "Source WOLFSSL_EXAMPLES_ROOT=$WOLFSSL_EXAMPLES_ROOT" + echo "Destination EXAMPLES_DIR=.${EXAMPLES_DIR}" + echo "EXAMPLES_DIR_REAL_PATH=${EXAMPLES_DIR_REAL_PATH}" + if [ -n "$WOLFSSL_EXAMPLES_ROOT" ]; then echo "Copy template example...." mkdir -p ".${EXAMPLES_DIR}"/template/wolfssl_library/src @@ -294,6 +299,9 @@ if [ "$THIS_DIR" = "ARDUINO" ]; then else NO_ARDUINO_EXAMPLES=1 fi + echo "Examples copied to .${EXAMPLES_DIR}" + echo "ls ${EXAMPLES_DIR_REAL_PATH}" + ls "${EXAMPLES_DIR_REAL_PATH}" else echo "ERROR: You must be in the IDE/ARDUINO directory to run this script" exit 1 diff --git a/examples/configs/user_settings_arduino.h b/examples/configs/user_settings_arduino.h index 8ff2d8c3b..c390a2b7f 100644 --- a/examples/configs/user_settings_arduino.h +++ b/examples/configs/user_settings_arduino.h @@ -92,9 +92,13 @@ #elif defined(WOLFSSL_SERVER_EXAMPLE) #define NO_WOLFSSL_CLIENT #elif defined(WOLFSSL_TEMPLATE_EXAMPLE) + #define NO_TLS + #define WOLFCRYPT_ONLY #define NO_WOLFSSL_SERVER #define NO_WOLFSSL_CLIENT #elif defined(WOLFSSL_AES_CTR_EXAMPLE) + #define NO_TLS + #define WOLFCRYPT_ONLY #define NO_WOLFSSL_SERVER #define NO_WOLFSSL_CLIENT #define WOLFSSL_AES diff --git a/wolfssl/wolfcrypt/settings.h b/wolfssl/wolfcrypt/settings.h index 9fa7a3372..daa1bd07d 100644 --- a/wolfssl/wolfcrypt/settings.h +++ b/wolfssl/wolfcrypt/settings.h @@ -316,6 +316,7 @@ /* board-specific */ #if defined(__AVR__) + #define WOLFSSL_USER_IO #define WOLFSSL_NO_SOCK #define NO_WRITEV #elif defined(__arm__)