Fix Arduino progmem print, AVR WOLFSSL_USER_IO

pull/8668/head
gojimmypi 2025-04-18 14:29:32 +02:00
parent 1b240e2cbc
commit 1f88ab58c1
No known key found for this signature in database
GPG Key ID: 3D684FA88DC3FAA8
4 changed files with 38 additions and 1 deletions

View File

@ -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 <avr/pgmspace.h> /* 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<uint16_t>(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;
};

View File

@ -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

View File

@ -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

View File

@ -316,6 +316,7 @@
/* board-specific */
#if defined(__AVR__)
#define WOLFSSL_USER_IO
#define WOLFSSL_NO_SOCK
#define NO_WRITEV
#elif defined(__arm__)