Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

define printf_P as Serial.printf on ESP32/8266 and RP2040 (arduino-pico) cores #870

Closed
2bndy5 opened this issue Sep 6, 2022 · 1 comment · Fixed by #873
Closed

define printf_P as Serial.printf on ESP32/8266 and RP2040 (arduino-pico) cores #870

2bndy5 opened this issue Sep 6, 2022 · 1 comment · Fixed by #873

Comments

@2bndy5
Copy link
Member

2bndy5 commented Sep 6, 2022

In researching how to test #864 (because I needed to call printDetails()) I found a solution to work well with the following Arduino cores

All of those cores have Serial.printf() defined using vsnprintf() (similar to the adafruit/arduinocore-samd). However, the ESP32 core has printf_P already defined in the extensa toolchain. So, I'm proposing

--- a/RF24_config.h
+++ b/RF24_config.h
@@ -159,12 +159,18 @@ extern HardwareSPI SPI;
     #endif // defined (__ARDUINO_X86__)
 
     // Progmem is Arduino-specific
-    #if defined(ARDUINO_ARCH_ESP8266) || defined(ESP32)
+    #if defined(ARDUINO_ARCH_ESP8266) || defined(ESP32) || (defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_MBED))
         #include <pgmspace.h>
         #define PRIPSTR "%s"
         #ifndef pgm_read_ptr
             #define pgm_read_ptr(p) (*(void* const*)(p))
         #endif
+        // Serial.printf() is no longer defined in the unifying Arduino/ArduinoCore-API repo
+        // Serial.printf() is defined if using the arduino-pico/esp32/8266 repo
+        #if defined(ARDUINO_ARCH_ESP32) // do not `undef` when using the espressif SDK only
+            #undef printf_P             // needed for ESP32 core
+        #endif
+        #define printf_P Serial.printf
     #elif defined(ARDUINO) && !defined(ESP_PLATFORM) && !defined(__arm__) && !defined(__ARDUINO_X86__) || defined(XMEGA)
         #include <avr/pgmspace.h>
         #define PRIPSTR "%S"

I already tested these changes on my QtPy boards using either ESP32-S2 or RP2040

Additional context

  • #undef printf_P

    I'm not sure if this lib works as is in the espressif SDK for the ESP32, but I wanted to make sure that we only #undef printf_P when using the ESP32 Arduino core only.

  • defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_MBED)

    Because the arduino cores that wrap mbed framework may not actually define Serial.printf(), I wanted to make sure that the definition of printf_P only applied to the arduino-pico core, a very popular RP2040 core that supports all boards that the PicoSDK supports and additionally multi-core processing and the PicoSDK's assembly routines feature...

@2bndy5
Copy link
Member Author

2bndy5 commented Sep 18, 2022

I looked into the ESP32 core to see if/where printf_P was used, and it looks like it isn't used anywhere (by the core at least).

I'm not sure if #undef printf_P may cause conflicts in user apps, but I think it is safe to redefine printf_P (for now). There's nothing stopping the user code from redefining printf_P the same way that this proposal does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant