From c103450bbe027a843e101a71982d804388c301bb Mon Sep 17 00:00:00 2001 From: David Gauchard Date: Wed, 6 Feb 2019 19:01:17 +0100 Subject: [PATCH 1/3] fix DEBUG macros All fmt strings in flash fix #5658 This also allows to avoid warnings and easy mistakes with (no brace): if (something) DEBUGV("blah"); --- cores/esp8266/debug.h | 4 ++-- libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h | 2 +- libraries/ESP8266WiFi/src/ESP8266WiFi.h | 2 +- libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h | 4 ++-- libraries/ESP8266WiFi/src/ESP8266WiFiMulti.h | 4 ++-- libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cores/esp8266/debug.h b/cores/esp8266/debug.h index 0a804e76b2..3fb4d2dd54 100644 --- a/cores/esp8266/debug.h +++ b/cores/esp8266/debug.h @@ -5,11 +5,11 @@ #include #ifdef DEBUG_ESP_CORE -#define DEBUGV(...) ets_printf(__VA_ARGS__) +#define DEBUGV(fmt, ...) ::printf_P( (PGM_P)PSTR(fmt), ## __VA_ARGS__) #endif #ifndef DEBUGV -#define DEBUGV(...) +#define DEBUGV(...) do { (void)0; } while (0) #endif #ifdef __cplusplus diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h index dad3267712..912f700c16 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h @@ -42,7 +42,7 @@ #endif #ifndef DEBUG_HTTPCLIENT -#define DEBUG_HTTPCLIENT(...) +#define DEBUG_HTTPCLIENT(...) do { (void)0; } while (0) #endif #define HTTPCLIENT_DEFAULT_TCP_TIMEOUT (5000) diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFi.h b/libraries/ESP8266WiFi/src/ESP8266WiFi.h index 3bd1472069..d26e1db6bd 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFi.h +++ b/libraries/ESP8266WiFi/src/ESP8266WiFi.h @@ -50,7 +50,7 @@ extern "C" { #endif #ifndef DEBUG_WIFI -#define DEBUG_WIFI(...) +#define DEBUG_WIFI(...) do { (void)0; } while (0) #endif diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h index af3fce3e16..60fdad5785 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiGeneric.h @@ -29,12 +29,12 @@ #ifdef DEBUG_ESP_WIFI #ifdef DEBUG_ESP_PORT -#define DEBUG_WIFI_GENERIC(fmt, ...) DEBUG_ESP_PORT.printf( (PGM_P)PSTR(fmt), ##__VA_ARGS__ ) +#define DEBUG_WIFI_GENERIC(fmt, ...) DEBUG_ESP_PORT.printf_P( (PGM_P)PSTR(fmt), ##__VA_ARGS__ ) #endif #endif #ifndef DEBUG_WIFI_GENERIC -#define DEBUG_WIFI_GENERIC(...) +#define DEBUG_WIFI_GENERIC(...) do { (void)0; } while (0) #endif struct WiFiEventHandlerOpaque; diff --git a/libraries/ESP8266WiFi/src/ESP8266WiFiMulti.h b/libraries/ESP8266WiFi/src/ESP8266WiFiMulti.h index 5c616da269..9417e2ba40 100644 --- a/libraries/ESP8266WiFi/src/ESP8266WiFiMulti.h +++ b/libraries/ESP8266WiFi/src/ESP8266WiFiMulti.h @@ -32,12 +32,12 @@ #ifdef DEBUG_ESP_WIFI #ifdef DEBUG_ESP_PORT -#define DEBUG_WIFI_MULTI(fmt, ...) DEBUG_ESP_PORT.printf( (PGM_P)PSTR(fmt), ##__VA_ARGS__ ) +#define DEBUG_WIFI_MULTI(fmt, ...) DEBUG_ESP_PORT.printf_P( (PGM_P)PSTR(fmt), ##__VA_ARGS__ ) #endif #endif #ifndef DEBUG_WIFI_MULTI -#define DEBUG_WIFI_MULTI(...) +#define DEBUG_WIFI_MULTI(...) do { (void)0; } while (0) #endif struct WifiAPEntry { diff --git a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h index 2e5b140f7f..a82e4f0efd 100644 --- a/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h +++ b/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h @@ -36,12 +36,12 @@ #ifdef DEBUG_ESP_HTTP_UPDATE #ifdef DEBUG_ESP_PORT -#define DEBUG_HTTP_UPDATE(...) DEBUG_ESP_PORT.printf( __VA_ARGS__ ) +#define DEBUG_HTTP_UPDATE(fmt, ...) DEBUG_ESP_PORT.printf_P( (PGM_P)PSTR(fmt), ## __VA_ARGS__ ) #endif #endif #ifndef DEBUG_HTTP_UPDATE -#define DEBUG_HTTP_UPDATE(...) +#define DEBUG_HTTP_UPDATE(...) do { (void)0; } while(0) #endif /// note we use HTTP client errors too so we start at 100 From 8999d933b111d59d2c9be6ebda8dac90dccfe2ca Mon Sep 17 00:00:00 2001 From: david gauchard Date: Wed, 13 Mar 2019 02:16:01 +0100 Subject: [PATCH 2/3] use newlib unaligned-compatible printf for DEBUGV --- cores/esp8266/debug.cpp | 10 ++++++++++ cores/esp8266/debug.h | 4 +++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/cores/esp8266/debug.cpp b/cores/esp8266/debug.cpp index 6a99510fe6..bd036b60a0 100644 --- a/cores/esp8266/debug.cpp +++ b/cores/esp8266/debug.cpp @@ -35,3 +35,13 @@ void ICACHE_RAM_ATTR hexdump(const void *mem, uint32_t len, uint8_t cols) { os_printf("\n"); } +int putprintf (int (*put)(int), const char* fmt, ...) { + char buf[128]; + va_list ap; + va_start(ap, fmt); + int len = ::vsnprintf(buf, sizeof(buf), fmt, ap); + for (int i = 0; i < len; i++) + put(buf[i]); + va_end(ap); + return len; +} diff --git a/cores/esp8266/debug.h b/cores/esp8266/debug.h index 3fb4d2dd54..e66cdbf7d5 100644 --- a/cores/esp8266/debug.h +++ b/cores/esp8266/debug.h @@ -5,7 +5,7 @@ #include #ifdef DEBUG_ESP_CORE -#define DEBUGV(fmt, ...) ::printf_P( (PGM_P)PSTR(fmt), ## __VA_ARGS__) +#define DEBUGV(fmt, ...) ::putprintf(ets_putc, (PGM_P)PSTR(fmt), ## __VA_ARGS__) #endif #ifndef DEBUGV @@ -25,6 +25,8 @@ extern "C" { void __panic_func(const char* file, int line, const char* func) __attribute__((noreturn)); #define panic() __panic_func(PSTR(__FILE__), __LINE__, __func__) +int putprintf (int (*put)(int), const char* fmt, ...); + #ifdef __cplusplus } #endif From 2444db19b3df6e826ba84f388db747580cb69af9 Mon Sep 17 00:00:00 2001 From: david gauchard Date: Thu, 14 Mar 2019 00:51:46 +0100 Subject: [PATCH 3/3] remove useless putprintf since ::printf already uses ets_putc --- cores/esp8266/debug.cpp | 11 ----------- cores/esp8266/debug.h | 4 +--- 2 files changed, 1 insertion(+), 14 deletions(-) diff --git a/cores/esp8266/debug.cpp b/cores/esp8266/debug.cpp index bd036b60a0..d8bf8bb11d 100644 --- a/cores/esp8266/debug.cpp +++ b/cores/esp8266/debug.cpp @@ -34,14 +34,3 @@ void ICACHE_RAM_ATTR hexdump(const void *mem, uint32_t len, uint8_t cols) { } os_printf("\n"); } - -int putprintf (int (*put)(int), const char* fmt, ...) { - char buf[128]; - va_list ap; - va_start(ap, fmt); - int len = ::vsnprintf(buf, sizeof(buf), fmt, ap); - for (int i = 0; i < len; i++) - put(buf[i]); - va_end(ap); - return len; -} diff --git a/cores/esp8266/debug.h b/cores/esp8266/debug.h index e66cdbf7d5..fab128253c 100644 --- a/cores/esp8266/debug.h +++ b/cores/esp8266/debug.h @@ -5,7 +5,7 @@ #include #ifdef DEBUG_ESP_CORE -#define DEBUGV(fmt, ...) ::putprintf(ets_putc, (PGM_P)PSTR(fmt), ## __VA_ARGS__) +#define DEBUGV(fmt, ...) ::printf((PGM_P)PSTR(fmt), ## __VA_ARGS__) #endif #ifndef DEBUGV @@ -25,8 +25,6 @@ extern "C" { void __panic_func(const char* file, int line, const char* func) __attribute__((noreturn)); #define panic() __panic_func(PSTR(__FILE__), __LINE__, __func__) -int putprintf (int (*put)(int), const char* fmt, ...); - #ifdef __cplusplus } #endif