Open agdl opened 7 years ago
On Mega2560, the following sketch compiles OK:
It may compile, but it certainly doesn't work. It has 3 fatal flaws:
1: There's no Serial.begin(), so it can't print anything 2: It doesn't actually store any pointers for pgm_read_ptr() to read. The array has 5 chars (including terminating zero), not a pointer to chars. 3: The array is local scope (stack allocated), which doesn't work with PROGMEM.
Here is a correct program which actually works when run on Uno or Mega (yes, I did just test both of them).
const char * const str_debug_1[] PROGMEM = {"ECHO", "ECHO2"};
void setup() {
Serial.begin(9600);
Serial.println("test pgm_read_ptr:");
Serial.println((char*)pgm_read_ptr(&str_debug_1[0]));
Serial.println((char*)pgm_read_ptr(&str_debug_1[1]));
}
void loop() {
}
This doesn't solve the issue on Arduino Due, but at least a working test case might be helpful?
There is no doubt that pgm_read_ptr
works on AVR platforms, so it doesn't help at all, frankly. Creating a runnable test case for Due once the compile issue has been fixed is a trivial exercise.
Any thoughts on how to fix it?
Use ((void const *)(addr))
https://github.com/arduino/ArduinoCore-samd/commit/4ffc9d2bdb557e1a0db2cc943aa9b3fef4ad71b1
From @bobc on December 10, 2016 12:31
Arduino IDE 1.6.8 Arduino AVR Boards 1.6.10 Arduino SAM Boards 1.6.9
On Mega2560, the following sketch compiles OK:
On Due, the same sketch has a compile error :
Inspection of pgm_read_ptr (in avr/pgmspace.h) for Due shows : -
#define pgm_read_ptr(addr) (*(const void *)(addr))
This macro casts the argument void , then tries to dereference a void , which is guaranteed to never work.
Probably, the cast to (void *) is not needed.
Copied from original issue: arduino/Arduino#5698