arduino / ArduinoCore-mbed

330 stars 195 forks source link

Program Space Utilities (pgmspace.h) #343

Open fkromer opened 2 years ago

fkromer commented 2 years ago

Other support packages are referencing pgmspace.h. E.g. ArduinoCore-avr or arduino-esp32. We are experimenting with porting some prototyp to the Portenta Machine Control Board. Unfortunatelly our code does not compile anymore cause one of our dependencies depends on pgmspace.h.

I could not find program space utilities (usually contained in pgmspace.h) in this drivers so far. Are there program space utilities defined in this drivers somewhere?

fkromer commented 2 years ago

It seems like pgmspace.h is required for low end devices only to store data in flash (program) memory instead of SRAM. This should be an issue with my lib dependency not providing proper device specific inlucludes. One can create a fake interface like described here to make the pgmspace.h interface point to the higher end device, potentially device specific implementation.

fkromer commented 2 years ago

One thing to add here is that the pgmspace.h topic is not specific to a single lib but potentially a lot of libs out there. I'm using Arduino IDE 1.8.15 to compile the sketch. According to the docs pgmemspace.h should be included automatically.

PROGMEM is part of the pgmspace.h library. It is included automatically in modern versions of the IDE. However, if you are using an IDE version below 1.0 (2011), you’ll first need to include the library at the top of your sketch, like this:

I'm not sure how I can help out in fixing this right now...

khoih-prog commented 2 years ago

Check if this Compile issue for RP2040 Connect #11 can be applicable in your use case

The actual pgmspace.h file of mbed_rp2040 core is in the deprecated section of the core, for example, if the core is v.2.5.2,

2.5.2/cores/arduino/api/deprecated-avr-comp/avr/pgmspace.h


Installation

Clone the repository in $sketchbook/hardware/arduino-git

mkdir -p $sketchbook/hardware/arduino-git
cd $sketchbook/hardware/arduino-git
git clone git@github.com:arduino/ArduinoCore-mbed mbed

Clone https://github.com/arduino/ArduinoCore-API into a directory of your choice.

git clone git@github.com:arduino/ArduinoCore-API

Update the api symlink

Create a symlink to ArduinoCore-API/api in $sketchbook/hardware/arduino/mbed/cores/arduino.

khoih-prog commented 2 years ago

Or you can try remove dependency on pgmspace.h by using something similar to WiFiWebServer.h#L149-L154

// ESP32/ESP8266 includes <pgmspace.h> by default, and memccpy_P was already defined there
#if !(ESP32 || ESP8266 || defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4))
  #include <avr/pgmspace.h>
  #define memccpy_P(dest, src, c, n) memccpy((dest), (src), (c), (n))
#endif
fkromer commented 2 years ago

@khoih-prog This issue is not of relevance for me anymore. Anyway... thanks for the answer.