Pages: [1]   Go Down
Author Topic: PROGMEM not working?  (Read 1631 times)
0 Members and 1 Guest are viewing this topic.
Nowhere at all
Offline Offline
Newbie
*
Karma: 0
Posts: 43
Patience, discipline
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:

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
« Last Edit: January 08, 2013, 09:56:06 am by Bi0H4z4rD » Logged

Ayer, Massachusetts, USA
Offline Offline
Edison Member
*
Karma: 53
Posts: 1832
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Arm doesn't have PROGMEM.  In theory, the DUE ide should have defined all the PROGMEM 'keywords' as nothing and all of the <xxx>_P functions as <xxx>, 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:

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

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

Brighton, UK
Offline Offline
Newbie
*
Karma: 0
Posts: 47
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Nowhere at all
Offline Offline
Newbie
*
Karma: 0
Posts: 43
Patience, discipline
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Arm doesn't have PROGMEM.  In theory, the DUE ide should have defined all the PROGMEM 'keywords' as nothing and all of the <xxx>_P functions as <xxx>, 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:

Code:
#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
Logged

Ayer, Massachusetts, USA
Offline Offline
Edison Member
*
Karma: 53
Posts: 1832
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Edison Member
*
Karma: 26
Posts: 1339
You do some programming to solve a problem, and some to solve it in a particular language. (CC2)
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Man, do we have experts on this forum smiley
Logged

Pages: [1]   Go Up
Jump to: