arduino / Arduino

Arduino IDE 1.x
https://www.arduino.cc/en/software
Other
14.17k stars 7.02k forks source link

PROGMEM no longer works #2456

Closed pjds closed 9 years ago

pjds commented 9 years ago

Hi - I have a program for the mega2560 which compiles and runs under 1.5.6r2. It makes extensive use of PROGMEM. I have installed the latest version of tthe Arduino IDE, 1.5.8. My program no longer compiles, and gives me the following error message:

C:\Users...\icons4.h:12:1: error: 'prog_uint16_t' does not name a type prog_uint16_t icon1[0x900] PROGMEM ={ ^

What can I do to correct this incompatibility? - best regards - Peter

matthijskooijman commented 9 years ago

Just use uint16_t, newer toolchains dropped all PROGMEM-specific types (see http://www.nongnu.org/avr-libc/user-manual/group__avr__pgmspace.html#ga93ec00229866bf6a125384ad08cefa73)

pjds commented 9 years ago

Thank you very much for your swift response Matthijs. However, I am not quite out of the woods yet. I now get another compiler message as follows:

C:\Users...\strings.h:259:19: error: variable 'xyz' must be const in order to be put into read-only section by means of 'attribute((progmem))'

const char *xyz[] PROGMEM = {string1, string2,string3};

               ^

String1 etc. have been declared already as

const char string1[] PROGMEM = "This is string 1";

etc.

Can you tell mw what is wrong? - best regards - Peter


From: Matthijs Kooijman [mailto:notifications@github.com] Sent: 18 November 2014 12:27 To: arduino/Arduino Cc: pjds Subject: Re: [Arduino] PROGMEM no longer works (#2456)

Just use uint16_t, newer toolchains dropped all PROGMEM-specific types (see http://www.nongnu.org/avr-libc/user-manual/group__avr__pgmspace.html#ga93ec0 0229866bf6a125384ad08cefa73)

Reply to this email directly or view https://github.com/arduino/Arduino/issues/2456#issuecomment-63462853 it on GitHub. https://github.com/notifications/beacon/AJXdrVUEyVFSjtqO4A9jxvMhM3EMegWGks5 nOzKogaJpZM4C9CU1.gif

matthijskooijman commented 9 years ago

I think the problem is that you're declaring a pointer-to-const, instead of a const pointer (or rather I think you need a const pointer-to-const here). I'm not sure where to add the extra const - you can probably google what you need using the above, though.

Also, this report tracker is really for bugs in the Arduino code, not for getting help with your own code. I'll close this issue - if you have further problems, I suggest you post them to the forums or ask on IRC.

pjds commented 9 years ago

OK thanks Matthijs - sorry to disturb - best regards - Peter


From: Matthijs Kooijman [mailto:notifications@github.com] Sent: 18 November 2014 16:28 To: arduino/Arduino Cc: pjds Subject: Re: [Arduino] PROGMEM no longer works (#2456)

I think the problem is that you're declaring a pointer-to-const, instead of a const pointer (or rather I think you need a const pointer-to-const here). I'm not sure where to add the extra const - you can probably google what you need using the above, though.

Also, this report tracker is really for bugs in the Arduino code, not for getting help with your own code. I'll close this issue - if you have further problems, I suggest you post them to the forums or ask on IRC.

Reply to this email directly or view https://github.com/arduino/Arduino/issues/2456#issuecomment-63498463 it on GitHub. https://github.com/notifications/beacon/AJXdraUpQKlnPc0FJMIyeHjAW0qdgrgYks5 nO2r_gaJpZM4C9CU1.gif

magic890 commented 9 years ago

I think it's solved using: char * const string1 PROGMEM = "This is string 1";

pjds commented 9 years ago

I reverted to the previous version, 1.5.6r2 - best regards - Peter

Dr P. J. Duffett-Smith Reader in Experimental Radio Physics The Cavendish Laboratory JJ Thomson Ave Cambridge CB3 0HE (Emeritus)

Mobile: 07979 953359 email: pjds@mrao.cam.ac.uk


From: Matteo Guarnerio [mailto:notifications@github.com] Sent: Sunday, March 29, 2015 10:21 PM To: arduino/Arduino Cc: pjds Subject: Re: [Arduino] PROGMEM no longer works (#2456)

How have you solved this issue?

Reply to this email directly or view https://github.com/arduino/Arduino/issues/2456#issuecomment-87482948 it on GitHub. https://github.com/notifications/beacon/AJXdrXrF6fhpJN25YEBMIvW_Mb_4Rqmvks5 n6GRSgaJpZM4C9CU1.gif

PaulStoffregen commented 9 years ago

Try this:

  const char * const xyz[] PROGMEM = {string1, string2,string3};

Notice the extra "const". Newer avr-gcc requires PROGMEM variables to be const. The first const means it point to something that it isn't allowed to change, but says nothing about whether "xyz" can itself change. Placing "const" on the right-hand side of "*" means the variable itself if const.

pjds commented 9 years ago

Hi Paul - thank you very much for your response to my email. I downloaded version 1.6.2 of the Arduino IDE and made the modification as you described. The strings for my program are all in a separate file with .h extension, and when I attempt to compile, I get the following error message:

error: 's194' was not declared in this scope

The relevant bits of the .h file are as follows:

include <avr/pgmspace.h>

prog_char s000[] PROGMEM = "This is string 0";

prog_char s001[] PROGMEM = "This is string 1";

.

.

prog_char s193[] PROGMEM = "This is string 193";

prog_char s194[] PROGMEM = "This is string 194";

prog_char s195[] PROGMEM = "This is string 195";

prog_char s196[] PROGMEM = "This is string 196";

.

.

prog_char s265[] PROGMEM = "This is strinmg 265";

const char * const string_table[] PROGMEM =

{

s000,

s001,

.

.

s193,

s194,

s195,

s196,

.

.

s265

};

Is there some memory limit I am hitting? Can you see what I am doing wrong? I am using a Mega2650 - best regards - Peter


From: Paul Stoffregen [mailto:notifications@github.com] Sent: 29 March 2015 23:25 To: arduino/Arduino Cc: pjds Subject: Re: [Arduino] PROGMEM no longer works (#2456)

Try this:

const char * const xyz[] PROGMEM = {string1, string2,string3};

Notice the extra "const". Newer avr-gcc requires PROGMEM variables to be const. The first const means it point to something that it isn't allowed to change, but says nothing about whether "xyz" can itself change. Placing "const" on the right-hand side of "*" means the variable itself if const.

Reply to this email directly or view https://github.com/arduino/Arduino/issues/2456#issuecomment-87489141 it on GitHub. https://github.com/notifications/beacon/AJXdrQAf26OWH6sc0dTUcZJkdnr-6YjNks5 n6HMjgaJpZM4C9CU1.gif

pjds commented 9 years ago

Hi Paul - I have investigated further. The error message I sent you yesterday was a red herring - there were so many that the IDE had simply scrolled off the top of its memory space for messages. The following does work under the latest release of the Arduino IDE (1.6.2):

include <avr/pgmspace.h>

const char string_1[] PROGMEM = "String 1";

const char string_2[] PROGMEM = "String 2";

PGM_P const string_table[] PROGMEM =

{

string_1,

string_2,

};

char buffer[30]; // make sure this is large enough for the largest string it must hold

void setup()

{

Serial.begin(9600);

}

void loop()

{

/* Using the string table in program memory requires the use of special functions to retrieve the data.

 The strcpy_P function copies a string from program space to a string in

RAM ("buffer").

 Make sure your receiving string in RAM  is large enough to hold

whatever

 you are retrieving from program space. */

for (int i = 0; i < 4; i++)

{

strcpy_P(buffer, (char*)pgm_read_word(&(string_table[i]))); // Necessary

casts and dereferencing, just copy.

Serial.println( buffer );

delay( 500 );

}

}

This is an example from somewhere on the web. I also have bitmaps to put into program memory. The form below works under 1.5.6r2, but does not work under the latest release. If I do the trick with the const keyword, then the bitmap reading routines fail. I would rather not have to declare a huge buffer in my working memory to read in a whole bitmap at once as in the strings example above. Can you see a way around this?

include <avr/pgmspace.h>

prog_uint16_t bitmap[0x900] PROGMEM ={0x0000, . 0x0000};

(works under 1.5.6r2, not under 1.6.2) - best regards - Peter


From: Paul Stoffregen [mailto:notifications@github.com] Sent: 29 March 2015 23:25 To: arduino/Arduino Cc: pjds Subject: Re: [Arduino] PROGMEM no longer works (#2456)

Try this:

const char * const xyz[] PROGMEM = {string1, string2,string3};

Notice the extra "const". Newer avr-gcc requires PROGMEM variables to be const. The first const means it point to something that it isn't allowed to change, but says nothing about whether "xyz" can itself change. Placing "const" on the right-hand side of "*" means the variable itself if const.

Reply to this email directly or view https://github.com/arduino/Arduino/issues/2456#issuecomment-87489141 it on GitHub. https://github.com/notifications/beacon/AJXdrQAf26OWH6sc0dTUcZJkdnr-6YjNks5 n6HMjgaJpZM4C9CU1.gif

PaulStoffregen commented 9 years ago

These github issues are for reporting bugs and discussing new features in the Arduino software.

How to write your program is a matter to discuss on the forum. Posting your full program in the first message of a new topic really helps solicit better answers. If the forum conversation turns up a clear bug in the Arduino software, open a new issue here to report it.