I'm attempting to use PROGMEM to store an array of uint32_t, and I'm having problems. I can make PROGMEM work with uint16_t, so I suspect (1) I'm doing something wrong, (2) I've found a bug, or (3) the compiler is messing things up.
I'm running arduino.cc 1.8.5.
Here's the code:
const uint32_t PROGMEM array32[] = { 0x00FFEEDD, 0x00CCBBAA, 0x00998877, 0x00665544, 0x00332211, 0x00000000 };
const uint16_t PROGMEM array16[] = { 0x1122, 0x3344, 0x5566, 0x7788, 0x99AA, 0xBBCC };
uint32_t stepStart;
uint16_t index;
void setup() {
// put your setup code here, to run once:
stepStart = millis();
Serial.begin(115200);
}
void loop() {
// put your main code here, to run repeatedly:
int step = 3000;
int color;
uint32_t mark = millis();
// print another array value every 3 seconds to avoid overwhelming anyone reading the serial
if (mark > (stepStart + step)) {
// output next color
Serial.print("color ");Serial.print(index,DEC);Serial.print(" at ");
// if I change uint32_t to uint16_ and array32 to array16 in the next 3 lines, the code works.
Serial.print((uint32_t) (array32+index));Serial.print(" is ");
color=(uint32_t) pgm_read_dword_near(array32+index);
Serial.println( (uint32_t) color,HEX);
index++;
index %= 6;
stepStart = mark;
}
}
Serial output:
color 0 at 104 is FFFFEEDD
color 1 at 108 is FFFFBBAA
color 2 at 112 is FFFF8877
color 3 at 116 is 5544
color 4 at 120 is 2211
color 5 at 124 is 0
I've taken a look at the compiler output with a binary editor, and (1) I can see the compiler's smart enough to load only the array I'm using (array32 in this case), (2) it doesn't appear to load the array32 correctly. Here's a portion of the hex file:
0x0120 0DDEEFF00AABBCC0
0x0130 083.:10007000778
0x0140 8990044556600112
0x0150 233000000000083.
Any ideas? Did I miss something basic, or did I potentially find a bug?