Update toolchain to fix pgm_read_float_unaligned by earlephilhower · Pull Request #8091 · esp8266/Arduino (original) (raw)
Here is one that works with this PR, and proves that master doesn't work. It's less synthetic in that it doesn't fabricate an array in RAM, but puts the constants into PROGMEM. If one adds const
to the constants
structure instance, the compiler optimizations outsmart the test and then it proves nothing. That is, master still fails in the pgm_read_float_unaligned
call, but one can access constants.pi
directly ;-)
static const uint8_t pi_array[] PROGMEM = { 42, 0xdb, 0x0f, 0x49, 0x40 };
static struct __attribute__((__packed__)) {
uint8_t pad = 42;
float pi = PI;
double pi_d = PI;
} constants PROGMEM;
void setup()
{
Serial.begin(74880);
while (!Serial);
delay(500);
Serial.println("pgmread");
float pi = PI;
Serial.println(pi, 6);
for (int i = 0; i < 4; ++i)
Serial.println(*((uint8_t*)&pi + i), 16);
Serial.println(pgm_read_float_unaligned((float*)&pi_array[1]), 6);
Serial.println(pgm_read_float_unaligned(&constants.pi), 6);
//Serial.println(pgm_read_double_unaligned(&constants.pi_d), 11);
}
void loop()
{
}