PROGMEM not working?

Well, i have a sketch that passes the check and works on Mega2560 on 1.0.3 and 1.51, but i just tried to compile it for Due (with 1.51 ) and it is returning an error.

The error comes from this line of code:

const char ArduBytes[] PROGMEM = {0x32,0x11,0xE5,0x10,0x12};

The error that 1.51 returns is "expected initializer before 'PROGMEM'".

Is it a sw error or am i doing something wrong?

BR

Arm doesn't have PROGMEM. In theory, the DUE ide should have defined all the PROGMEM 'keywords' as nothing and all of the _P functions as , but maybe they missed a few places.

If you are only programming on the Due, and no longer target the AVR based microprocessors, just take out the PROGMEM stuff. If you need to run on both platforms, then you probably should do something like:

#if defined(__arm__) && !defined(PROGMEM)
#define PROGMEM
#define PSTR(STR) STR
#endif

You probably need more than that, depending on your program.

Personally I'm happy that PROGMEM causes compilation errors, as this reminds me that I don't yet know how to achieve the same functionality on the Due!

Jim

MichaelMeissner:
Arm doesn't have PROGMEM. In theory, the DUE ide should have defined all the PROGMEM 'keywords' as nothing and all of the _P functions as , but maybe they missed a few places.

If you are only programming on the Due, and no longer target the AVR based microprocessors, just take out the PROGMEM stuff. If you need to run on both platforms, then you probably should do something like:

#if defined(__arm__) && !defined(PROGMEM)

#define PROGMEM
#define PSTR(STR) STR
#endif




You probably need more than that, depending on your program.

Ok, got the point! I am currently developing some stuff that should work on both platforms (for performance issues), so i'll stick to what you mention.

Thanks for the tips!

BR

jgmdavies:
Personally I'm happy that PROGMEM causes compilation errors, as this reminds me that I don't yet know how to achieve the same functionality on the Due!

You don't need it on the ARM, because the ARM has an integrated memory address space, where the program and the data are both visible with standard memory instructions (though the code should be write protected).

The AVR is a so-called Harvard architecture, where the text and the data are in different address spaces that overlap, and you need different instructions to reference memory in the text/program section compared to the data section. So what PROGMEM does is move big constants to the text/program area, and then you use special functions to move it back to the data section so it can be used for things like calls with long strings.

In the GCC that is distributed with the Arduino IDE, it is old enough that the PROGMEM stuff is not as well integrated. When I was working on another embedded port for GCC (the SPU or cell), I added support in GCC 4.5 for having more integrated separate memory address spaces for that processor and the AVR gcc maintainer has used it to support PROGMEM in newer versions of the compiler. I have since moved onto the PowerPC backend which doesn't need the support, but it would be nice to know people use stuff I developed a few years ago and find it useful.

Man, do we have experts on this forum :slight_smile: