Skip to content

FPSTR() incorrectly defined in pgmspace.h #1371

Closed
@bxparks

Description

@bxparks

Hardware:

Board: ESP32 Dev Module
Core Installation/update date: 2018-05-01
IDE name: Arduino IDE
Flash Frequency: 80Mhz
Upload Speed: 921600

Description:

The FPSTR() macro in ./cores/esp32/pgmspace.h is incorrectly defined. It is currently

#define PSTR(s)       (s)

But that macro should do a cast to a (const __FlashStringHelper*) instead.
See https://github.com/esp8266/Arduino/blob/master/cores/esp8266/WString.h#L38

The sketch below works on ESP8266 but fails on ESP32.

The solution is to remove FPSTR() from pgmspace.h and add the following to WString.h:

#define FPSTR(pstr_pointer) (reinterpret_cast<const __FlashStringHelper *>(pstr_pointer))
#define F(string_literal) (FPSTR(PSTR(string_literal)))

(where I have redefined F() in terms of FPSTR() as done in the ESP8266 version of this file).

I can send you a PR if you agree that this is the correct solution.

Sketch:

#include <Arduino.h>

#if defined(ESP32) || defined(ESP8266)
  #include <pgmspace.h>
#else
  #error Unsupported platform
#endif

const char flashString[] PROGMEM = "abcedf";
const __FlashStringHelper* const flashHelperString = FPSTR(flashString);

void setup() {
}

void loop() {
}

Debug Messages:

Build options changed, rebuilding all
In file included from /home/brian/Downloads/Arduino/arduino-1.8.5/hardware/espressif/esp32/cores/esp32/WString.h:29:0,
                 from /home/brian/Downloads/Arduino/arduino-1.8.5/hardware/espressif/esp32/cores/esp32/Arduino.h:150,
                 from /home/brian/dev/arduino/esp32/fpstr_demo/fpstr_demo.ino:1:
/home/brian/Downloads/Arduino/arduino-1.8.5/hardware/espressif/esp32/cores/esp32/pgmspace.h:35:41: error: cannot convert 'const char*' to 'const __FlashStringHelper* const' in initialization
 #define FPSTR(p)      ((const char *)(p))
                                         ^
/home/brian/dev/arduino/esp32/fpstr_demo/fpstr_demo.ino:10:54: note: in expansion of macro 'FPSTR'
 const __FlashStringHelper* const flashHelperString = FPSTR(flashString);
                                                      ^
exit status 1
Error compiling for board ESP32 Dev Module.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: StaleIssue is stale stage (outdated/stuck)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions