Skip to content

Commit da23c86

Browse files
committed
Fix Arduino progmem print, AVR WOLFSSL_USER_IO
1 parent b38ab8a commit da23c86

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

IDE/ARDUINO/wolfssl-arduino.cpp

+26-3
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,35 @@
2222
#include <Arduino.h>
2323
#include "wolfssl.h"
2424

25-
/* Function to allow wolfcrypt to use Arduino Serial.print for debug messages.
26-
* See wolfssl/wolfcrypt/logging.c */
25+
/* Function to allow wolfcrypt to use Arduino Serial.print for debug messages.
26+
* See wolfssl/wolfcrypt/logging.c */
27+
28+
#if defined(__AVR__)
29+
#include <avr/pgmspace.h> /* Required for PROGMEM handling on AVR */
30+
#endif
2731

2832
int wolfSSL_Arduino_Serial_Print(const char* const s)
2933
{
3034
/* Reminder: Serial.print is only available in C++ */
31-
Serial.println(F(s));
35+
int is_progmem = 0;
36+
const char* t;
37+
t = s;
38+
39+
#if defined(__AVR__)
40+
/* Safely check if `s` is in PROGMEM, 0x8000 is typical for AVR flash */
41+
if (reinterpret_cast<uint16_t>(t) >= 0x8000) {
42+
while (pgm_read_byte(t)) {
43+
Serial.write(pgm_read_byte(t++));
44+
}
45+
Serial.println();
46+
is_progmem = 1;
47+
}
48+
#endif
49+
50+
/* Print normally for non-AVR boards or RAM-stored strings */
51+
if (!is_progmem) {
52+
Serial.println(s);
53+
}
54+
3255
return 0;
3356
};

wolfssl/wolfcrypt/settings.h

+1
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@
316316

317317
/* board-specific */
318318
#if defined(__AVR__)
319+
#define WOLFSSL_USER_IO
319320
#define WOLFSSL_NO_SOCK
320321
#define NO_WRITEV
321322
#elif defined(__arm__)

0 commit comments

Comments
 (0)